Skip to content

Commit 70be30b

Browse files
Changes to diagnostics
1 parent dd4dd84 commit 70be30b

13 files changed

+149
-97
lines changed

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,13 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
584584
diag.code(E0565);
585585
}
586586
AttributeParseErrorReason::ExpectedNameValue(None) => {
587-
// The suggestion we add below this match already contains enough information
587+
// If the span is the entire attribute, the suggestion we add below this match already contains enough information
588+
if self.span != self.attr_span {
589+
diag.span_label(
590+
self.span,
591+
format!("expected this to be of the form `... = \"...\"`"),
592+
);
593+
}
588594
}
589595
AttributeParseErrorReason::ExpectedNameValue(Some(name)) => {
590596
diag.span_label(

tests/ui/attributes/malformed-attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
//~^ ERROR malformed
101101
//~| ERROR the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type
102102
#[cfg]
103-
//~^ ERROR is not followed by parentheses
103+
//~^ ERROR malformed
104104
#[cfg_attr]
105105
//~^ ERROR malformed
106106
#[instruction_set]

tests/ui/attributes/malformed-attrs.stderr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
error: `cfg` is not followed by parentheses
1+
error[E0539]: malformed `cfg` attribute input
22
--> $DIR/malformed-attrs.rs:102:1
33
|
44
LL | #[cfg]
5-
| ^^^^^^ help: expected syntax is: `cfg(/* predicate */)`
5+
| ^^^^^^
6+
| |
7+
| expected this to be a list
8+
| help: must be of the form: `#[cfg(predicate)]`
69

710
error: malformed `cfg_attr` attribute input
811
--> $DIR/malformed-attrs.rs:104:1

tests/ui/cfg/cfg-target-compact-errors.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
#![feature(cfg_target_compact)]
44

55
#[cfg(target(o::o))]
6-
//~^ ERROR `cfg` predicate key must be an identifier
6+
//~^ ERROR malformed `cfg` attribute input
77
fn one() {}
88

99
#[cfg(target(os = 8))]
10-
//~^ ERROR literal in `cfg` predicate value must be a string
10+
//~^ ERROR malformed `cfg` attribute input
1111
fn two() {}
1212

1313
#[cfg(target(os = "linux", pointer(width = "64")))]
14-
//~^ ERROR invalid predicate `target_pointer`
14+
//~^ ERROR malformed `cfg` attribute input
1515
fn three() {}
1616

1717
#[cfg(target(true))]
18-
//~^ ERROR `cfg` predicate key must be an identifier
18+
//~^ ERROR malformed `cfg` attribute input
1919
fn four() {}
2020

21+
#[cfg(target(clippy::os = "linux"))]
22+
//~^ ERROR `cfg` predicate key must be an identifier
23+
fn five() {}
24+
2125
fn main() {}
Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
1-
error: `cfg` predicate key must be an identifier
2-
--> $DIR/cfg-target-compact-errors.rs:5:14
1+
error[E0539]: malformed `cfg` attribute input
2+
--> $DIR/cfg-target-compact-errors.rs:5:1
33
|
44
LL | #[cfg(target(o::o))]
5-
| ^^^^
5+
| ^^^^^^^^^^^^^----^^^
6+
| | |
7+
| | expected this to be of the form `... = "..."`
8+
| help: must be of the form: `#[cfg(predicate)]`
69

7-
error[E0565]: literal in `cfg` predicate value must be a string
8-
--> $DIR/cfg-target-compact-errors.rs:9:19
10+
error[E0539]: malformed `cfg` attribute input
11+
--> $DIR/cfg-target-compact-errors.rs:9:1
912
|
1013
LL | #[cfg(target(os = 8))]
11-
| ^
14+
| ^^^^^^^^^^^^^^^^^^-^^^
15+
| | |
16+
| | expected a string literal here
17+
| help: must be of the form: `#[cfg(predicate)]`
1218

13-
error[E0537]: invalid predicate `target_pointer`
14-
--> $DIR/cfg-target-compact-errors.rs:13:28
19+
error[E0539]: malformed `cfg` attribute input
20+
--> $DIR/cfg-target-compact-errors.rs:13:1
1521
|
1622
LL | #[cfg(target(os = "linux", pointer(width = "64")))]
17-
| ^^^^^^^^^^^^^^^^^^^^^
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------^^^
24+
| | |
25+
| | expected this to be of the form `... = "..."`
26+
| help: must be of the form: `#[cfg(predicate)]`
1827

19-
error: `cfg` predicate key must be an identifier
20-
--> $DIR/cfg-target-compact-errors.rs:17:14
28+
error[E0539]: malformed `cfg` attribute input
29+
--> $DIR/cfg-target-compact-errors.rs:17:1
2130
|
2231
LL | #[cfg(target(true))]
23-
| ^^^^
32+
| ^^^^^^^^^^^^^----^^^
33+
| | |
34+
| | expected this to be of the form `... = "..."`
35+
| help: must be of the form: `#[cfg(predicate)]`
36+
37+
error: `cfg` predicate key must be an identifier
38+
--> $DIR/cfg-target-compact-errors.rs:21:7
39+
|
40+
LL | #[cfg(target(clippy::os = "linux"))]
41+
| ^^^^^^
2442

25-
error: aborting due to 4 previous errors
43+
error: aborting due to 5 previous errors
2644

27-
Some errors have detailed explanations: E0537, E0565.
28-
For more information about an error, try `rustc --explain E0537`.
45+
For more information about this error, try `rustc --explain E0539`.

tests/ui/cfg/cfg-version/syntax.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ LL | #[cfg(version(false))]
1717
| ^^^^^
1818

1919
error: expected single version literal
20-
--> $DIR/syntax.rs:23:7
20+
--> $DIR/syntax.rs:23:14
2121
|
2222
LL | #[cfg(version("1.43", "1.44", "1.45"))]
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
warning: unknown version literal format, assuming it refers to a future version
2626
--> $DIR/syntax.rs:51:15

tests/ui/cfg/diagnostics-cross-crate.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ note: found an item that was configured out
1010
LL | pub mod doesnt_exist {
1111
| ^^^^^^^^^^^^
1212
note: the item is gated here
13-
--> $DIR/auxiliary/cfged_out.rs:5:5
13+
--> $DIR/auxiliary/cfged_out.rs:5:11
1414
|
1515
LL | #[cfg(false)]
16-
| ^^^^^^^^^^^^^
16+
| ^^^^^
1717

1818
error[E0425]: cannot find function `uwu` in crate `cfged_out`
1919
--> $DIR/diagnostics-cross-crate.rs:7:16
@@ -33,10 +33,10 @@ note: found an item that was configured out
3333
LL | pub fn uwu() {}
3434
| ^^^
3535
note: the item is gated here
36-
--> $DIR/auxiliary/cfged_out.rs:2:5
36+
--> $DIR/auxiliary/cfged_out.rs:2:11
3737
|
3838
LL | #[cfg(false)]
39-
| ^^^^^^^^^^^^^
39+
| ^^^^^
4040

4141
error[E0425]: cannot find function `meow` in module `cfged_out::inner::right`
4242
--> $DIR/diagnostics-cross-crate.rs:24:30
@@ -67,10 +67,10 @@ note: found an item that was configured out
6767
LL | pub fn vanished() {}
6868
| ^^^^^^^^
6969
note: the item is gated here
70-
--> $DIR/auxiliary/cfged_out.rs:21:1
70+
--> $DIR/auxiliary/cfged_out.rs:21:7
7171
|
7272
LL | #[cfg(i_dont_exist_and_you_can_do_nothing_about_it)]
73-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7474

7575
error: aborting due to 5 previous errors
7676

tests/ui/cfg/diagnostics-reexport-2.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ note: found an item that was configured out
1010
LL | pub mod gated {
1111
| ^^^^^
1212
note: the item is gated here
13-
--> $DIR/diagnostics-reexport-2.rs:4:5
13+
--> $DIR/diagnostics-reexport-2.rs:4:11
1414
|
1515
LL | #[cfg(false)]
16-
| ^^^^^^^^^^^^^
16+
| ^^^^^
1717

1818
error[E0433]: failed to resolve: could not find `gated` in `reexport2`
1919
--> $DIR/diagnostics-reexport-2.rs:46:16
@@ -27,10 +27,10 @@ note: found an item that was configured out
2727
LL | pub mod gated {
2828
| ^^^^^
2929
note: the item is gated here
30-
--> $DIR/diagnostics-reexport-2.rs:4:5
30+
--> $DIR/diagnostics-reexport-2.rs:4:11
3131
|
3232
LL | #[cfg(false)]
33-
| ^^^^^^^^^^^^^
33+
| ^^^^^
3434

3535
error[E0433]: failed to resolve: could not find `gated` in `reexport30`
3636
--> $DIR/diagnostics-reexport-2.rs:50:17
@@ -44,10 +44,10 @@ note: found an item that was configured out
4444
LL | pub mod gated {
4545
| ^^^^^
4646
note: the item is gated here
47-
--> $DIR/diagnostics-reexport-2.rs:4:5
47+
--> $DIR/diagnostics-reexport-2.rs:4:11
4848
|
4949
LL | #[cfg(false)]
50-
| ^^^^^^^^^^^^^
50+
| ^^^^^
5151

5252
error[E0433]: failed to resolve: could not find `gated` in `reexport31`
5353
--> $DIR/diagnostics-reexport-2.rs:54:17
@@ -61,10 +61,10 @@ note: found an item that was configured out
6161
LL | pub mod gated {
6262
| ^^^^^
6363
note: the item is gated here
64-
--> $DIR/diagnostics-reexport-2.rs:4:5
64+
--> $DIR/diagnostics-reexport-2.rs:4:11
6565
|
6666
LL | #[cfg(false)]
67-
| ^^^^^^^^^^^^^
67+
| ^^^^^
6868

6969
error[E0433]: failed to resolve: could not find `gated` in `reexport32`
7070
--> $DIR/diagnostics-reexport-2.rs:58:17
@@ -78,10 +78,10 @@ note: found an item that was configured out
7878
LL | pub mod gated {
7979
| ^^^^^
8080
note: the item is gated here
81-
--> $DIR/diagnostics-reexport-2.rs:4:5
81+
--> $DIR/diagnostics-reexport-2.rs:4:11
8282
|
8383
LL | #[cfg(false)]
84-
| ^^^^^^^^^^^^^
84+
| ^^^^^
8585

8686
error: aborting due to 5 previous errors
8787

tests/ui/cfg/diagnostics-reexport.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ note: found an item that was configured out
1010
LL | pub fn x() {}
1111
| ^
1212
note: the item is gated here
13-
--> $DIR/diagnostics-reexport.rs:17:5
13+
--> $DIR/diagnostics-reexport.rs:17:11
1414
|
1515
LL | #[cfg(false)]
16-
| ^^^^^^^^^^^^^
16+
| ^^^^^
1717

1818
error[E0432]: unresolved imports `b::x`, `b::y`
1919
--> $DIR/diagnostics-reexport.rs:22:13
@@ -29,20 +29,20 @@ note: found an item that was configured out
2929
LL | pub fn x() {}
3030
| ^
3131
note: the item is gated here
32-
--> $DIR/diagnostics-reexport.rs:28:5
32+
--> $DIR/diagnostics-reexport.rs:28:11
3333
|
3434
LL | #[cfg(false)]
35-
| ^^^^^^^^^^^^^
35+
| ^^^^^
3636
note: found an item that was configured out
3737
--> $DIR/diagnostics-reexport.rs:32:12
3838
|
3939
LL | pub fn y() {}
4040
| ^
4141
note: the item is gated here
42-
--> $DIR/diagnostics-reexport.rs:31:5
42+
--> $DIR/diagnostics-reexport.rs:31:11
4343
|
4444
LL | #[cfg(false)]
45-
| ^^^^^^^^^^^^^
45+
| ^^^^^
4646

4747
error[E0425]: cannot find function `uwu` in module `inner`
4848
--> $DIR/diagnostics-reexport.rs:38:12
@@ -56,10 +56,10 @@ note: found an item that was configured out
5656
LL | pub use super::uwu;
5757
| ^^^
5858
note: the item is gated here
59-
--> $DIR/diagnostics-reexport.rs:7:5
59+
--> $DIR/diagnostics-reexport.rs:7:11
6060
|
6161
LL | #[cfg(false)]
62-
| ^^^^^^^^^^^^^
62+
| ^^^^^
6363

6464
error: aborting due to 3 previous errors
6565

tests/ui/cfg/diagnostics-same-crate.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ note: found an item that was configured out
1010
LL | pub mod doesnt_exist {
1111
| ^^^^^^^^^^^^
1212
note: the item is gated here
13-
--> $DIR/diagnostics-same-crate.rs:8:5
13+
--> $DIR/diagnostics-same-crate.rs:8:11
1414
|
1515
LL | #[cfg(false)]
16-
| ^^^^^^^^^^^^^
16+
| ^^^^^
1717

1818
error[E0432]: unresolved import `super::inner::doesnt_exist`
1919
--> $DIR/diagnostics-same-crate.rs:35:23
@@ -27,10 +27,10 @@ note: found an item that was configured out
2727
LL | pub mod doesnt_exist {
2828
| ^^^^^^^^^^^^
2929
note: the item is gated here
30-
--> $DIR/diagnostics-same-crate.rs:8:5
30+
--> $DIR/diagnostics-same-crate.rs:8:11
3131
|
3232
LL | #[cfg(false)]
33-
| ^^^^^^^^^^^^^
33+
| ^^^^^
3434

3535
error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
3636
--> $DIR/diagnostics-same-crate.rs:54:12
@@ -44,10 +44,10 @@ note: found an item that was configured out
4444
LL | pub mod doesnt_exist {
4545
| ^^^^^^^^^^^^
4646
note: the item is gated here
47-
--> $DIR/diagnostics-same-crate.rs:8:5
47+
--> $DIR/diagnostics-same-crate.rs:8:11
4848
|
4949
LL | #[cfg(false)]
50-
| ^^^^^^^^^^^^^
50+
| ^^^^^
5151

5252
error[E0425]: cannot find function `uwu` in module `inner`
5353
--> $DIR/diagnostics-same-crate.rs:49:12
@@ -61,10 +61,10 @@ note: found an item that was configured out
6161
LL | pub fn uwu() {}
6262
| ^^^
6363
note: the item is gated here
64-
--> $DIR/diagnostics-same-crate.rs:4:5
64+
--> $DIR/diagnostics-same-crate.rs:4:11
6565
|
6666
LL | #[cfg(false)]
67-
| ^^^^^^^^^^^^^
67+
| ^^^^^
6868

6969
error[E0425]: cannot find function `meow` in module `inner::right`
7070
--> $DIR/diagnostics-same-crate.rs:58:19

0 commit comments

Comments
 (0)