Skip to content

Commit 609ffa1

Browse files
committedMay 25, 2019
Reword malformed attribute input diagnostics
- Handle empty `cfg_attr` attribute - Reword empty `derive` attribute error - Use consistend error message: "malformed `attrname` attribute input" - Provide suggestions when possible - Move note/help to label/suggestion - Use consistent wording "ill-formed" -> "malformed" - Move diagnostic logic out of parser
1 parent 02f5786 commit 609ffa1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+375
-272
lines changed
 

‎src/librustc/lint/levels.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'a> LintLevelsBuilder<'a> {
191191
let store = self.sess.lint_store.borrow();
192192
let sess = self.sess;
193193
let bad_attr = |span| {
194-
struct_span_err!(sess, span, E0452, "malformed lint attribute")
194+
struct_span_err!(sess, span, E0452, "malformed lint attribute input")
195195
};
196196
for attr in attrs {
197197
let level = match Level::from_symbol(attr.name_or_empty()) {
@@ -238,18 +238,20 @@ impl<'a> LintLevelsBuilder<'a> {
238238
}
239239
reason = Some(rationale);
240240
} else {
241-
let mut err = bad_attr(name_value.span);
242-
err.help("reason must be a string literal");
243-
err.emit();
241+
bad_attr(name_value.span)
242+
.span_label(name_value.span, "reason must be a string literal")
243+
.emit();
244244
}
245245
} else {
246-
let mut err = bad_attr(item.span);
247-
err.emit();
246+
bad_attr(item.span)
247+
.span_label(item.span, "bad attribute argument")
248+
.emit();
248249
}
249250
},
250251
ast::MetaItemKind::List(_) => {
251-
let mut err = bad_attr(item.span);
252-
err.emit();
252+
bad_attr(item.span)
253+
.span_label(item.span, "bad attribute argument")
254+
.emit();
253255
}
254256
}
255257
}
@@ -258,14 +260,20 @@ impl<'a> LintLevelsBuilder<'a> {
258260
let meta_item = match li.meta_item() {
259261
Some(meta_item) if meta_item.is_word() => meta_item,
260262
_ => {
261-
let mut err = bad_attr(li.span());
263+
let sp = li.span();
264+
let mut err = bad_attr(sp);
265+
let mut add_label = true;
262266
if let Some(item) = li.meta_item() {
263267
if let ast::MetaItemKind::NameValue(_) = item.node {
264268
if item.path == sym::reason {
265-
err.help("reason in lint attribute must come last");
269+
err.span_label(sp, "reason in lint attribute must come last");
270+
add_label = false;
266271
}
267272
}
268273
}
274+
if add_label {
275+
err.span_label(sp, "bad attribute argument");
276+
}
269277
err.emit();
270278
continue;
271279
}
@@ -318,15 +326,14 @@ impl<'a> LintLevelsBuilder<'a> {
318326
Also `cfg_attr(cargo-clippy)` won't be necessary anymore",
319327
name
320328
);
321-
let mut err = lint::struct_lint_level(
329+
lint::struct_lint_level(
322330
self.sess,
323331
lint,
324332
lvl,
325333
src,
326334
Some(li.span().into()),
327335
&msg,
328-
);
329-
err.span_suggestion(
336+
).span_suggestion(
330337
li.span(),
331338
"change it to",
332339
new_lint_name.to_string(),

‎src/librustc_plugin/load.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::env;
1010
use std::mem;
1111
use std::path::PathBuf;
1212
use syntax::ast;
13-
use syntax::span_err;
13+
use syntax::struct_span_err;
1414
use syntax::symbol::{Symbol, kw, sym};
1515
use syntax_pos::{Span, DUMMY_SP};
1616

@@ -29,8 +29,10 @@ struct PluginLoader<'a> {
2929
plugins: Vec<PluginRegistrar>,
3030
}
3131

32-
fn call_malformed_plugin_attribute(a: &Session, b: Span) {
33-
span_err!(a, b, E0498, "malformed plugin attribute");
32+
fn call_malformed_plugin_attribute(sess: &Session, span: Span) {
33+
struct_span_err!(sess, span, E0498, "malformed `plugin` attribute")
34+
.span_label(span, "malformed attribute")
35+
.emit();
3436
}
3537

3638
/// Read plugin metadata and dynamically load registrar functions.

0 commit comments

Comments
 (0)