Rollup merge of #68670 - euclio:invalid-issue, r=estebank
clarify "incorrect issue" error Changes the message to be more precise, shrinks the span and adds a label specifying why the `issue` field is incorrect.
This commit is contained in:
commit
f60b95aaa1
5 changed files with 47 additions and 30 deletions
|
@ -371,6 +371,7 @@ where
|
||||||
let mut feature = None;
|
let mut feature = None;
|
||||||
let mut reason = None;
|
let mut reason = None;
|
||||||
let mut issue = None;
|
let mut issue = None;
|
||||||
|
let mut issue_num = None;
|
||||||
let mut is_soft = false;
|
let mut is_soft = false;
|
||||||
for meta in metas {
|
for meta in metas {
|
||||||
if let Some(mi) = meta.meta_item() {
|
if let Some(mi) = meta.meta_item() {
|
||||||
|
@ -389,6 +390,37 @@ where
|
||||||
if !get(mi, &mut issue) {
|
if !get(mi, &mut issue) {
|
||||||
continue 'outer;
|
continue 'outer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These unwraps are safe because `get` ensures the meta item
|
||||||
|
// is a name/value pair string literal.
|
||||||
|
issue_num = match &*issue.unwrap().as_str() {
|
||||||
|
"none" => None,
|
||||||
|
issue => {
|
||||||
|
match issue.parse() {
|
||||||
|
Ok(num) => {
|
||||||
|
// FIXME(rossmacarthur): disallow 0
|
||||||
|
// Disallowing this requires updates to
|
||||||
|
// some submodules
|
||||||
|
NonZeroU32::new(num)
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
struct_span_err!(
|
||||||
|
diagnostic,
|
||||||
|
mi.span,
|
||||||
|
E0545,
|
||||||
|
"`issue` must be a numeric string \
|
||||||
|
or \"none\"",
|
||||||
|
)
|
||||||
|
.span_label(
|
||||||
|
mi.name_value_literal().unwrap().span,
|
||||||
|
&err.to_string(),
|
||||||
|
)
|
||||||
|
.emit();
|
||||||
|
continue 'outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
sym::soft => {
|
sym::soft => {
|
||||||
if !mi.is_word() {
|
if !mi.is_word() {
|
||||||
|
@ -420,27 +452,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
match (feature, reason, issue) {
|
match (feature, reason, issue) {
|
||||||
(Some(feature), reason, Some(issue)) => {
|
(Some(feature), reason, Some(_)) => {
|
||||||
let issue = match &*issue.as_str() {
|
let level = Unstable { reason, issue: issue_num, is_soft };
|
||||||
"none" => None,
|
|
||||||
issue => {
|
|
||||||
if let Ok(num) = issue.parse() {
|
|
||||||
// FIXME(rossmacarthur): disallow 0
|
|
||||||
// Disallowing this requires updates to some submodules
|
|
||||||
NonZeroU32::new(num)
|
|
||||||
} else {
|
|
||||||
struct_span_err!(
|
|
||||||
diagnostic,
|
|
||||||
attr.span,
|
|
||||||
E0545,
|
|
||||||
"incorrect 'issue'"
|
|
||||||
)
|
|
||||||
.emit();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let level = Unstable { reason, issue, is_soft };
|
|
||||||
if sym::unstable == meta_name {
|
if sym::unstable == meta_name {
|
||||||
stab = Some(Stability { level, feature, rustc_depr: None });
|
stab = Some(Stability { level, feature, rustc_depr: None });
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -9,5 +9,5 @@ fn unstable_issue_0() {}
|
||||||
#[unstable(feature = "unstable_test_feature", issue = "none")]
|
#[unstable(feature = "unstable_test_feature", issue = "none")]
|
||||||
fn unstable_issue_none() {}
|
fn unstable_issue_none() {}
|
||||||
|
|
||||||
#[unstable(feature = "unstable_test_feature", issue = "something")] //~ ERROR incorrect 'issue'
|
#[unstable(feature = "unstable_test_feature", issue = "something")]
|
||||||
fn unstable_issue_not_allowed() {}
|
fn unstable_issue_not_allowed() {} //~^ ERROR `issue` must be a numeric string or "none"
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
error[E0545]: incorrect 'issue'
|
error[E0545]: `issue` must be a numeric string or "none"
|
||||||
--> $DIR/unstable-attribute-allow-issue-0.rs:12:1
|
--> $DIR/unstable-attribute-allow-issue-0.rs:12:47
|
||||||
|
|
|
|
||||||
LL | #[unstable(feature = "unstable_test_feature", issue = "something")]
|
LL | #[unstable(feature = "unstable_test_feature", issue = "something")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^-----------
|
||||||
|
| |
|
||||||
|
| invalid digit found in string
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ fn f1() { }
|
||||||
#[stable(feature = "a", sinse = "1.0.0")] //~ ERROR unknown meta item 'sinse'
|
#[stable(feature = "a", sinse = "1.0.0")] //~ ERROR unknown meta item 'sinse'
|
||||||
fn f2() { }
|
fn f2() { }
|
||||||
|
|
||||||
#[unstable(feature = "a", issue = "no")] //~ ERROR incorrect 'issue'
|
#[unstable(feature = "a", issue = "no")] //~ ERROR `issue` must be a numeric string or "none"
|
||||||
fn f3() { }
|
fn f3() { }
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
|
|
@ -10,11 +10,13 @@ error[E0541]: unknown meta item 'sinse'
|
||||||
LL | #[stable(feature = "a", sinse = "1.0.0")]
|
LL | #[stable(feature = "a", sinse = "1.0.0")]
|
||||||
| ^^^^^^^^^^^^^^^ expected one of `since`, `note`
|
| ^^^^^^^^^^^^^^^ expected one of `since`, `note`
|
||||||
|
|
||||||
error[E0545]: incorrect 'issue'
|
error[E0545]: `issue` must be a numeric string or "none"
|
||||||
--> $DIR/stability-attribute-sanity-2.rs:13:1
|
--> $DIR/stability-attribute-sanity-2.rs:13:27
|
||||||
|
|
|
|
||||||
LL | #[unstable(feature = "a", issue = "no")]
|
LL | #[unstable(feature = "a", issue = "no")]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^----
|
||||||
|
| |
|
||||||
|
| invalid digit found in string
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue