Skip to content

Commit 2226977

Browse files
committed
Ensure suggestion is in its own diagnostic window
For two reasons: 1. Now that the suggestion span has been corrected, the output is a bit cluttered and hard to read. Putting the suggestion its own window creates more space. 2. It's easier to see what's being suggested, since now the version after the suggestion is applied is shown.
1 parent d2b13ba commit 2226977

File tree

5 files changed

+68
-46
lines changed

5 files changed

+68
-46
lines changed

compiler/rustc_typeck/src/check/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15141514
),
15151515
);
15161516
err.span_label(field.ident.span, "field does not exist");
1517-
err.span_suggestion(
1517+
err.span_suggestion_verbose(
15181518
expr_span,
15191519
&format!(
15201520
"`{adt}::{variant}` is a tuple {kind_name}, use the appropriate syntax",
@@ -1532,7 +1532,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15321532
_ => {
15331533
err.span_label(variant.ident.span, format!("`{adt}` defined here", adt = ty));
15341534
err.span_label(field.ident.span, "field does not exist");
1535-
err.span_suggestion(
1535+
err.span_suggestion_verbose(
15361536
expr_span,
15371537
&format!(
15381538
"`{adt}` is a tuple {kind_name}, use the appropriate syntax",

src/test/ui/issues/issue-4736.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ LL | struct NonCopyable(());
55
| ----------- `NonCopyable` defined here
66
...
77
LL | let z = NonCopyable{ p: () };
8-
| -------------^------
9-
| | |
10-
| | field does not exist
11-
| help: `NonCopyable` is a tuple struct, use the appropriate syntax: `NonCopyable(/* fields */)`
8+
| ^ field does not exist
9+
|
10+
help: `NonCopyable` is a tuple struct, use the appropriate syntax
11+
|
12+
LL | let z = NonCopyable(/* fields */);
13+
| ~~~~~~~~~~~~~~~~~~~~~~~~~
1214

1315
error: aborting due to previous error
1416

src/test/ui/issues/issue-80607.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ LL | V1(i32),
55
| -- `Enum::V1` defined here
66
...
77
LL | Enum::V1 { x }
8-
| -----------^--
9-
| | |
10-
| | field does not exist
11-
| help: `Enum::V1` is a tuple variant, use the appropriate syntax: `Enum::V1(/* fields */)`
8+
| ^ field does not exist
9+
|
10+
help: `Enum::V1` is a tuple variant, use the appropriate syntax
11+
|
12+
LL | Enum::V1(/* fields */)
13+
| ~~~~~~~~~~~~~~~~~~~~~~
1214

1315
error: aborting due to previous error
1416

src/test/ui/numeric/numeric-fields.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ LL | struct S(u8, u16);
55
| - `S` defined here
66
...
77
LL | let s = S{0b1: 10, 0: 11};
8-
| --^^^------------
9-
| | |
10-
| | field does not exist
11-
| help: `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
8+
| ^^^ field does not exist
9+
|
10+
help: `S` is a tuple struct, use the appropriate syntax
11+
|
12+
LL | let s = S(/* fields */);
13+
| ~~~~~~~~~~~~~~~
1214

1315
error[E0026]: struct `S` does not have a field named `0x1`
1416
--> $DIR/numeric-fields.rs:7:17

src/test/ui/suggestions/nested-non-tuple-tuple-struct.stderr

+48-32
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ LL | pub struct S(f32, f32);
55
| - `S` defined here
66
...
77
LL | let _x = (S { x: 1.0, y: 2.0 }, S { x: 3.0, y: 4.0 });
8-
| ----^---------------
9-
| | |
10-
| | field does not exist
11-
| help: `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
8+
| ^ field does not exist
9+
|
10+
help: `S` is a tuple struct, use the appropriate syntax
11+
|
12+
LL | let _x = (S(/* fields */), S { x: 3.0, y: 4.0 });
13+
| ~~~~~~~~~~~~~~~
1214

1315
error[E0560]: struct `S` has no field named `y`
1416
--> $DIR/nested-non-tuple-tuple-struct.rs:8:27
@@ -17,10 +19,12 @@ LL | pub struct S(f32, f32);
1719
| - `S` defined here
1820
...
1921
LL | let _x = (S { x: 1.0, y: 2.0 }, S { x: 3.0, y: 4.0 });
20-
| ------------^-------
21-
| | |
22-
| | field does not exist
23-
| help: `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
22+
| ^ field does not exist
23+
|
24+
help: `S` is a tuple struct, use the appropriate syntax
25+
|
26+
LL | let _x = (S(/* fields */), S { x: 3.0, y: 4.0 });
27+
| ~~~~~~~~~~~~~~~
2428

2529
error[E0560]: struct `S` has no field named `x`
2630
--> $DIR/nested-non-tuple-tuple-struct.rs:8:41
@@ -29,10 +33,12 @@ LL | pub struct S(f32, f32);
2933
| - `S` defined here
3034
...
3135
LL | let _x = (S { x: 1.0, y: 2.0 }, S { x: 3.0, y: 4.0 });
32-
| ----^---------------
33-
| | |
34-
| | field does not exist
35-
| help: `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
36+
| ^ field does not exist
37+
|
38+
help: `S` is a tuple struct, use the appropriate syntax
39+
|
40+
LL | let _x = (S { x: 1.0, y: 2.0 }, S(/* fields */));
41+
| ~~~~~~~~~~~~~~~
3642

3743
error[E0560]: struct `S` has no field named `y`
3844
--> $DIR/nested-non-tuple-tuple-struct.rs:8:49
@@ -41,10 +47,12 @@ LL | pub struct S(f32, f32);
4147
| - `S` defined here
4248
...
4349
LL | let _x = (S { x: 1.0, y: 2.0 }, S { x: 3.0, y: 4.0 });
44-
| ------------^-------
45-
| | |
46-
| | field does not exist
47-
| help: `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
50+
| ^ field does not exist
51+
|
52+
help: `S` is a tuple struct, use the appropriate syntax
53+
|
54+
LL | let _x = (S { x: 1.0, y: 2.0 }, S(/* fields */));
55+
| ~~~~~~~~~~~~~~~
4856

4957
error[E0559]: variant `E::V` has no field named `x`
5058
--> $DIR/nested-non-tuple-tuple-struct.rs:13:22
@@ -53,10 +61,12 @@ LL | V(f32, f32),
5361
| - `E::V` defined here
5462
...
5563
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V { x: 3.0, y: 4.0 });
56-
| -------^---------------
57-
| | |
58-
| | field does not exist
59-
| help: `E::V` is a tuple variant, use the appropriate syntax: `E::V(/* fields */)`
64+
| ^ field does not exist
65+
|
66+
help: `E::V` is a tuple variant, use the appropriate syntax
67+
|
68+
LL | let _y = (E::V(/* fields */), E::V { x: 3.0, y: 4.0 });
69+
| ~~~~~~~~~~~~~~~~~~
6070

6171
error[E0559]: variant `E::V` has no field named `y`
6272
--> $DIR/nested-non-tuple-tuple-struct.rs:13:30
@@ -65,10 +75,12 @@ LL | V(f32, f32),
6575
| - `E::V` defined here
6676
...
6777
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V { x: 3.0, y: 4.0 });
68-
| ---------------^-------
69-
| | |
70-
| | field does not exist
71-
| help: `E::V` is a tuple variant, use the appropriate syntax: `E::V(/* fields */)`
78+
| ^ field does not exist
79+
|
80+
help: `E::V` is a tuple variant, use the appropriate syntax
81+
|
82+
LL | let _y = (E::V(/* fields */), E::V { x: 3.0, y: 4.0 });
83+
| ~~~~~~~~~~~~~~~~~~
7284

7385
error[E0559]: variant `E::V` has no field named `x`
7486
--> $DIR/nested-non-tuple-tuple-struct.rs:13:47
@@ -77,10 +89,12 @@ LL | V(f32, f32),
7789
| - `E::V` defined here
7890
...
7991
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V { x: 3.0, y: 4.0 });
80-
| -------^---------------
81-
| | |
82-
| | field does not exist
83-
| help: `E::V` is a tuple variant, use the appropriate syntax: `E::V(/* fields */)`
92+
| ^ field does not exist
93+
|
94+
help: `E::V` is a tuple variant, use the appropriate syntax
95+
|
96+
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V(/* fields */));
97+
| ~~~~~~~~~~~~~~~~~~
8498

8599
error[E0559]: variant `E::V` has no field named `y`
86100
--> $DIR/nested-non-tuple-tuple-struct.rs:13:55
@@ -89,10 +103,12 @@ LL | V(f32, f32),
89103
| - `E::V` defined here
90104
...
91105
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V { x: 3.0, y: 4.0 });
92-
| ---------------^-------
93-
| | |
94-
| | field does not exist
95-
| help: `E::V` is a tuple variant, use the appropriate syntax: `E::V(/* fields */)`
106+
| ^ field does not exist
107+
|
108+
help: `E::V` is a tuple variant, use the appropriate syntax
109+
|
110+
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V(/* fields */));
111+
| ~~~~~~~~~~~~~~~~~~
96112

97113
error: aborting due to 8 previous errors
98114

0 commit comments

Comments
 (0)