From 44c686113fe93bb67ac2dcb1db500b5b8cbf0b6a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 12 Feb 2018 23:21:20 +0100 Subject: [PATCH 1/3] Add error codes for libsyntax_ext --- src/libsyntax/ext/base.rs | 5 ++++- src/libsyntax_ext/asm.rs | 16 ++++++++++++++-- src/libsyntax_ext/diagnostics.rs | 22 ++++++++++++++++++++++ src/libsyntax_ext/lib.rs | 5 +++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/libsyntax_ext/diagnostics.rs diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index c25a7686bead0..0c313ab14899f 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -14,7 +14,7 @@ use ast::{self, Attribute, Name, PatKind, MetaItem}; use attr::HasAttrs; use codemap::{self, CodeMap, Spanned, respan}; use syntax_pos::{Span, MultiSpan, DUMMY_SP}; -use errors::DiagnosticBuilder; +use errors::{DiagnosticBuilder, DiagnosticId}; use ext::expand::{self, Expansion, Invocation}; use ext::hygiene::{Mark, SyntaxContext}; use fold::{self, Folder}; @@ -841,6 +841,9 @@ impl<'a> ExtCtxt<'a> { pub fn span_err>(&self, sp: S, msg: &str) { self.parse_sess.span_diagnostic.span_err(sp, msg); } + pub fn span_err_with_code>(&self, sp: S, msg: &str, code: DiagnosticId) { + self.parse_sess.span_diagnostic.span_err_with_code(sp, msg, code); + } pub fn mut_span_err>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'a> { self.parse_sess.span_diagnostic.mut_span_err(sp, msg) diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index d1de4dccd0043..e1eabc5cb0145 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -45,6 +45,17 @@ impl State { } } +macro_rules! span_err_if_not_stage0 { + ($cx:expr, $sp:expr, $code:ident, $text:tt) => { + #[cfg(not(stage0))] { + span_err!($cx, $sp, $code, $text) + } + #[cfg(stage0)] { + $cx.span_err($sp, $text) + } + } +} + const OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"]; pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, @@ -89,7 +100,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, if asm_str_style.is_some() { // If we already have a string with instructions, // ending up in Asm state again is an error. - cx.span_err(sp, "malformed inline assembly"); + span_err_if_not_stage0!(cx, sp, E0660, "malformed inline assembly"); return DummyResult::expr(sp); } // Nested parser, stop before the first colon (see above). @@ -142,7 +153,8 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, Some(Symbol::intern(&format!("={}", ch.as_str()))) } _ => { - cx.span_err(span, "output operand constraint lacks '=' or '+'"); + span_err_if_not_stage0!(cx, span, E0661, + "output operand constraint lacks '=' or '+'"); None } }; diff --git a/src/libsyntax_ext/diagnostics.rs b/src/libsyntax_ext/diagnostics.rs new file mode 100644 index 0000000000000..e247a22aeb073 --- /dev/null +++ b/src/libsyntax_ext/diagnostics.rs @@ -0,0 +1,22 @@ +// Copyright 2014 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. + +#![allow(non_snake_case)] + +// Error messages for EXXXX errors. +// Each message should start and end with a new line, and be wrapped to 80 characters. +// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable. +register_long_diagnostics! { +E0660: r##" +"##, + +E0661: r##" +"##, +} diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index 97e34c554d116..39ad594e5c577 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -18,6 +18,8 @@ #![feature(decl_macro)] #![feature(str_escape)] +#![cfg_attr(not(stage0), feature(rustc_diagnostic_macros))] + extern crate fmt_macros; #[macro_use] extern crate syntax; @@ -26,6 +28,9 @@ extern crate proc_macro; extern crate rustc_data_structures; extern crate rustc_errors as errors; +#[cfg(not(stage0))] +mod diagnostics; + mod assert; mod asm; mod cfg; From 5d52ef5091b8e993477fff36efd4cc6f2df33491 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 26 Mar 2018 22:04:27 +0200 Subject: [PATCH 2/3] Add tests and longer error explanation --- src/libsyntax_ext/diagnostics.rs | 25 ++++++++++++++++++- .../issue-21045.rs => ui/E0660.rs} | 5 ++-- src/test/ui/E0660.stderr | 15 +++++++++++ src/test/ui/E0661.rs | 16 ++++++++++++ src/test/ui/E0661.stderr | 9 +++++++ 5 files changed, 67 insertions(+), 3 deletions(-) rename src/test/{compile-fail/issue-21045.rs => ui/E0660.rs} (79%) create mode 100644 src/test/ui/E0660.stderr create mode 100644 src/test/ui/E0661.rs create mode 100644 src/test/ui/E0661.stderr diff --git a/src/libsyntax_ext/diagnostics.rs b/src/libsyntax_ext/diagnostics.rs index e247a22aeb073..a840c0392e9fe 100644 --- a/src/libsyntax_ext/diagnostics.rs +++ b/src/libsyntax_ext/diagnostics.rs @@ -1,4 +1,4 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// 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. // @@ -15,8 +15,31 @@ // In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable. register_long_diagnostics! { E0660: r##" +The argument to the `asm` macro is not well-formed. + +Erroneous code example: + +```compile_fail,E0660 +asm!("nop" "nop"); +``` + +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 "##, E0661: r##" +An invalid syntax was passed to the second argument of an `asm` macro line. + +Erroneous code example: + +```compile_fail,E0661 +let a; +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 "##, } diff --git a/src/test/compile-fail/issue-21045.rs b/src/test/ui/E0660.rs similarity index 79% rename from src/test/compile-fail/issue-21045.rs rename to src/test/ui/E0660.rs index 134240f8c8aa3..dbea0c8e7d847 100644 --- a/src/test/compile-fail/issue-21045.rs +++ b/src/test/ui/E0660.rs @@ -7,10 +7,11 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. + #![feature(asm)] fn main() { let a; - asm!("nop" "nop"); //~ ERROR malformed inline assembly - asm!("nop" "nop" : "=r"(a)); //~ ERROR malformed inline assembly + asm!("nop" "nop"); + asm!("nop" "nop" : "=r"(a)); } diff --git a/src/test/ui/E0660.stderr b/src/test/ui/E0660.stderr new file mode 100644 index 0000000000000..0ef8fc4648794 --- /dev/null +++ b/src/test/ui/E0660.stderr @@ -0,0 +1,15 @@ +error[E0660]: malformed inline assembly + --> $DIR/E0660.rs:15:5 + | +LL | asm!("nop" "nop"); + | ^^^^^^^^^^^^^^^^^^ + +error[E0660]: malformed inline assembly + --> $DIR/E0660.rs:16:5 + | +LL | asm!("nop" "nop" : "=r"(a)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0660`. diff --git a/src/test/ui/E0661.rs b/src/test/ui/E0661.rs new file mode 100644 index 0000000000000..be932a0d471d5 --- /dev/null +++ b/src/test/ui/E0661.rs @@ -0,0 +1,16 @@ +// 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. + +#![feature(asm)] + +fn main() { + let a; + asm!("nop" : "r"(a)); +} diff --git a/src/test/ui/E0661.stderr b/src/test/ui/E0661.stderr new file mode 100644 index 0000000000000..90aeca5612ae4 --- /dev/null +++ b/src/test/ui/E0661.stderr @@ -0,0 +1,9 @@ +error[E0661]: output operand constraint lacks '=' or '+' + --> $DIR/E0661.rs:15:18 + | +LL | asm!("nop" : "r"(a)); + | ^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0661`. From f367567e06b9c05938b38df44e1dc990eb12cb26 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 13 Apr 2018 23:22:01 +0200 Subject: [PATCH 3/3] ignore stage1 testing --- src/test/ui/E0660.rs | 4 ++++ src/test/ui/E0660.stderr | 4 ++-- src/test/ui/E0661.rs | 3 +++ src/test/ui/E0661.stderr | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/test/ui/E0660.rs b/src/test/ui/E0660.rs index dbea0c8e7d847..82ef38e96cded 100644 --- a/src/test/ui/E0660.rs +++ b/src/test/ui/E0660.rs @@ -8,10 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-stage1 + #![feature(asm)] fn main() { let a; asm!("nop" "nop"); + //~^ ERROR E0660 asm!("nop" "nop" : "=r"(a)); + //~^ ERROR E0660 } diff --git a/src/test/ui/E0660.stderr b/src/test/ui/E0660.stderr index 0ef8fc4648794..fcf3e9a255273 100644 --- a/src/test/ui/E0660.stderr +++ b/src/test/ui/E0660.stderr @@ -1,11 +1,11 @@ error[E0660]: malformed inline assembly - --> $DIR/E0660.rs:15:5 + --> $DIR/E0660.rs:17:5 | LL | asm!("nop" "nop"); | ^^^^^^^^^^^^^^^^^^ error[E0660]: malformed inline assembly - --> $DIR/E0660.rs:16:5 + --> $DIR/E0660.rs:19:5 | LL | asm!("nop" "nop" : "=r"(a)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/E0661.rs b/src/test/ui/E0661.rs index be932a0d471d5..7f8a0d8b57420 100644 --- a/src/test/ui/E0661.rs +++ b/src/test/ui/E0661.rs @@ -8,9 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-stage1 + #![feature(asm)] fn main() { let a; asm!("nop" : "r"(a)); + //~^ ERROR E0661 } diff --git a/src/test/ui/E0661.stderr b/src/test/ui/E0661.stderr index 90aeca5612ae4..d8b974d424074 100644 --- a/src/test/ui/E0661.stderr +++ b/src/test/ui/E0661.stderr @@ -1,5 +1,5 @@ error[E0661]: output operand constraint lacks '=' or '+' - --> $DIR/E0661.rs:15:18 + --> $DIR/E0661.rs:17:18 | LL | asm!("nop" : "r"(a)); | ^^^