-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #127988 - estebank:dupe-derive-params, r=fmease
Do not ICE with incorrect empty suggestion When we have two types with the same name, one without type parameters and the other with type parameters and a derive macro, we were before incorrectly suggesting to remove type parameters from the former, which ICEd because we were suggesting to remove nothing. We now gate against this. The output is still not perfect. E0107 should explicitly detect this case and provide better context, but for now let's avoid the ICE. Fix #108748.
- Loading branch information
Showing
3 changed files
with
102 additions
and
1 deletion.
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
19 changes: 19 additions & 0 deletions
19
tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs
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,19 @@ | ||
// Here, there are two types with the same name. One of these has a `derive` annotation, but in the | ||
// expansion these `impl`s are associated to the the *other* type. There is a suggestion to remove | ||
// unneded type parameters, but because we're now point at a type with no type parameters, the | ||
// suggestion would suggest removing code from an empty span, which would ICE in nightly. | ||
// | ||
// issue: rust-lang/rust#108748 | ||
|
||
struct NotSM; | ||
|
||
#[derive(PartialEq, Eq)] | ||
//~^ ERROR struct takes 0 generic arguments | ||
//~| ERROR struct takes 0 generic arguments | ||
//~| ERROR struct takes 0 generic arguments | ||
//~| ERROR struct takes 0 generic arguments | ||
struct NotSM<T>(T); | ||
//~^ ERROR the name `NotSM` is defined multiple times | ||
//~| ERROR no field `0` | ||
|
||
fn main() {} |
71 changes: 71 additions & 0 deletions
71
tests/ui/duplicate/multiple-types-with-same-name-and-derive.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,71 @@ | ||
error[E0428]: the name `NotSM` is defined multiple times | ||
--> $DIR/multiple-types-with-same-name-and-derive.rs:15:1 | ||
| | ||
LL | struct NotSM; | ||
| ------------- previous definition of the type `NotSM` here | ||
... | ||
LL | struct NotSM<T>(T); | ||
| ^^^^^^^^^^^^^^^^^^^ `NotSM` redefined here | ||
| | ||
= note: `NotSM` must be defined only once in the type namespace of this module | ||
|
||
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied | ||
--> $DIR/multiple-types-with-same-name-and-derive.rs:10:10 | ||
| | ||
LL | #[derive(PartialEq, Eq)] | ||
| ^^^^^^^^^ expected 0 generic arguments | ||
| | ||
note: struct defined here, with 0 generic parameters | ||
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:8 | ||
| | ||
LL | struct NotSM; | ||
| ^^^^^ | ||
|
||
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied | ||
--> $DIR/multiple-types-with-same-name-and-derive.rs:10:10 | ||
| | ||
LL | #[derive(PartialEq, Eq)] | ||
| ^^^^^^^^^ expected 0 generic arguments | ||
| | ||
note: struct defined here, with 0 generic parameters | ||
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:8 | ||
| | ||
LL | struct NotSM; | ||
| ^^^^^ | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied | ||
--> $DIR/multiple-types-with-same-name-and-derive.rs:10:21 | ||
| | ||
LL | #[derive(PartialEq, Eq)] | ||
| ^^ expected 0 generic arguments | ||
| | ||
note: struct defined here, with 0 generic parameters | ||
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:8 | ||
| | ||
LL | struct NotSM; | ||
| ^^^^^ | ||
|
||
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied | ||
--> $DIR/multiple-types-with-same-name-and-derive.rs:10:10 | ||
| | ||
LL | #[derive(PartialEq, Eq)] | ||
| ^^^^^^^^^ expected 0 generic arguments | ||
| | ||
note: struct defined here, with 0 generic parameters | ||
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:8 | ||
| | ||
LL | struct NotSM; | ||
| ^^^^^ | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error[E0609]: no field `0` on type `&NotSM` | ||
--> $DIR/multiple-types-with-same-name-and-derive.rs:15:17 | ||
| | ||
LL | struct NotSM<T>(T); | ||
| ^ unknown field | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
Some errors have detailed explanations: E0107, E0428, E0609. | ||
For more information about an error, try `rustc --explain E0107`. |