Skip to content

Commit

Permalink
add label to unknown meta item error
Browse files Browse the repository at this point in the history
  • Loading branch information
euclio committed Jul 1, 2018
1 parent f315943 commit 5468e12
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
44 changes: 33 additions & 11 deletions src/libsyntax/attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::{list_contains_name, mark_used, MetaItemKind};

enum AttrError {
MultipleItem(Name),
UnknownMetaItem(Name),
UnknownMetaItem(Name, &'static [&'static str]),
MissingSince,
MissingFeature,
MultipleStabilityLevels,
Expand All @@ -31,8 +31,15 @@ fn handle_errors(diag: &Handler, span: Span, error: AttrError) {
match error {
AttrError::MultipleItem(item) => span_err!(diag, span, E0538,
"multiple '{}' items", item),
AttrError::UnknownMetaItem(item) => span_err!(diag, span, E0541,
"unknown meta item '{}'", item),
AttrError::UnknownMetaItem(item, expected) => {
let expected = expected
.iter()
.map(|name| format!("`{}`", name))
.collect::<Vec<_>>();
struct_span_err!(diag, span, E0541, "unknown meta item '{}'", item)
.span_label(span, format!("expected one of {}", expected.join(", ")))
.emit();
}
AttrError::MissingSince => span_err!(diag, span, E0542, "missing 'since'"),
AttrError::MissingFeature => span_err!(diag, span, E0546, "missing 'feature'"),
AttrError::MultipleStabilityLevels => span_err!(diag, span, E0544,
Expand Down Expand Up @@ -213,8 +220,11 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
=> if !get(mi, &mut $name) { continue 'outer },
)+
_ => {
handle_errors(diagnostic, mi.span,
AttrError::UnknownMetaItem(mi.name()));
let expected = &[ $( stringify!($name) ),+ ];
handle_errors(
diagnostic,
mi.span,
AttrError::UnknownMetaItem(mi.name(), expected));
continue 'outer
}
}
Expand Down Expand Up @@ -286,8 +296,14 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
"reason" => if !get(mi, &mut reason) { continue 'outer },
"issue" => if !get(mi, &mut issue) { continue 'outer },
_ => {
handle_errors(diagnostic, meta.span,
AttrError::UnknownMetaItem(mi.name()));
handle_errors(
diagnostic,
meta.span,
AttrError::UnknownMetaItem(
mi.name(),
&["feature", "reason", "issue"]
),
);
continue 'outer
}
}
Expand Down Expand Up @@ -341,8 +357,11 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
"feature" => if !get(mi, &mut feature) { continue 'outer },
"since" => if !get(mi, &mut since) { continue 'outer },
_ => {
handle_errors(diagnostic, meta.span,
AttrError::UnknownMetaItem(mi.name()));
handle_errors(
diagnostic,
meta.span,
AttrError::UnknownMetaItem(mi.name(), &["since", "note"]),
);
continue 'outer
}
}
Expand Down Expand Up @@ -520,8 +539,11 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
"since" => if !get(mi, &mut since) { continue 'outer },
"note" => if !get(mi, &mut note) { continue 'outer },
_ => {
handle_errors(diagnostic, meta.span,
AttrError::UnknownMetaItem(mi.name()));
handle_errors(
diagnostic,
meta.span,
AttrError::UnknownMetaItem(mi.name(), &["since", "note"]),
);
continue 'outer
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/deprecation-sanity.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0541]: unknown meta item 'reason'
--> $DIR/deprecation-sanity.rs:14:43
|
LL | #[deprecated(since = "a", note = "a", reason)] //~ ERROR unknown meta item 'reason'
| ^^^^^^
| ^^^^^^ expected one of `since`, `note`

error[E0551]: incorrect meta item
--> $DIR/deprecation-sanity.rs:17:31
Expand Down

0 comments on commit 5468e12

Please sign in to comment.