Skip to content

clarify "incorrect issue" error #68670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 34 additions & 21 deletions src/libsyntax/attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ where
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() {
Expand All @@ -389,6 +390,37 @@ where
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make 0 to act as "none"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, preexisting

}
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() {
Expand Down Expand Up @@ -420,27 +452,8 @@ where
}

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 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/feature-gate/unstable-attribute-allow-issue-0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down