about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2024-09-18 19:30:20 +0200
committerLeón Orell Valerian Liehr <me@fmease.dev>2024-09-18 19:36:44 +0200
commit682c5f485b4cc55ce16315e0d76a5a16ab3064f5 (patch)
tree1825cb0551e8a7a7e26a0584460533256c2b04f3
parentbd8e88fd7b2401242cbcc95d88ef7b8058d59a77 (diff)
downloadrust-682c5f485b4cc55ce16315e0d76a5a16ab3064f5.tar.gz
rust-682c5f485b4cc55ce16315e0d76a5a16ab3064f5.zip
Explicitly mark a hack as a HACK and elaborate its comment
-rw-r--r--compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs15
-rw-r--r--tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs2
-rw-r--r--tests/ui/duplicate/multiple-types-with-same-name-and-derive.stderr20
3 files changed, 20 insertions, 17 deletions
diff --git a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs
index 418f12b7158..236543007fc 100644
--- a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs
+++ b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs
@@ -1049,13 +1049,14 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
             );
 
             if span.is_empty() {
-                // Avoid ICE when types with the same name with `derive`s are in the same scope:
-                // struct NotSM;
-                // #[derive(PartialEq, Eq)]
-                // struct NotSM<T>(T);
-                // With the above code, the suggestion is to remove the generics of the first
-                // `NotSM`, which doesn't *have* generics, so we're suggesting to remove no code
-                // with no code, which ICEs on nightly due to an `assert!`.
+                // HACK: Avoid ICE when types with the same name with `derive`s are in the same scope:
+                //     struct NotSM;
+                //     #[derive(PartialEq, Eq)]
+                //     struct NotSM<T>(T);
+                // With the above code, the suggestion would be to remove the generics of the first
+                // `NotSM`, which doesn't *have* generics, so we would suggest to remove no code with
+                // no code, which would trigger an `assert!` later. Ideally, we would do something a
+                // bit more principled. See closed PR #109082.
             } else {
                 err.span_suggestion(span, msg, "", Applicability::MaybeIncorrect);
             }
diff --git a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs
index 93c25b243e2..8d36981b41b 100644
--- a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs
+++ b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.rs
@@ -2,6 +2,8 @@
 // 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;
 
diff --git a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.stderr b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.stderr
index e3aeb362063..32c3cf44031 100644
--- a/tests/ui/duplicate/multiple-types-with-same-name-and-derive.stderr
+++ b/tests/ui/duplicate/multiple-types-with-same-name-and-derive.stderr
@@ -1,5 +1,5 @@
 error[E0428]: the name `NotSM` is defined multiple times
-  --> $DIR/multiple-types-with-same-name-and-derive.rs:13:1
+  --> $DIR/multiple-types-with-same-name-and-derive.rs:15:1
    |
 LL | struct NotSM;
    | ------------- previous definition of the type `NotSM` here
@@ -10,57 +10,57 @@ LL | struct NotSM<T>(T);
    = 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:8:10
+  --> $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:6:8
+  --> $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:8:10
+  --> $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:6:8
+  --> $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:8:21
+  --> $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:6:8
+  --> $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:8:10
+  --> $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:6:8
+  --> $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:13:17
+  --> $DIR/multiple-types-with-same-name-and-derive.rs:15:17
    |
 LL | struct NotSM<T>(T);
    |                 ^ unknown field