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.
This commit is contained in:
parent
d2b13ba466
commit
2226977a87
5 changed files with 68 additions and 46 deletions
|
@ -1514,7 +1514,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
),
|
||||
);
|
||||
err.span_label(field.ident.span, "field does not exist");
|
||||
err.span_suggestion(
|
||||
err.span_suggestion_verbose(
|
||||
expr_span,
|
||||
&format!(
|
||||
"`{adt}::{variant}` is a tuple {kind_name}, use the appropriate syntax",
|
||||
|
@ -1532,7 +1532,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
_ => {
|
||||
err.span_label(variant.ident.span, format!("`{adt}` defined here", adt = ty));
|
||||
err.span_label(field.ident.span, "field does not exist");
|
||||
err.span_suggestion(
|
||||
err.span_suggestion_verbose(
|
||||
expr_span,
|
||||
&format!(
|
||||
"`{adt}` is a tuple {kind_name}, use the appropriate syntax",
|
||||
|
|
|
@ -5,10 +5,12 @@ LL | struct NonCopyable(());
|
|||
| ----------- `NonCopyable` defined here
|
||||
...
|
||||
LL | let z = NonCopyable{ p: () };
|
||||
| -------------^------
|
||||
| | |
|
||||
| | field does not exist
|
||||
| help: `NonCopyable` is a tuple struct, use the appropriate syntax: `NonCopyable(/* fields */)`
|
||||
| ^ field does not exist
|
||||
|
|
||||
help: `NonCopyable` is a tuple struct, use the appropriate syntax
|
||||
|
|
||||
LL | let z = NonCopyable(/* fields */);
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@ LL | V1(i32),
|
|||
| -- `Enum::V1` defined here
|
||||
...
|
||||
LL | Enum::V1 { x }
|
||||
| -----------^--
|
||||
| | |
|
||||
| | field does not exist
|
||||
| help: `Enum::V1` is a tuple variant, use the appropriate syntax: `Enum::V1(/* fields */)`
|
||||
| ^ field does not exist
|
||||
|
|
||||
help: `Enum::V1` is a tuple variant, use the appropriate syntax
|
||||
|
|
||||
LL | Enum::V1(/* fields */)
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@ LL | struct S(u8, u16);
|
|||
| - `S` defined here
|
||||
...
|
||||
LL | let s = S{0b1: 10, 0: 11};
|
||||
| --^^^------------
|
||||
| | |
|
||||
| | field does not exist
|
||||
| help: `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
|
||||
| ^^^ field does not exist
|
||||
|
|
||||
help: `S` is a tuple struct, use the appropriate syntax
|
||||
|
|
||||
LL | let s = S(/* fields */);
|
||||
| ~~~~~~~~~~~~~~~
|
||||
|
||||
error[E0026]: struct `S` does not have a field named `0x1`
|
||||
--> $DIR/numeric-fields.rs:7:17
|
||||
|
|
|
@ -5,10 +5,12 @@ LL | pub struct S(f32, f32);
|
|||
| - `S` defined here
|
||||
...
|
||||
LL | let _x = (S { x: 1.0, y: 2.0 }, S { x: 3.0, y: 4.0 });
|
||||
| ----^---------------
|
||||
| | |
|
||||
| | field does not exist
|
||||
| help: `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
|
||||
| ^ field does not exist
|
||||
|
|
||||
help: `S` is a tuple struct, use the appropriate syntax
|
||||
|
|
||||
LL | let _x = (S(/* fields */), S { x: 3.0, y: 4.0 });
|
||||
| ~~~~~~~~~~~~~~~
|
||||
|
||||
error[E0560]: struct `S` has no field named `y`
|
||||
--> $DIR/nested-non-tuple-tuple-struct.rs:8:27
|
||||
|
@ -17,10 +19,12 @@ LL | pub struct S(f32, f32);
|
|||
| - `S` defined here
|
||||
...
|
||||
LL | let _x = (S { x: 1.0, y: 2.0 }, S { x: 3.0, y: 4.0 });
|
||||
| ------------^-------
|
||||
| | |
|
||||
| | field does not exist
|
||||
| help: `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
|
||||
| ^ field does not exist
|
||||
|
|
||||
help: `S` is a tuple struct, use the appropriate syntax
|
||||
|
|
||||
LL | let _x = (S(/* fields */), S { x: 3.0, y: 4.0 });
|
||||
| ~~~~~~~~~~~~~~~
|
||||
|
||||
error[E0560]: struct `S` has no field named `x`
|
||||
--> $DIR/nested-non-tuple-tuple-struct.rs:8:41
|
||||
|
@ -29,10 +33,12 @@ LL | pub struct S(f32, f32);
|
|||
| - `S` defined here
|
||||
...
|
||||
LL | let _x = (S { x: 1.0, y: 2.0 }, S { x: 3.0, y: 4.0 });
|
||||
| ----^---------------
|
||||
| | |
|
||||
| | field does not exist
|
||||
| help: `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
|
||||
| ^ field does not exist
|
||||
|
|
||||
help: `S` is a tuple struct, use the appropriate syntax
|
||||
|
|
||||
LL | let _x = (S { x: 1.0, y: 2.0 }, S(/* fields */));
|
||||
| ~~~~~~~~~~~~~~~
|
||||
|
||||
error[E0560]: struct `S` has no field named `y`
|
||||
--> $DIR/nested-non-tuple-tuple-struct.rs:8:49
|
||||
|
@ -41,10 +47,12 @@ LL | pub struct S(f32, f32);
|
|||
| - `S` defined here
|
||||
...
|
||||
LL | let _x = (S { x: 1.0, y: 2.0 }, S { x: 3.0, y: 4.0 });
|
||||
| ------------^-------
|
||||
| | |
|
||||
| | field does not exist
|
||||
| help: `S` is a tuple struct, use the appropriate syntax: `S(/* fields */)`
|
||||
| ^ field does not exist
|
||||
|
|
||||
help: `S` is a tuple struct, use the appropriate syntax
|
||||
|
|
||||
LL | let _x = (S { x: 1.0, y: 2.0 }, S(/* fields */));
|
||||
| ~~~~~~~~~~~~~~~
|
||||
|
||||
error[E0559]: variant `E::V` has no field named `x`
|
||||
--> $DIR/nested-non-tuple-tuple-struct.rs:13:22
|
||||
|
@ -53,10 +61,12 @@ LL | V(f32, f32),
|
|||
| - `E::V` defined here
|
||||
...
|
||||
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V { x: 3.0, y: 4.0 });
|
||||
| -------^---------------
|
||||
| | |
|
||||
| | field does not exist
|
||||
| help: `E::V` is a tuple variant, use the appropriate syntax: `E::V(/* fields */)`
|
||||
| ^ field does not exist
|
||||
|
|
||||
help: `E::V` is a tuple variant, use the appropriate syntax
|
||||
|
|
||||
LL | let _y = (E::V(/* fields */), E::V { x: 3.0, y: 4.0 });
|
||||
| ~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error[E0559]: variant `E::V` has no field named `y`
|
||||
--> $DIR/nested-non-tuple-tuple-struct.rs:13:30
|
||||
|
@ -65,10 +75,12 @@ LL | V(f32, f32),
|
|||
| - `E::V` defined here
|
||||
...
|
||||
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V { x: 3.0, y: 4.0 });
|
||||
| ---------------^-------
|
||||
| | |
|
||||
| | field does not exist
|
||||
| help: `E::V` is a tuple variant, use the appropriate syntax: `E::V(/* fields */)`
|
||||
| ^ field does not exist
|
||||
|
|
||||
help: `E::V` is a tuple variant, use the appropriate syntax
|
||||
|
|
||||
LL | let _y = (E::V(/* fields */), E::V { x: 3.0, y: 4.0 });
|
||||
| ~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error[E0559]: variant `E::V` has no field named `x`
|
||||
--> $DIR/nested-non-tuple-tuple-struct.rs:13:47
|
||||
|
@ -77,10 +89,12 @@ LL | V(f32, f32),
|
|||
| - `E::V` defined here
|
||||
...
|
||||
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V { x: 3.0, y: 4.0 });
|
||||
| -------^---------------
|
||||
| | |
|
||||
| | field does not exist
|
||||
| help: `E::V` is a tuple variant, use the appropriate syntax: `E::V(/* fields */)`
|
||||
| ^ field does not exist
|
||||
|
|
||||
help: `E::V` is a tuple variant, use the appropriate syntax
|
||||
|
|
||||
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V(/* fields */));
|
||||
| ~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error[E0559]: variant `E::V` has no field named `y`
|
||||
--> $DIR/nested-non-tuple-tuple-struct.rs:13:55
|
||||
|
@ -89,10 +103,12 @@ LL | V(f32, f32),
|
|||
| - `E::V` defined here
|
||||
...
|
||||
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V { x: 3.0, y: 4.0 });
|
||||
| ---------------^-------
|
||||
| | |
|
||||
| | field does not exist
|
||||
| help: `E::V` is a tuple variant, use the appropriate syntax: `E::V(/* fields */)`
|
||||
| ^ field does not exist
|
||||
|
|
||||
help: `E::V` is a tuple variant, use the appropriate syntax
|
||||
|
|
||||
LL | let _y = (E::V { x: 1.0, y: 2.0 }, E::V(/* fields */));
|
||||
| ~~~~~~~~~~~~~~~~~~
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue