Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix span used for structured tuple struct suggestion
(And same for tuple variants.) Previously, the span was just for the constructor name, which meant it would result in syntactically-invalid code when applied. Now, the span is for the entire expression.
- Loading branch information
Showing
6 changed files
with
135 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pub struct S(f32, f32); | ||
|
||
pub enum E { | ||
V(f32, f32), | ||
} | ||
|
||
fn main() { | ||
let _x = (S { x: 1.0, y: 2.0 }, S { x: 3.0, y: 4.0 }); | ||
//~^ ERROR struct `S` has no field named `x` | ||
//~| ERROR struct `S` has no field named `y` | ||
//~| ERROR struct `S` has no field named `x` | ||
//~| ERROR struct `S` has no field named `y` | ||
let _y = (E::V { x: 1.0, y: 2.0 }, E::V { x: 3.0, y: 4.0 }); | ||
//~^ ERROR variant `E::V` has no field named `x` | ||
//~| ERROR variant `E::V` has no field named `y` | ||
//~| ERROR variant `E::V` has no field named `x` | ||
//~| ERROR variant `E::V` has no field named `y` | ||
} |
100 changes: 100 additions & 0 deletions
100
src/test/ui/suggestions/nested-non-tuple-tuple-struct.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
error[E0560]: struct `S` has no field named `x` | ||
--> $DIR/nested-non-tuple-tuple-struct.rs:8:19 | ||
| | ||
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 */)` | ||
|
||
error[E0560]: struct `S` has no field named `y` | ||
--> $DIR/nested-non-tuple-tuple-struct.rs:8:27 | ||
| | ||
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 */)` | ||
|
||
error[E0560]: struct `S` has no field named `x` | ||
--> $DIR/nested-non-tuple-tuple-struct.rs:8:41 | ||
| | ||
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 */)` | ||
|
||
error[E0560]: struct `S` has no field named `y` | ||
--> $DIR/nested-non-tuple-tuple-struct.rs:8:49 | ||
| | ||
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 */)` | ||
|
||
error[E0559]: variant `E::V` has no field named `x` | ||
--> $DIR/nested-non-tuple-tuple-struct.rs:13:22 | ||
| | ||
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 */)` | ||
|
||
error[E0559]: variant `E::V` has no field named `y` | ||
--> $DIR/nested-non-tuple-tuple-struct.rs:13:30 | ||
| | ||
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 */)` | ||
|
||
error[E0559]: variant `E::V` has no field named `x` | ||
--> $DIR/nested-non-tuple-tuple-struct.rs:13:47 | ||
| | ||
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 */)` | ||
|
||
error[E0559]: variant `E::V` has no field named `y` | ||
--> $DIR/nested-non-tuple-tuple-struct.rs:13:55 | ||
| | ||
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 */)` | ||
|
||
error: aborting due to 8 previous errors | ||
|
||
Some errors have detailed explanations: E0559, E0560. | ||
For more information about an error, try `rustc --explain E0559`. |