]> git.lizzy.rs Git - rust.git/commitdiff
Check for `llvm_asm` in a const context
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Sun, 19 Apr 2020 23:03:35 +0000 (16:03 -0700)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Mon, 20 Apr 2020 00:50:56 +0000 (17:50 -0700)
src/librustc_mir/transform/check_consts/ops.rs
src/librustc_mir/transform/check_consts/validation.rs
src/test/ui/consts/inline_asm.rs [new file with mode: 0644]
src/test/ui/consts/inline_asm.stderr [new file with mode: 0644]

index b5e62aa20130b1eb0bdebfdaa3ad111cdcf5da70..c4b94b70938d33505fb7b204a8738cd517108d06 100644 (file)
@@ -147,6 +147,10 @@ fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
     }
 }
 
+#[derive(Debug)]
+pub struct InlineAsm;
+impl NonConstOp for InlineAsm {}
+
 #[derive(Debug)]
 pub struct LiveDrop;
 impl NonConstOp for LiveDrop {
index cee98e9b299c16e35183a2d4604dd26738e6ed36..19df6e39e4c2421d177583e40027b51800237364 100644 (file)
@@ -481,11 +481,14 @@ fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
             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 => {}
diff --git a/src/test/ui/consts/inline_asm.rs b/src/test/ui/consts/inline_asm.rs
new file mode 100644 (file)
index 0000000..c2ab97e
--- /dev/null
@@ -0,0 +1,6 @@
+#![feature(llvm_asm)]
+
+const _: () = unsafe { llvm_asm!("nop") };
+//~^ ERROR contains unimplemented expression type
+
+fn main() {}
diff --git a/src/test/ui/consts/inline_asm.stderr b/src/test/ui/consts/inline_asm.stderr
new file mode 100644 (file)
index 0000000..68a78d6
--- /dev/null
@@ -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`.