Skip to content

Commit 682c5f4

Browse files
committed
Explicitly mark a hack as a HACK and elaborate its comment
1 parent bd8e88f commit 682c5f4

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1049,13 +1049,14 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
10491049
);
10501050

10511051
if span.is_empty() {
1052-
// Avoid ICE when types with the same name with `derive`s are in the same scope:
1053-
// struct NotSM;
1054-
// #[derive(PartialEq, Eq)]
1055-
// struct NotSM<T>(T);
1056-
// With the above code, the suggestion is to remove the generics of the first
1057-
// `NotSM`, which doesn't *have* generics, so we're suggesting to remove no code
1058-
// with no code, which ICEs on nightly due to an `assert!`.
1052+
// HACK: Avoid ICE when types with the same name with `derive`s are in the same scope:
1053+
// struct NotSM;
1054+
// #[derive(PartialEq, Eq)]
1055+
// struct NotSM<T>(T);
1056+
// With the above code, the suggestion would be to remove the generics of the first
1057+
// `NotSM`, which doesn't *have* generics, so we would suggest to remove no code with
1058+
// no code, which would trigger an `assert!` later. Ideally, we would do something a
1059+
// bit more principled. See closed PR #109082.
10591060
} else {
10601061
err.span_suggestion(span, msg, "", Applicability::MaybeIncorrect);
10611062
}

tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// expansion these `impl`s are associated to the the *other* type. There is a suggestion to remove
33
// unneded type parameters, but because we're now point at a type with no type parameters, the
44
// suggestion would suggest removing code from an empty span, which would ICE in nightly.
5+
//
6+
// issue: rust-lang/rust#108748
57

68
struct NotSM;
79

tests/ui/duplicate/multiple-types-with-same-name-and-derive.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0428]: the name `NotSM` is defined multiple times
2-
--> $DIR/multiple-types-with-same-name-and-derive.rs:13:1
2+
--> $DIR/multiple-types-with-same-name-and-derive.rs:15:1
33
|
44
LL | struct NotSM;
55
| ------------- previous definition of the type `NotSM` here
@@ -10,57 +10,57 @@ LL | struct NotSM<T>(T);
1010
= note: `NotSM` must be defined only once in the type namespace of this module
1111

1212
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
13-
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:10
13+
--> $DIR/multiple-types-with-same-name-and-derive.rs:10:10
1414
|
1515
LL | #[derive(PartialEq, Eq)]
1616
| ^^^^^^^^^ expected 0 generic arguments
1717
|
1818
note: struct defined here, with 0 generic parameters
19-
--> $DIR/multiple-types-with-same-name-and-derive.rs:6:8
19+
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:8
2020
|
2121
LL | struct NotSM;
2222
| ^^^^^
2323

2424
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
25-
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:10
25+
--> $DIR/multiple-types-with-same-name-and-derive.rs:10:10
2626
|
2727
LL | #[derive(PartialEq, Eq)]
2828
| ^^^^^^^^^ expected 0 generic arguments
2929
|
3030
note: struct defined here, with 0 generic parameters
31-
--> $DIR/multiple-types-with-same-name-and-derive.rs:6:8
31+
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:8
3232
|
3333
LL | struct NotSM;
3434
| ^^^^^
3535
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3636

3737
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
38-
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:21
38+
--> $DIR/multiple-types-with-same-name-and-derive.rs:10:21
3939
|
4040
LL | #[derive(PartialEq, Eq)]
4141
| ^^ expected 0 generic arguments
4242
|
4343
note: struct defined here, with 0 generic parameters
44-
--> $DIR/multiple-types-with-same-name-and-derive.rs:6:8
44+
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:8
4545
|
4646
LL | struct NotSM;
4747
| ^^^^^
4848

4949
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
50-
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:10
50+
--> $DIR/multiple-types-with-same-name-and-derive.rs:10:10
5151
|
5252
LL | #[derive(PartialEq, Eq)]
5353
| ^^^^^^^^^ expected 0 generic arguments
5454
|
5555
note: struct defined here, with 0 generic parameters
56-
--> $DIR/multiple-types-with-same-name-and-derive.rs:6:8
56+
--> $DIR/multiple-types-with-same-name-and-derive.rs:8:8
5757
|
5858
LL | struct NotSM;
5959
| ^^^^^
6060
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
6161

6262
error[E0609]: no field `0` on type `&NotSM`
63-
--> $DIR/multiple-types-with-same-name-and-derive.rs:13:17
63+
--> $DIR/multiple-types-with-same-name-and-derive.rs:15:17
6464
|
6565
LL | struct NotSM<T>(T);
6666
| ^ unknown field

0 commit comments

Comments
 (0)