clarify "incorrect issue" error
This commit is contained in:
parent
c4071d0919
commit
7632ade65b
@ -371,6 +371,7 @@ macro_rules! get_meta {
|
||||
let mut feature = None;
|
||||
let mut reason = None;
|
||||
let mut issue = None;
|
||||
let mut issue_num = None;
|
||||
let mut is_soft = false;
|
||||
for meta in metas {
|
||||
if let Some(mi) = meta.meta_item() {
|
||||
@ -389,6 +390,37 @@ macro_rules! get_meta {
|
||||
if !get(mi, &mut issue) {
|
||||
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 => {
|
||||
if !mi.is_word() {
|
||||
@ -420,27 +452,8 @@ macro_rules! get_meta {
|
||||
}
|
||||
|
||||
match (feature, reason, issue) {
|
||||
(Some(feature), reason, Some(issue)) => {
|
||||
let issue = match &*issue.as_str() {
|
||||
"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 };
|
||||
(Some(feature), reason, Some(_)) => {
|
||||
let level = Unstable { reason, issue: issue_num, is_soft };
|
||||
if sym::unstable == meta_name {
|
||||
stab = Some(Stability { level, feature, rustc_depr: None });
|
||||
} else {
|
||||
|
@ -9,5 +9,5 @@ fn unstable_issue_0() {}
|
||||
#[unstable(feature = "unstable_test_feature", issue = "none")]
|
||||
fn unstable_issue_none() {}
|
||||
|
||||
#[unstable(feature = "unstable_test_feature", issue = "something")] //~ ERROR incorrect 'issue'
|
||||
fn unstable_issue_not_allowed() {}
|
||||
#[unstable(feature = "unstable_test_feature", issue = "something")]
|
||||
fn unstable_issue_not_allowed() {} //~^ ERROR `issue` must be a numeric string or "none"
|
||||
|
@ -1,8 +1,10 @@
|
||||
error[E0545]: incorrect 'issue'
|
||||
--> $DIR/unstable-attribute-allow-issue-0.rs:12:1
|
||||
error[E0545]: `issue` must be a numeric string or "none"
|
||||
--> $DIR/unstable-attribute-allow-issue-0.rs:12:47
|
||||
|
|
||||
LL | #[unstable(feature = "unstable_test_feature", issue = "something")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^-----------
|
||||
| |
|
||||
| invalid digit found in string
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -10,7 +10,7 @@ fn f1() { }
|
||||
#[stable(feature = "a", sinse = "1.0.0")] //~ ERROR unknown meta item 'sinse'
|
||||
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 main() { }
|
||||
|
@ -10,11 +10,13 @@ error[E0541]: unknown meta item 'sinse'
|
||||
LL | #[stable(feature = "a", sinse = "1.0.0")]
|
||||
| ^^^^^^^^^^^^^^^ expected one of `since`, `note`
|
||||
|
||||
error[E0545]: incorrect 'issue'
|
||||
--> $DIR/stability-attribute-sanity-2.rs:13:1
|
||||
error[E0545]: `issue` must be a numeric string or "none"
|
||||
--> $DIR/stability-attribute-sanity-2.rs:13:27
|
||||
|
|
||||
LL | #[unstable(feature = "a", issue = "no")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^----
|
||||
| |
|
||||
| invalid digit found in string
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user