Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 44c6861

Browse files
Add error codes for libsyntax_ext
1 parent fb730d7 commit 44c6861

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

src/libsyntax/ext/base.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ast::{self, Attribute, Name, PatKind, MetaItem};
1414
use attr::HasAttrs;
1515
use codemap::{self, CodeMap, Spanned, respan};
1616
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
17-
use errors::DiagnosticBuilder;
17+
use errors::{DiagnosticBuilder, DiagnosticId};
1818
use ext::expand::{self, Expansion, Invocation};
1919
use ext::hygiene::{Mark, SyntaxContext};
2020
use fold::{self, Folder};
@@ -841,6 +841,9 @@ impl<'a> ExtCtxt<'a> {
841841
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
842842
self.parse_sess.span_diagnostic.span_err(sp, msg);
843843
}
844+
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: DiagnosticId) {
845+
self.parse_sess.span_diagnostic.span_err_with_code(sp, msg, code);
846+
}
844847
pub fn mut_span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str)
845848
-> DiagnosticBuilder<'a> {
846849
self.parse_sess.span_diagnostic.mut_span_err(sp, msg)

src/libsyntax_ext/asm.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ impl State {
4545
}
4646
}
4747

48+
macro_rules! span_err_if_not_stage0 {
49+
($cx:expr, $sp:expr, $code:ident, $text:tt) => {
50+
#[cfg(not(stage0))] {
51+
span_err!($cx, $sp, $code, $text)
52+
}
53+
#[cfg(stage0)] {
54+
$cx.span_err($sp, $text)
55+
}
56+
}
57+
}
58+
4859
const OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"];
4960

5061
pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
@@ -89,7 +100,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
89100
if asm_str_style.is_some() {
90101
// If we already have a string with instructions,
91102
// ending up in Asm state again is an error.
92-
cx.span_err(sp, "malformed inline assembly");
103+
span_err_if_not_stage0!(cx, sp, E0660, "malformed inline assembly");
93104
return DummyResult::expr(sp);
94105
}
95106
// Nested parser, stop before the first colon (see above).
@@ -142,7 +153,8 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
142153
Some(Symbol::intern(&format!("={}", ch.as_str())))
143154
}
144155
_ => {
145-
cx.span_err(span, "output operand constraint lacks '=' or '+'");
156+
span_err_if_not_stage0!(cx, span, E0661,
157+
"output operand constraint lacks '=' or '+'");
146158
None
147159
}
148160
};

src/libsyntax_ext/diagnostics.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![allow(non_snake_case)]
12+
13+
// Error messages for EXXXX errors.
14+
// Each message should start and end with a new line, and be wrapped to 80 characters.
15+
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
16+
register_long_diagnostics! {
17+
E0660: r##"
18+
"##,
19+
20+
E0661: r##"
21+
"##,
22+
}

src/libsyntax_ext/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#![feature(decl_macro)]
1919
#![feature(str_escape)]
2020

21+
#![cfg_attr(not(stage0), feature(rustc_diagnostic_macros))]
22+
2123
extern crate fmt_macros;
2224
#[macro_use]
2325
extern crate syntax;
@@ -26,6 +28,9 @@ extern crate proc_macro;
2628
extern crate rustc_data_structures;
2729
extern crate rustc_errors as errors;
2830

31+
#[cfg(not(stage0))]
32+
mod diagnostics;
33+
2934
mod assert;
3035
mod asm;
3136
mod cfg;

0 commit comments

Comments
 (0)