Skip to content

Commit 0383131

Browse files
committed
Contents of reachable statics is reachable
1 parent 3e9e574 commit 0383131

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

compiler/rustc_passes/src/reachable.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,11 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
9898
self.worklist.push(def_id);
9999
} else {
100100
match res {
101-
// If this path leads to a constant, then we need to
102-
// recurse into the constant to continue finding
103-
// items that are reachable.
104-
Res::Def(DefKind::Const | DefKind::AssocConst, _) => {
101+
// Reachable constants and reachable statics can have their contents inlined
102+
// into other crates. Mark them as reachable and recurse into their body.
103+
Res::Def(DefKind::Const | DefKind::AssocConst | DefKind::Static(_), _) => {
105104
self.worklist.push(def_id);
106105
}
107-
108-
// If this wasn't a static, then the destination is
109-
// surely reachable.
110106
_ => {
111107
self.reachable_symbols.insert(def_id);
112108
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
pub static V: &u32 = &X;
22
pub static F: fn() = f;
3+
pub static G: fn() = G0;
34

45
static X: u32 = 42;
6+
static G0: fn() = g;
57

68
pub fn v() -> *const u32 {
79
V
810
}
911

1012
fn f() {}
13+
14+
fn g() {}

tests/ui/cross-crate/static-init.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// Regression test for #84455 and #115052.
12
// run-pass
23
// aux-build:static_init_aux.rs
34
extern crate static_init_aux as aux;
45

56
static V: &u32 = aux::V;
67
static F: fn() = aux::F;
8+
static G: fn() = aux::G;
79

810
fn v() -> *const u32 {
911
V
@@ -12,4 +14,5 @@ fn v() -> *const u32 {
1214
fn main() {
1315
assert_eq!(aux::v(), crate::v());
1416
F();
17+
G();
1518
}

0 commit comments

Comments
 (0)