about summary refs log tree commit diff
diff options
context:
space:
mode:
authorouz-a <oguz.agcayazi@gmail.com>2022-03-07 21:55:58 +0300
committerouz-a <oguz.agcayazi@gmail.com>2022-03-07 21:55:58 +0300
commitb930efb3546777fce80d941489afe888d6e654a6 (patch)
tree0d837781fce6755d3c319133758595614f3a1ae0
parentecb867ec3cefa97a5807453a68758392730e3ed9 (diff)
fix
-rw-r--r--compiler/rustc_middle/src/ty/diagnostics.rs6
-rw-r--r--src/test/ui/suggestions/constrain-suggest-ice.rs11
-rw-r--r--src/test/ui/suggestions/constrain-suggest-ice.stderr81
3 files changed, 98 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs
index 99a3d4c7fe4..19c80ac7f1a 100644
--- a/compiler/rustc_middle/src/ty/diagnostics.rs
+++ b/compiler/rustc_middle/src/ty/diagnostics.rs
@@ -325,6 +325,12 @@ pub fn suggest_constraining_type_params<'a>(
             }
         }
 
+        // This check is always run on non-valid code
+        // to not trigger ICE
+        if constraints.is_empty() && suggestions.is_empty() {
+            return false;
+        }
+
         if constraints.is_empty() {
             continue;
         }
diff --git a/src/test/ui/suggestions/constrain-suggest-ice.rs b/src/test/ui/suggestions/constrain-suggest-ice.rs
new file mode 100644
index 00000000000..69b874bed1b
--- /dev/null
+++ b/src/test/ui/suggestions/constrain-suggest-ice.rs
@@ -0,0 +1,11 @@
+struct Bug<S>{ //~ ERROR parameter `S` is never used [E0392]
+    A: [(); {
+        let x: [u8; Self::W] = [0; Self::W]; //~ ERROR generic `Self` types are currently not permitted in anonymous constants
+        //~^ ERROR generic `Self` types are currently not permitted in anonymous constants
+        //~^^ ERROR the size for values of type `S` cannot be known at compilation time [E0277]
+        F //~ ERROR cannot find value `F` in this scope [E0425]
+    }
+} //~ ERROR mismatched closing delimiter: `}`
+//~^ ERROR mismatched closing delimiter: `}`
+
+fn main() {}
diff --git a/src/test/ui/suggestions/constrain-suggest-ice.stderr b/src/test/ui/suggestions/constrain-suggest-ice.stderr
new file mode 100644
index 00000000000..477eb278679
--- /dev/null
+++ b/src/test/ui/suggestions/constrain-suggest-ice.stderr
@@ -0,0 +1,81 @@
+error: mismatched closing delimiter: `}`
+  --> $DIR/constrain-suggest-ice.rs:2:8
+   |
+LL | struct Bug<S>{
+   |              - closing delimiter possibly meant for this
+LL |     A: [(); {
+   |        ^ unclosed delimiter
+...
+LL | }
+   | ^ mismatched closing delimiter
+
+error: mismatched closing delimiter: `}`
+  --> $DIR/constrain-suggest-ice.rs:2:8
+   |
+LL | struct Bug<S>{
+   |              - closing delimiter possibly meant for this
+LL |     A: [(); {
+   |        ^ unclosed delimiter
+...
+LL | }
+   | ^ mismatched closing delimiter
+
+error[E0425]: cannot find value `F` in this scope
+  --> $DIR/constrain-suggest-ice.rs:6:9
+   |
+LL |         F
+   |         ^
+   |
+help: a local variable with a similar name exists
+   |
+LL |         x
+   |         ~
+help: you might be missing a type parameter
+   |
+LL | struct Bug<S, F>{
+   |             +++
+
+error: generic `Self` types are currently not permitted in anonymous constants
+  --> $DIR/constrain-suggest-ice.rs:3:21
+   |
+LL |         let x: [u8; Self::W] = [0; Self::W];
+   |                     ^^^^
+
+error: generic `Self` types are currently not permitted in anonymous constants
+  --> $DIR/constrain-suggest-ice.rs:3:36
+   |
+LL |         let x: [u8; Self::W] = [0; Self::W];
+   |                                    ^^^^
+
+error[E0277]: the size for values of type `S` cannot be known at compilation time
+  --> $DIR/constrain-suggest-ice.rs:3:36
+   |
+LL | struct Bug<S>{
+   |            - this type parameter needs to be `std::marker::Sized`
+LL |     A: [(); {
+LL |         let x: [u8; Self::W] = [0; Self::W];
+   |                                    ^^^^^^^ doesn't have a size known at compile-time
+   |
+note: required by a bound in `Bug`
+  --> $DIR/constrain-suggest-ice.rs:1:12
+   |
+LL | struct Bug<S>{
+   |            ^ required by this bound in `Bug`
+help: consider relaxing the implicit `Sized` restriction
+   |
+LL | struct Bug<S: ?Sized>{
+   |             ++++++++
+
+error[E0392]: parameter `S` is never used
+  --> $DIR/constrain-suggest-ice.rs:1:12
+   |
+LL | struct Bug<S>{
+   |            ^ unused parameter
+   |
+   = help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData`
+   = help: if you intended `S` to be a const parameter, use `const S: usize` instead
+
+error: aborting due to 7 previous errors
+
+Some errors have detailed explanations: E0277, E0392, E0425.
+For more information about an error, try `rustc --explain E0277`.