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
This commit is contained in:
parent
264aafe056
commit
6cae080516
@ -336,6 +336,12 @@ struct CollectPrivateImplItemsVisitor<'a, 'tcx: 'a> {
|
||||
|
||||
impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx> {
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
// Anything which has custom linkage gets thrown on the worklist no
|
||||
// matter where it is in the crate.
|
||||
if attr::contains_name(&item.attrs, "linkage") {
|
||||
self.worklist.push(item.id);
|
||||
}
|
||||
|
||||
// We need only trait impls here, not inherent impls, and only non-exported ones
|
||||
if let hir::ItemImpl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node {
|
||||
if !self.access_levels.is_reachable(item.id) {
|
||||
|
@ -1,41 +0,0 @@
|
||||
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Smallest "hello world" with a libc runtime
|
||||
|
||||
// ignore-windows
|
||||
// ignore-android
|
||||
|
||||
#![feature(intrinsics, lang_items, start, no_core, alloc_system)]
|
||||
#![feature(global_allocator, allocator_api)]
|
||||
#![no_std]
|
||||
|
||||
extern crate alloc_system;
|
||||
|
||||
use alloc_system::System;
|
||||
|
||||
#[global_allocator]
|
||||
static A: System = System;
|
||||
|
||||
extern {
|
||||
fn puts(s: *const u8);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[lang = "eh_personality"] pub extern fn rust_eh_personality() {}
|
||||
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
|
||||
|
||||
#[start]
|
||||
fn main(_: isize, _: *const *const u8) -> isize {
|
||||
unsafe {
|
||||
puts("Hello!\0".as_ptr() as *const u8);
|
||||
}
|
||||
return 0
|
||||
}
|
19
src/test/run-pass/thin-lto-global-allocator.rs
Normal file
19
src/test/run-pass/thin-lto-global-allocator.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags: -Z thinlto -C codegen-units=2
|
||||
// min-llvm-version 4.0
|
||||
|
||||
#![feature(allocator_api, global_allocator)]
|
||||
|
||||
#[global_allocator]
|
||||
static A: std::heap::System = std::heap::System;
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user