Skip to content

Commit 3302190

Browse files
Clean some error codes diagnostics
1 parent 0aea1ca commit 3302190

File tree

7 files changed

+71
-53
lines changed

7 files changed

+71
-53
lines changed

src/librustc/middle/lib_features.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use syntax::ast::{Attribute, MetaItem, MetaItemKind};
1111
use syntax_pos::{Span, sym};
1212
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
1313
use rustc_macros::HashStable;
14-
use errors::DiagnosticId;
14+
15+
use rustc_error_codes::*;
1516

1617
#[derive(HashStable)]
1718
pub struct LibFeatures {
@@ -98,15 +99,16 @@ impl LibFeatureCollector<'tcx> {
9899
(Some(since), _, false) => {
99100
if let Some(prev_since) = self.lib_features.stable.get(&feature) {
100101
if *prev_since != since {
101-
let msg = format!(
102-
"feature `{}` is declared stable since {}, \
103-
but was previously declared stable since {}",
104-
feature,
105-
since,
106-
prev_since,
102+
self.span_feature_error(
103+
span,
104+
&format!(
105+
"feature `{}` is declared stable since {}, \
106+
but was previously declared stable since {}",
107+
feature,
108+
since,
109+
prev_since,
110+
),
107111
);
108-
self.tcx.sess.struct_span_err_with_code(span, &msg,
109-
DiagnosticId::Error("E0711".into())).emit();
110112
return;
111113
}
112114
}
@@ -117,17 +119,27 @@ impl LibFeatureCollector<'tcx> {
117119
self.lib_features.unstable.insert(feature);
118120
}
119121
(Some(_), _, true) | (None, true, _) => {
120-
let msg = format!(
121-
"feature `{}` is declared {}, but was previously declared {}",
122-
feature,
123-
if since.is_some() { "stable" } else { "unstable" },
124-
if since.is_none() { "stable" } else { "unstable" },
122+
self.span_feature_error(
123+
span,
124+
&format!(
125+
"feature `{}` is declared {}, but was previously declared {}",
126+
feature,
127+
if since.is_some() { "stable" } else { "unstable" },
128+
if since.is_none() { "stable" } else { "unstable" },
129+
),
125130
);
126-
self.tcx.sess.struct_span_err_with_code(span, &msg,
127-
DiagnosticId::Error("E0711".into())).emit();
128131
}
129132
}
130133
}
134+
135+
fn span_feature_error(&self, span: Span, msg: &str) {
136+
struct_span_err!(
137+
self.tcx.sess,
138+
span,
139+
E0711,
140+
"{}", &msg,
141+
).emit();
142+
}
131143
}
132144

