diff options
| author | Michael Goulet <michael@errs.io> | 2023-10-05 09:43:55 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-11-25 18:00:35 +0000 |
| commit | 82f23d56b758d87e5eee642946ad8a422e6542ba (patch) | |
| tree | 453fa52e17c15547d51529b46dfdfd0771d21cf3 | |
| parent | a992defc8b0d7937d0422003984b7b5d3e5f472e (diff) | |
| download | rust-82f23d56b758d87e5eee642946ad8a422e6542ba.tar.gz rust-82f23d56b758d87e5eee642946ad8a422e6542ba.zip | |
make sure we still eagerly emit errors
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/cx/expr.rs | 6 | ||||
| -rw-r--r-- | tests/ui/asm/const-error.rs | 15 | ||||
| -rw-r--r-- | tests/ui/asm/const-error.stderr | 9 |
3 files changed, 28 insertions, 2 deletions
diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index e01ee45180f..b07ffe7293b 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -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 } @@ -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 } diff --git a/tests/ui/asm/const-error.rs b/tests/ui/asm/const-error.rs new file mode 100644 index 00000000000..4e14becf74b --- /dev/null +++ b/tests/ui/asm/const-error.rs @@ -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() {} diff --git a/tests/ui/asm/const-error.stderr b/tests/ui/asm/const-error.stderr new file mode 100644 index 00000000000..fe311832177 --- /dev/null +++ b/tests/ui/asm/const-error.stderr @@ -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`. |
