diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index e1eabc5cb01455919db258bcefeaae0abe8cdd98..369c5b1ff60dbba182d5c272b6b551d98af2b3b7 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -179,9 +179,11 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, let (constraint, _str_style) = panictry!(p.parse_str()); if constraint.as_str().starts_with("=") { - cx.span_err(p.prev_span, "input operand constraint contains '='"); + span_err_if_not_stage0!(cx, p.prev_span, E0662, + "input operand constraint contains '='"); } else if constraint.as_str().starts_with("+") { - cx.span_err(p.prev_span, "input operand constraint contains '+'"); + span_err_if_not_stage0!(cx, p.prev_span, E0663, + "input operand constraint contains '+'"); } panictry!(p.expect(&token::OpenDelim(token::Paren))); @@ -203,7 +205,8 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, if OPTIONS.iter().any(|&opt| s == opt) { cx.span_warn(p.prev_span, "expected a clobber, found an option"); } else if s.as_str().starts_with("{") || s.as_str().ends_with("}") { - cx.span_err(p.prev_span, "clobber should not be surrounded by braces"); + span_err_if_not_stage0!(cx, p.prev_span, E0664, + "clobber should not be surrounded by braces"); } clobs.push(s); diff --git a/src/libsyntax_ext/diagnostics.rs b/src/libsyntax_ext/diagnostics.rs index a840c0392e9fe7cc663fd1a9bc85814a4bb4f98d..33ae24c37e53f2791c9bfe51630c3071a1e43816 100644 --- a/src/libsyntax_ext/diagnostics.rs +++ b/src/libsyntax_ext/diagnostics.rs @@ -38,6 +38,58 @@ asm!("nop" : "r"(a)); ``` +Considering that this would be a long explanation, we instead recommend you to +take a look at the unstable book: +https://doc.rust-lang.org/unstable-book/language-features/asm.html +"##, + +E0662: r##" +An invalid input operand constraint was passed to the `asm` macro (third line). + +Erroneous code example: + +```compile_fail,E0662 +asm!("xor %eax, %eax" + : + : "=test"("a") + ); +``` + +Considering that this would be a long explanation, we instead recommend you to +take a look at the unstable book: +https://doc.rust-lang.org/unstable-book/language-features/asm.html +"##, + +E0663: r##" +An invalid input operand constraint was passed to the `asm` macro (third line). + +Erroneous code example: + +```compile_fail,E0663 +asm!("xor %eax, %eax" + : + : "+test"("a") + ); +``` + +Considering that this would be a long explanation, we instead recommend you to +take a look at the unstable book: +https://doc.rust-lang.org/unstable-book/language-features/asm.html +"##, + +E0664: r##" +A clobber was surrounded by braces in the `asm` macro. + +Erroneous code example: + +```compile_fail,E0663 +asm!("mov $$0x200, %eax" + : + : + : "{eax}" + ); +``` + Considering that this would be a long explanation, we instead recommend you to take a look at the unstable book: https://doc.rust-lang.org/unstable-book/language-features/asm.html diff --git a/src/test/ui/E0662.rs b/src/test/ui/E0662.rs new file mode 100644 index 0000000000000000000000000000000000000000..6adb11c56169c956be8eb69665dad27a0ba15c33 --- /dev/null +++ b/src/test/ui/E0662.rs @@ -0,0 +1,20 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-stage1 + +#![feature(asm)] + +fn main() { + asm!("xor %eax, %eax" + : + : "=test"("a") //~ ERROR E0662 + ); +} diff --git a/src/test/ui/E0662.stderr b/src/test/ui/E0662.stderr new file mode 100644 index 0000000000000000000000000000000000000000..215e3a6d2f02357e7d1087ad3415cc756361ea11 --- /dev/null +++ b/src/test/ui/E0662.stderr @@ -0,0 +1,9 @@ +error[E0662]: input operand constraint contains '=' + --> $DIR/E0662.rs:18:12 + | +LL | : "=test"("a") //~ ERROR E0662 + | ^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0662`. diff --git a/src/test/ui/E0663.rs b/src/test/ui/E0663.rs new file mode 100644 index 0000000000000000000000000000000000000000..9eb05ada4a82a0c79d65d29149d1ce6efe198329 --- /dev/null +++ b/src/test/ui/E0663.rs @@ -0,0 +1,20 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-stage1 + +#![feature(asm)] + +fn main() { + asm!("xor %eax, %eax" + : + : "+test"("a") //~ ERROR E0663 + ); +} diff --git a/src/test/ui/E0663.stderr b/src/test/ui/E0663.stderr new file mode 100644 index 0000000000000000000000000000000000000000..123aa73eccc5e9e0e135c49e432f61bf7a3e9184 --- /dev/null +++ b/src/test/ui/E0663.stderr @@ -0,0 +1,9 @@ +error[E0663]: input operand constraint contains '+' + --> $DIR/E0663.rs:18:12 + | +LL | : "+test"("a") //~ ERROR E0663 + | ^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0663`. diff --git a/src/test/ui/E0664.rs b/src/test/ui/E0664.rs new file mode 100644 index 0000000000000000000000000000000000000000..738ffc18e38271bd353dfc3063090e331990516a --- /dev/null +++ b/src/test/ui/E0664.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-stage1 + +#![feature(asm)] + +fn main() { + asm!("mov $$0x200, %eax" + : + : + : "{eax}" //~ ERROR E0664 + ); +} diff --git a/src/test/ui/E0664.stderr b/src/test/ui/E0664.stderr new file mode 100644 index 0000000000000000000000000000000000000000..570811729be85a26bdb1142979a10a7cb0bb7807 --- /dev/null +++ b/src/test/ui/E0664.stderr @@ -0,0 +1,9 @@ +error[E0664]: clobber should not be surrounded by braces + --> $DIR/E0664.rs:19:12 + | +LL | : "{eax}" //~ ERROR E0664 + | ^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0664`.