Skip to content

Commit f60b95a

Browse files
authored
Rollup merge of #68670 - euclio:invalid-issue, r=estebank
clarify "incorrect issue" error Changes the message to be more precise, shrinks the span and adds a label specifying why the `issue` field is incorrect.
2 parents b3e63f2 + 7632ade commit f60b95a

File tree

5 files changed

+47
-30
lines changed

5 files changed

+47
-30
lines changed

src/libsyntax/attr/builtin.rs

+34-21
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ where
371371
let mut feature = None;
372372
let mut reason = None;
373373
let mut issue = None;
374+
let mut issue_num = None;
374375
let mut is_soft = false;
375376
for meta in metas {
376377
if let Some(mi) = meta.meta_item() {
@@ -389,6 +390,37 @@ where
389390
if !get(mi, &mut issue) {
390391
continue 'outer;
391392
}
393+
394+
// These unwraps are safe because `get` ensures the meta item
395+
// is a name/value pair string literal.
396+
issue_num = match &*issue.unwrap().as_str() {
397+
"none" => None,
398+
issue => {
399+
match issue.parse() {
400+
Ok(num) => {
401+
// FIXME(rossmacarthur): disallow 0
402+
// Disallowing this requires updates to
403+
// some submodules
404+
NonZeroU32::new(num)
405+
}
406+
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();
419+
continue 'outer;
420+
}
421+
}
422+
}
423+
};
392424
}
393425
sym::soft => {
394426
if !mi.is_word() {
@@ -420,27 +452,8 @@ where
420452
}
421453

422454
match (feature, reason, issue) {
423-
(Some(feature), reason, Some(issue)) => {
424-
let issue = match &*issue.as_str() {
425-
"none" => None,
426-
issue => {
427-
if let Ok(num) = issue.parse() {
428-
// FIXME(rossmacarthur): disallow 0
429-
// Disallowing this requires updates to some submodules
430-
NonZeroU32::new(num)
431-
} else {
432-
struct_span_err!(
433-
diagnostic,
434-
attr.span,
435-
E0545,
436-
"incorrect 'issue'"
437-
)
438-
.emit();
439-
continue;
440-
}
441-
}
442-
};
443-
let level = Unstable { reason, issue, is_soft };
455+
(Some(feature), reason, Some(_)) => {
456+
let level = Unstable { reason, issue: issue_num, is_soft };
444457
if sym::unstable == meta_name {
445458
stab = Some(Stability { level, feature, rustc_depr: None });
446459
} else {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ fn unstable_issue_0() {}
99
#[unstable(feature = "unstable_test_feature", issue = "none")]
1010
fn unstable_issue_none() {}
1111

12-
#[unstable(feature = "unstable_test_feature", issue = "something")] //~ ERROR incorrect 'issue'
13-
fn unstable_issue_not_allowed() {}
12+
#[unstable(feature = "unstable_test_feature", issue = "something")]
13+
fn unstable_issue_not_allowed() {} //~^ ERROR `issue` must be a numeric string or "none"
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error[E0545]: incorrect 'issue'
2-
--> $DIR/unstable-attribute-allow-issue-0.rs:12:1
1+
error[E0545]: `issue` must be a numeric string or "none"
2+
--> $DIR/unstable-attribute-allow-issue-0.rs:12:47
33
|
44
LL | #[unstable(feature = "unstable_test_feature", issue = "something")]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^-----------
6+
| |
7+
| invalid digit found in string
68

79
error: aborting due to previous error
810

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ 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 incorrect 'issue'
13+
#[unstable(feature = "a", issue = "no")] //~ ERROR `issue` must be a numeric string or "none"
1414
fn f3() { }
1515

1616
fn main() { }

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ 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]: incorrect 'issue'
14-
--> $DIR/stability-attribute-sanity-2.rs:13:1
13+
error[E0545]: `issue` must be a numeric string or "none"
14+
--> $DIR/stability-attribute-sanity-2.rs:13:27
1515
|
1616
LL | #[unstable(feature = "a", issue = "no")]
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
| ^^^^^^^^----
18+
| |
19+
| invalid digit found in string
1820

1921
error: aborting due to 3 previous errors
2022

0 commit comments

Comments
 (0)