Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --I couldn't I couldn't produce a single file example, as it seems the ICE is triggered when cross crate compilation is involved; i.e dumping the contents of into does not trigger the ICE. This seems like a regression of the feature as this previously worked on nightly of the 1.50 stable release. : : <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details
While regression itself is related to the introduction of CTFE MIR, it seems this actually never worked correctly, with static ending up duplicated.
Assigning priority as discussed as part of the and removing . label -I-prioritize +P-medium
I can't reproduce with the latest nightly and cargo. Are there any further instructions for reproducing this?
Apologies, forgot to mention you'll need to add Or build for a target that does not have panic unwinding enabled by default.
(discussed in T-compiler meeting. This is an issue on stable, and might get a backport via . Re-opening to investigate details of what worked, what stopped working, what is fixed, and what is still broken.)
In the case reported here, one crate references static from another crate. During mono item collection, based on reachability determines whether it will link to item from an upstream crate or codegen it locally. When decision is made to codegen locally, it is followed by an assertion that optimized MIR is available to do so. In 1.50 static is non-reachable and codegenned locally. In 1.51 and 1.52 static is non-reachable, but the assertion fails since statics no longer use optimized MIR. In nightly, since , the static is reachable and linked to. The change seems safe for backporting to me.
Closing as the .

Discussion:
// Reachable constants will be inlined into other crates // unconditionally, so we need to make sure that their // contents are also reachable. <del> hir::ItemKind::Const(_, init) => { </del> <ins> hir::ItemKind::Const(_, init) | hir::ItemKind::Static(_, _, init) => { </ins> self.visit_nested_body(init); }

| hir::ItemKind::Use(..) | hir::ItemKind::OpaqueTy(..) | hir::ItemKind::TyAlias(..) <del> | hir::ItemKind::Static(..) </del> | hir::ItemKind::Mod(..) | hir::ItemKind::ForeignMod { .. } | hir::ItemKind::Impl { .. }

pub static mut L: u8 = 0; }; <del> // The surrounding item should not accidentally become external </del> fn x() { // CHECK: @M = local_unnamed_addr constant #[no_mangle]

#[no_mangle] pub static mut P: u8 = 0; } <del> // CHECK-LABEL: ; external_no_mangle_statics::x // CHECK-NEXT: ; Function Attrs: // CHECK-NEXT: define internal </del>

<ins> pub static V: &u32 = &X; pub static F: fn() = f; static X: u32 = 42; pub fn v() -> *const u32 { V } fn f() {} </ins>

<ins> // run-pass // aux-build:static_init_aux.rs extern crate static_init_aux as aux; static V: &u32 = aux::V; static F: fn() = aux::F; fn v() -> *const u32 { V } fn main() { assert_eq!(aux::v(), crate::v()); F(); } </ins>