Skip to content

Commit 29b73ee

Browse files
author
hyd-dev
committed
Fix reachable_set for non-function items in non-library crates
1 parent 9315a0c commit 29b73ee

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

compiler/rustc_passes/src/reachable.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,22 @@ impl<'tcx> ReachableContext<'tcx> {
211211
if !self.any_library {
212212
// If we are building an executable, only explicitly extern
213213
// types need to be exported.
214-
if let Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), def_id, .. })
215-
| Node::ImplItem(hir::ImplItem {
216-
kind: hir::ImplItemKind::Fn(sig, ..),
217-
def_id,
218-
..
219-
}) = *node
220-
{
221-
let reachable = sig.header.abi != Abi::Rust;
222-
let codegen_attrs = self.tcx.codegen_fn_attrs(*def_id);
223-
let is_extern = codegen_attrs.contains_extern_indicator();
224-
let std_internal =
225-
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
226-
if reachable || is_extern || std_internal {
227-
self.reachable_symbols.insert(search_item);
228-
}
214+
let reachable =
215+
if let Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. })
216+
| Node::ImplItem(hir::ImplItem {
217+
kind: hir::ImplItemKind::Fn(sig, ..), ..
218+
}) = *node
219+
{
220+
sig.header.abi != Abi::Rust
221+
} else {
222+
false
223+
};
224+
let codegen_attrs = self.tcx.codegen_fn_attrs(search_item);
225+
let is_extern = codegen_attrs.contains_extern_indicator();
226+
let std_internal =
227+
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
228+
if reachable || is_extern || std_internal {
229+
self.reachable_symbols.insert(search_item);
229230
}
230231
} else {
231232
// If we are building a library, then reachable symbols will

src/test/codegen/external-no-mangle-statics.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// revisions: lib staticlib
12
// ignore-emscripten default visibility is hidden
23
// compile-flags: -O
34
// `#[no_mangle]`d static variables always have external linkage, i.e., no `internal` in their
45
// definitions
56

6-
#![crate_type = "lib"]
7-
#![no_std]
7+
#![cfg_attr(lib, crate_type = "lib")]
8+
#![cfg_attr(staticlib, crate_type = "staticlib")]
89

910
// CHECK: @A = local_unnamed_addr constant
1011
#[no_mangle]

0 commit comments

Comments
 (0)