Construct MIR error body for global_asm correctly

This commit is contained in:
Michael Goulet 2025-02-23 22:54:36 +00:00
parent 30f168ef81
commit c867b8f11d
3 changed files with 22 additions and 1 deletions

View File

@ -612,7 +612,8 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
| DefKind::AssocConst
| DefKind::AnonConst
| DefKind::InlineConst
| DefKind::Static { .. } => (vec![], tcx.type_of(def_id).instantiate_identity(), None),
| DefKind::Static { .. }
| DefKind::GlobalAsm => (vec![], tcx.type_of(def_id).instantiate_identity(), None),
DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => {
let sig = tcx.liberate_late_bound_regions(
def_id.to_def_id(),

View File

@ -0,0 +1,11 @@
// Ensure that we don't ICE when constructing the fake MIR body for a global
// asm when the body has errors. See #137470.
//@ needs-asm-support
use std::arch::global_asm;
global_asm!("/* {} */", sym a);
//~^ ERROR cannot find value `a` in this scope
fn main() {}

View File

@ -0,0 +1,9 @@
error[E0425]: cannot find value `a` in this scope
--> $DIR/global-asm-with-error.rs:6:29
|
LL | global_asm!("/* {} */", sym a);
| ^ not found in this scope
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0425`.