Skip to content

Commit 1ad674a

Browse files
authored
Rollup merge of #68880 - JohnTitor:issue-non-zero, r=Dylan-DPC
Forbid using `0` as issue number Fixes #67496 r? @Centril
2 parents 2210d3f + bf26933 commit 1ad674a

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

src/librustc_attr/builtin.rs

+22-17
Original file line numberDiff line numberDiff line change
@@ -396,26 +396,31 @@ where
396396
issue_num = match &*issue.unwrap().as_str() {
397397
"none" => None,
398398
issue => {
399+
let emit_diag = |msg: &str| {
400+
struct_span_err!(
401+
diagnostic,
402+
mi.span,
403+
E0545,
404+
"`issue` must be a non-zero numeric string \
405+
or \"none\"",
406+
)
407+
.span_label(
408+
mi.name_value_literal().unwrap().span,
409+
msg,
410+
)
411+
.emit();
412+
};
399413
match issue.parse() {
400-
Ok(num) => {
401-
// FIXME(rossmacarthur): disallow 0
402-
// Disallowing this requires updates to
403-
// some submodules
404-
NonZeroU32::new(num)
414+
Ok(num) if num == 0 => {
415+
emit_diag(
416+
"`issue` must not be \"0\", \
417+
use \"none\" instead",
418+
);
419+
continue 'outer;
405420
}
421+
Ok(num) => NonZeroU32::new(num),
406422
Err(err) => {
407-
struct_span_err!(
408-
diagnostic,
409-
mi.span,
410-
E0545,
411-
"`issue` must be a numeric string \
412-
or \"none\"",
413-
)
414-
.span_label(
415-
mi.name_value_literal().unwrap().span,
416-
&err.to_string(),
417-
)
418-
.emit();
423+
emit_diag(&err.to_string());
419424
continue 'outer;
420425
}
421426
}

src/test/ui/feature-gate/unstable-attribute-allow-issue-0.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#![stable(feature = "stable_test_feature", since = "1.0.0")]
55

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

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

1212
#[unstable(feature = "unstable_test_feature", issue = "something")]
13-
fn unstable_issue_not_allowed() {} //~^ ERROR `issue` must be a numeric string or "none"
13+
fn unstable_issue_not_allowed() {} //~^ ERROR `issue` must be a non-zero numeric string or "none"
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
error[E0545]: `issue` must be a numeric string or "none"
1+
error[E0545]: `issue` must be a non-zero numeric string or "none"
2+
--> $DIR/unstable-attribute-allow-issue-0.rs:6:47
3+
|
4+
LL | #[unstable(feature = "unstable_test_feature", issue = "0")]
5+
| ^^^^^^^^---
6+
| |
7+
| `issue` must not be "0", use "none" instead
8+
9+
error[E0545]: `issue` must be a non-zero numeric string or "none"
210
--> $DIR/unstable-attribute-allow-issue-0.rs:12:47
311
|
412
LL | #[unstable(feature = "unstable_test_feature", issue = "something")]
513
| ^^^^^^^^-----------
614
| |
715
| invalid digit found in string
816

9-
error: aborting due to previous error
17+
error: aborting due to 2 previous errors
1018

src/test/ui/stability-attribute/stability-attribute-sanity-2.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ fn f1() { }
1010
#[stable(feature = "a", sinse = "1.0.0")] //~ ERROR unknown meta item 'sinse'
1111
fn f2() { }
1212

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

1617
fn main() { }

src/test/ui/stability-attribute/stability-attribute-sanity-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0541]: unknown meta item 'sinse'
1010
LL | #[stable(feature = "a", sinse = "1.0.0")]
1111
| ^^^^^^^^^^^^^^^ expected one of `since`, `note`
1212

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

0 commit comments

Comments
 (0)