Skip to content

Commit f6bbc80

Browse files
Don't ICE when encountering asm sym with regions
1 parent 959b2c7 commit f6bbc80

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/rustc_borrowck/src/universal_regions.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_errors::Diagnostic;
1717
use rustc_hir as hir;
18+
use rustc_hir::def::DefKind;
1819
use rustc_hir::def_id::{DefId, LocalDefId};
1920
use rustc_hir::lang_items::LangItem;
2021
use rustc_hir::BodyOwnerKind;
@@ -711,7 +712,17 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
711712
// For a constant body, there are no inputs, and one
712713
// "output" (the type of the constant).
713714
assert_eq!(self.mir_def.to_def_id(), def_id);
714-
let ty = tcx.type_of(self.mir_def).instantiate_identity();
715+
let mut ty = tcx.type_of(self.mir_def).instantiate_identity();
716+
// `SymFn` in global asm may only reference `'static`, but those
717+
// regions are erased as part of computing the type of the anon
718+
// const. Put them back, since the `UniversalRegionsBuilder` is
719+
// not setup to handle erased regions.
720+
if tcx.def_kind(tcx.parent(def_id)) == DefKind::GlobalAsm {
721+
ty = tcx.fold_regions(ty, |re, _| {
722+
assert_eq!(re, tcx.lifetimes.re_erased);
723+
tcx.lifetimes.re_static
724+
});
725+
}
715726
let ty = indices.fold_to_region_vids(tcx, ty);
716727
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
717728
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// build-pass
2+
3+
core::arch::global_asm!("/* {} */", sym <&'static ()>::clone);
4+
5+
fn main() {}

0 commit comments

Comments
 (0)