Skip to content
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

Forbid using 0 as issue number #68880

Merged
merged 1 commit into from
Feb 6, 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
39 changes: 22 additions & 17 deletions src/librustc_attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,26 +396,31 @@ where
issue_num = match &*issue.unwrap().as_str() {
"none" => None,
issue => {
let emit_diag = |msg: &str| {
struct_span_err!(
diagnostic,
mi.span,
E0545,
"`issue` must be a non-zero numeric string \
or \"none\"",
)
.span_label(
mi.name_value_literal().unwrap().span,
msg,
)
.emit();
};
match issue.parse() {
Ok(num) => {
// FIXME(rossmacarthur): disallow 0
// Disallowing this requires updates to
// some submodules
NonZeroU32::new(num)
Ok(num) if num == 0 => {
emit_diag(
"`issue` must not be \"0\", \
use \"none\" instead",
);
continue 'outer;
}
Ok(num) => 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();
emit_diag(&err.to_string());
continue 'outer;
}
}
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 @@ -4,10 +4,10 @@
#![stable(feature = "stable_test_feature", since = "1.0.0")]

#[unstable(feature = "unstable_test_feature", issue = "0")]
fn unstable_issue_0() {}
fn unstable_issue_0() {} //~^ ERROR `issue` must be a non-zero numeric string or "none"

#[unstable(feature = "unstable_test_feature", issue = "none")]
fn unstable_issue_none() {}

#[unstable(feature = "unstable_test_feature", issue = "something")]
fn unstable_issue_not_allowed() {} //~^ ERROR `issue` must be a numeric string or "none"
fn unstable_issue_not_allowed() {} //~^ ERROR `issue` must be a non-zero numeric string or "none"
12 changes: 10 additions & 2 deletions src/test/ui/feature-gate/unstable-attribute-allow-issue-0.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
error[E0545]: `issue` must be a numeric string or "none"
error[E0545]: `issue` must be a non-zero numeric string or "none"
--> $DIR/unstable-attribute-allow-issue-0.rs:6:47
|
LL | #[unstable(feature = "unstable_test_feature", issue = "0")]
| ^^^^^^^^---
| |
| `issue` must not be "0", use "none" instead

error[E0545]: `issue` must be a non-zero 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
error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ fn f1() { }
#[stable(feature = "a", sinse = "1.0.0")] //~ ERROR unknown meta item 'sinse'
fn f2() { }

#[unstable(feature = "a", issue = "no")] //~ ERROR `issue` must be a numeric string or "none"
#[unstable(feature = "a", issue = "no")]
//~^ ERROR `issue` must be a non-zero numeric string or "none"
fn f3() { }

fn main() { }
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error[E0541]: unknown meta item 'sinse'
LL | #[stable(feature = "a", sinse = "1.0.0")]
| ^^^^^^^^^^^^^^^ expected one of `since`, `note`

error[E0545]: `issue` must be a numeric string or "none"
error[E0545]: `issue` must be a non-zero numeric string or "none"
--> $DIR/stability-attribute-sanity-2.rs:13:27
|
LL | #[unstable(feature = "a", issue = "no")]
Expand Down