Skip to content

Commit 65a985e

Browse files
Check for llvm_asm in a const context
1 parent dbf8b6b commit 65a985e

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/librustc_mir/transform/check_consts/ops.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ impl NonConstOp for IfOrMatch {
147147
}
148148
}
149149

150+
#[derive(Debug)]
151+
pub struct InlineAsm;
152+
impl NonConstOp for InlineAsm {}
153+
150154
#[derive(Debug)]
151155
pub struct LiveDrop;
152156
impl NonConstOp for LiveDrop {

src/librustc_mir/transform/check_consts/validation.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,14 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
481481
StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => {
482482
self.check_op(ops::IfOrMatch);
483483
}
484+
StatementKind::LlvmInlineAsm { .. } => {
485+
self.check_op(ops::InlineAsm);
486+
}
487+
484488
// FIXME(eddyb) should these really do nothing?
485489
StatementKind::FakeRead(..)
486490
| StatementKind::StorageLive(_)
487491
| StatementKind::StorageDead(_)
488-
| StatementKind::LlvmInlineAsm { .. }
489492
| StatementKind::Retag { .. }
490493
| StatementKind::AscribeUserType(..)
491494
| StatementKind::Nop => {}

src/test/ui/consts/inline_asm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![feature(llvm_asm)]
2+
3+
const _: () = unsafe { llvm_asm!("nop") };
4+
//~^ ERROR contains unimplemented expression type
5+
6+
fn main() {}

src/test/ui/consts/inline_asm.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0019]: constant contains unimplemented expression type
2+
--> $DIR/inline_asm.rs:3:1
3+
|
4+
LL | const _: () = unsafe { llvm_asm!("nop") };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0019`.

0 commit comments

Comments
 (0)