Skip to content

Commit f369271

Browse files
Construct MIR error body for global_asm correctly
1 parent 07b5eee commit f369271

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

compiler/rustc_mir_build/src/builder/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,8 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
612612
| DefKind::AssocConst
613613
| DefKind::AnonConst
614614
| DefKind::InlineConst
615-
| DefKind::Static { .. } => (vec![], tcx.type_of(def_id).instantiate_identity(), None),
615+
| DefKind::Static { .. }
616+
| DefKind::GlobalAsm => (vec![], tcx.type_of(def_id).instantiate_identity(), None),
616617
DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => {
617618
let sig = tcx.liberate_late_bound_regions(
618619
def_id.to_def_id(),

tests/ui/asm/global-asm-with-error.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Ensure that we don't ICE when constructing the fake MIR body for a global
2+
// asm when the body has errors. See #137470.
3+
4+
//@ needs-asm-support
5+
6+
use std::arch::global_asm;
7+
8+
global_asm!("/* {} */", sym a);
9+
//~^ ERROR cannot find value `a` in this scope
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find value `a` in this scope
2+
--> $DIR/global-asm-with-error.rs:6:29
3+
|
4+
LL | global_asm!("/* {} */", sym a);
5+
| ^ not found in this scope
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)