Check for llvm_asm in a const context

This commit is contained in:
Dylan MacKenzie 2020-04-19 16:03:35 -07:00
parent dbf8b6bf11
commit 65a985e81e
4 changed files with 23 additions and 1 deletions

View File

@ -147,6 +147,10 @@ impl NonConstOp for IfOrMatch {
}
}
#[derive(Debug)]
pub struct InlineAsm;
impl NonConstOp for InlineAsm {}
#[derive(Debug)]
pub struct LiveDrop;
impl NonConstOp for LiveDrop {

View File

@ -481,11 +481,14 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => {
self.check_op(ops::IfOrMatch);
}
StatementKind::LlvmInlineAsm { .. } => {
self.check_op(ops::InlineAsm);
}
// FIXME(eddyb) should these really do nothing?
StatementKind::FakeRead(..)
| StatementKind::StorageLive(_)
| StatementKind::StorageDead(_)
| StatementKind::LlvmInlineAsm { .. }
| StatementKind::Retag { .. }
| StatementKind::AscribeUserType(..)
| StatementKind::Nop => {}

View File

@ -0,0 +1,6 @@
#![feature(llvm_asm)]
const _: () = unsafe { llvm_asm!("nop") };
//~^ ERROR contains unimplemented expression type
fn main() {}

View File

@ -0,0 +1,9 @@
error[E0019]: constant contains unimplemented expression type
--> $DIR/inline_asm.rs:3:1
|
LL | const _: () = unsafe { llvm_asm!("nop") };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0019`.