133145
impl Visitor<'tcx> for LibFeatureCollector<'tcx> {

src/librustc_parse/parser/diagnostics.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use syntax::ThinVec;
1212
use syntax::util::parser::AssocOp;
1313
use syntax::struct_span_err;
1414

15-
use errors::{PResult, Applicability, DiagnosticBuilder, DiagnosticId, pluralize};
15+
use errors::{PResult, Applicability, DiagnosticBuilder, pluralize};
1616
use rustc_data_structures::fx::FxHashSet;
1717
use syntax_pos::{Span, DUMMY_SP, MultiSpan, SpanSnippetError};
1818
use log::{debug, trace};
@@ -1413,19 +1413,19 @@ impl<'a> Parser<'a> {
14131413
self.expect(&token::Colon)?;
14141414
let ty = self.parse_ty()?;
14151415

1416-
self.diagnostic()
1417-
.struct_span_err_with_code(
1418-
pat.span,
1419-
"patterns aren't allowed in methods without bodies",
1420-
DiagnosticId::Error("E0642".into()),
1421-
)
1422-
.span_suggestion_short(
1423-
pat.span,
1424-
"give this argument a name or use an underscore to ignore it",
1425-
"_".to_owned(),
1426-
Applicability::MachineApplicable,
1427-
)
1428-
.emit();
1416+
struct_span_err!(
1417+
self.diagnostic(),
1418+
pat.span,
1419+
E0642,
1420+
"patterns aren't allowed in methods without bodies",
1421+
)
1422+
.span_suggestion_short(
1423+
pat.span,
1424+
"give this argument a name or use an underscore to ignore it",
1425+
"_".to_owned(),
1426+
Applicability::MachineApplicable,
1427+
)
1428+
.emit();
14291429

14301430
// Pretend the pattern is `_`, to avoid duplicate errors from AST validation.
14311431
let pat = P(Pat {

src/librustc_parse/parser/item.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ use syntax::ThinVec;
1414
use syntax::token;
1515
use syntax::tokenstream::{TokenTree, TokenStream};
1616
use syntax::source_map::{self, respan, Span};
17+
use syntax::struct_span_err;
1718
use syntax_pos::BytePos;
1819
use syntax_pos::symbol::{kw, sym};
1920

21+
use rustc_error_codes::*;
22+
2023
use log::debug;
2124
use std::mem;
22-
use errors::{PResult, Applicability, DiagnosticBuilder, DiagnosticId, StashKey};
25+
use errors::{PResult, Applicability, DiagnosticBuilder, StashKey};
2326

2427
/// Whether the type alias or associated type is a concrete type or an opaque type.
2528
#[derive(Debug)]
@@ -842,10 +845,11 @@ impl<'a> Parser<'a> {
842845
if let token::DocComment(_) = self.token.kind {
843846
if self.look_ahead(1,
844847
|tok| tok == &token::CloseDelim(token::Brace)) {
845-
self.diagnostic().struct_span_err_with_code(
848+
struct_span_err!(
849+
self.diagnostic(),
846850
self.token.span,
851+
E0584,
847852
"found a documentation comment that doesn't document anything",
848-
DiagnosticId::Error("E0584".into()),
849853
)
850854
.help(
851855
"doc comments must come before what they document, maybe a \

src/librustc_parse/parser/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use syntax::util::comments::{doc_comment_style, strip_doc_comment_decoration};
3030
use syntax_pos::symbol::{kw, sym, Symbol};
3131
use syntax_pos::{Span, BytePos, DUMMY_SP, FileName};
3232
use rustc_data_structures::thin_vec::ThinVec;
33-
use errors::{PResult, Applicability, DiagnosticBuilder, DiagnosticId, FatalError};
33+
use errors::{PResult, Applicability, DiagnosticBuilder, FatalError};
3434
use log::debug;
3535

3636
use std::borrow::Cow;
@@ -1251,13 +1251,13 @@ impl<'a> Parser<'a> {
12511251
/// We are parsing `async fn`. If we are on Rust 2015, emit an error.
12521252
fn ban_async_in_2015(&self, async_span: Span) {
12531253
if async_span.rust_2015() {
1254-
self.diagnostic()
1255-
.struct_span_err_with_code(
1256-
async_span,
1257-
"`async fn` is not permitted in the 2015 edition",
1258-
DiagnosticId::Error("E0670".into())
1259-
)
1260-
.emit();
1254+
struct_span_err!(
1255+
self.diagnostic(),
1256+
async_span,
1257+
E0670,
1258+
"`async fn` is not permitted in the 2015 edition",
1259+
)
1260+
.emit();
12611261
}
12621262
}
12631263

src/librustc_resolve/diagnostics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::cmp::Reverse;
22

3-
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
3+
use errors::{Applicability, DiagnosticBuilder};
44
use log::debug;
55
use rustc::bug;
66
use rustc::hir::def::{self, DefKind, NonMacroAttrKind};
@@ -207,11 +207,11 @@ impl<'a> Resolver<'a> {
207207
let origin_sp = origin.iter().copied().collect::<Vec<_>>();
208208

209209
let msp = MultiSpan::from_spans(target_sp.clone());
210-
let msg = format!("variable `{}` is not bound in all patterns", name);
211-
let mut err = self.session.struct_span_err_with_code(
210+
let mut err = struct_span_err!(
211+
self.session,
212212
msp,
213-
&msg,
214-
DiagnosticId::Error("E0408".into()),
213+
E0408,
214+
"variable `{}` is not bound in all patterns", name,
215215
);
216216
for sp in target_sp {
217217
err.span_label(sp, format!("pattern doesn't bind `{}`", name));

src/librustc_typeck/check/wfcheck.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use syntax::ast;
1313
use syntax::feature_gate::{self, GateIssue};
1414
use syntax_pos::Span;
1515
use syntax::symbol::sym;
16-
use errors::{DiagnosticBuilder, DiagnosticId};
16+
use errors::DiagnosticBuilder;
1717

1818
use rustc::hir::itemlikevisit::ParItemLikeVisitor;
1919
use rustc::hir;
@@ -847,12 +847,13 @@ fn check_method_receiver<'fcx, 'tcx>(
847847
}
848848

849849
fn e0307(fcx: &FnCtxt<'fcx, 'tcx>, span: Span, receiver_ty: Ty<'_>) {
850-
fcx.tcx.sess.diagnostic().struct_span_err(
850+
struct_span_err!(
851+
fcx.tcx.sess.diagnostic(),
851852
span,
852-
&format!("invalid `self` parameter type: {:?}", receiver_ty)
853+
E0307,
854+
"invalid `self` parameter type: {:?}", receiver_ty,
853855
).note("type of `self` must be `Self` or a type that dereferences to it")
854856
.help(HELP_FOR_SELF_TYPE)
855-
.code(DiagnosticId::Error("E0307".into()))
856857
.emit();
857858
}
858859

src/librustc_typeck/collect.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
4646
use rustc::hir::GenericParamKind;
4747
use rustc::hir::{self, CodegenFnAttrFlags, CodegenFnAttrs, Unsafety};
4848

49-
use errors::{Applicability, DiagnosticId, StashKey};
49+
use errors::{Applicability, StashKey};
5050

5151
use rustc_error_codes::*;
5252

@@ -160,10 +160,11 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
160160
// Utility types and common code for the above passes.
161161

162162
fn bad_placeholder_type(tcx: TyCtxt<'tcx>, span: Span) -> errors::DiagnosticBuilder<'tcx> {
163-
let mut diag = tcx.sess.struct_span_err_with_code(
163+
let mut diag = struct_span_err!(
164+
tcx.sess,
164165
span,
166+
E0121,
165167
"the type placeholder `_` is not allowed within types on item signatures",
166-
DiagnosticId::Error("E0121".into()),
167168
);
168169
diag.span_label(span, "not allowed in type signatures");
169170
diag

0 commit comments

Comments
 (0)