Skip to content

Commit

Permalink
Forbid using 0 as issue number
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Feb 6, 2020
1 parent ed853b8 commit bf26933
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
39 changes: 22 additions & 17 deletions src/librustc_attr/builtin.rs
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
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
@@ -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

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() { }
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

0 comments on commit bf26933

Please sign in to comment.