]> git.lizzy.rs Git - rust.git/commitdiff
Add error codes for libsyntax_ext
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Mon, 12 Feb 2018 22:21:20 +0000 (23:21 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 14 Apr 2018 15:25:35 +0000 (17:25 +0200)
src/libsyntax/ext/base.rs
src/libsyntax_ext/asm.rs
src/libsyntax_ext/diagnostics.rs [new file with mode: 0644]
src/libsyntax_ext/lib.rs

index c25a7686bead0e8296460215c42d1d199feaa8cc..0c313ab14899f54b824d0181f6ff8d4244824331 100644 (file)
@@ -14,7 +14,7 @@
 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 @@ pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> ! {
     pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
         self.parse_sess.span_diagnostic.span_err(sp, msg);
     }
+    pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
+        self.parse_sess.span_diagnostic.span_err_with_code(sp, msg, code);
+    }
     pub fn mut_span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str)
                         -> DiagnosticBuilder<'a> {
         self.parse_sess.span_diagnostic.mut_span_err(sp, msg)
index d1de4dccd00430b4d3885c3635d7d556b1c1eb00..e1eabc5cb01455919db258bcefeaae0abe8cdd98 100644 (file)
@@ -45,6 +45,17 @@ fn next(&self) -> 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 (file)
index 0000000..e247a22
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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##"
+"##,
+}
index 97e34c554d116f66fa8ab262381df5cf48f1c4b3..39ad594e5c5770b788a9effb25356d3e38813ae0 100644 (file)
@@ -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 rustc_data_structures;
 extern crate rustc_errors as errors;
 
+#[cfg(not(stage0))]
+mod diagnostics;
+
 mod assert;
 mod asm;
 mod cfg;