Skip to content

Commit

Permalink
make sure we still eagerly emit errors
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Nov 25, 2023
1 parent a992def commit 82f23d5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,8 @@ impl<'tcx> Cx<'tcx> {
promoted: None,
},
tcx.type_of(anon_const.def_id).instantiate_identity(),
);
)
.normalize(tcx, self.param_env);
let span = tcx.def_span(anon_const.def_id);

InlineAsmOperand::Const { value, span }
Expand All @@ -668,7 +669,8 @@ impl<'tcx> Cx<'tcx> {
promoted: None,
},
tcx.type_of(anon_const.def_id).instantiate_identity(),
);
)
.normalize(tcx, self.param_env);
let span = tcx.def_span(anon_const.def_id);

InlineAsmOperand::SymFn { value, span }
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/asm/const-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// only-x86_64
// needs-asm-support

#![feature(asm_const)]

// Test to make sure that we emit const errors eagerly for inline asm

use std::arch::asm;

fn test<T>() {
unsafe { asm!("/* {} */", const 1 / 0); }
//~^ ERROR evaluation of
}

fn main() {}
9 changes: 9 additions & 0 deletions tests/ui/asm/const-error.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0080]: evaluation of `test::<T>::{constant#0}` failed
--> $DIR/const-error.rs:11:37
|
LL | unsafe { asm!("/* {} */", const 1 / 0); }
| ^^^^^ attempt to divide `1_i32` by zero

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.

0 comments on commit 82f23d5

Please sign in to comment.