Skip to content

Commit 6cae080

Browse files
committed
rustc: Handle #[linkage] anywhere in a crate
This commit updates the reachability pass of the compiler to seed the local worklist with `#[linkage]`-like items anywhere in a crate, not just those reachable from public items. Closes #45165
1 parent 264aafe commit 6cae080

File tree

3 files changed

+25
-41
lines changed

3 files changed

+25
-41
lines changed

src/librustc/middle/reachable.rs

+6
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ struct CollectPrivateImplItemsVisitor<'a, 'tcx: 'a> {
336336

337337
impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx> {
338338
fn visit_item(&mut self, item: &hir::Item) {
339+
// Anything which has custom linkage gets thrown on the worklist no
340+
// matter where it is in the crate.
341+
if attr::contains_name(&item.attrs, "linkage") {
342+
self.worklist.push(item.id);
343+
}
344+
339345
// We need only trait impls here, not inherent impls, and only non-exported ones
340346
if let hir::ItemImpl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node {
341347
if !self.access_levels.is_reachable(item.id) {

src/test/run-pass/smallest-hello-world.rs

-41
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Z thinlto -C codegen-units=2
12+
// min-llvm-version 4.0
13+
14+
#![feature(allocator_api, global_allocator)]
15+
16+
#[global_allocator]
17+
static A: std::heap::System = std::heap::System;
18+
19+
fn main() {}

0 commit comments

Comments
 (0)