Skip to content

Commit 22a20e3

Browse files
committed
Auto merge of #94711 - ouz-a:master3, r=oli-obk
Return early to fix ICE This fixes #94627, ICE happens because compiler tries to suggest constraining type parameter but the only constraint is implicit `std::Sized` one, so it gets removed and there is nothing to suggest resulting in ICE.
2 parents ed2a69c + 1853ffc commit 22a20e3

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

compiler/rustc_middle/src/ty/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ pub fn suggest_constraining_type_params<'a>(
512512
};
513513

514514
err.span_suggestion_verbose(span, msg, suggestion, applicability);
515-
} else {
515+
} else if suggestions.len() > 1 {
516516
err.multipart_suggestion_verbose(
517517
"consider restricting type parameters",
518518
suggestions.into_iter().map(|(span, suggestion, _)| (span, suggestion)).collect(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct Bug<S>{ //~ ERROR parameter `S` is never used [E0392]
2+
A: [(); {
3+
let x: [u8; Self::W] = [0; Self::W]; //~ ERROR generic `Self` types are currently not permitted in anonymous constants
4+
//~^ ERROR generic `Self` types are currently not permitted in anonymous constants
5+
//~^^ ERROR the size for values of type `S` cannot be known at compilation time [E0277]
6+
F //~ ERROR cannot find value `F` in this scope [E0425]
7+
}
8+
} //~ ERROR mismatched closing delimiter: `}`
9+
//~^ ERROR mismatched closing delimiter: `}`
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
error: mismatched closing delimiter: `}`
2+
--> $DIR/constrain-suggest-ice.rs:2:8
3+
|
4+
LL | struct Bug<S>{
5+
| - closing delimiter possibly meant for this
6+
LL | A: [(); {
7+
| ^ unclosed delimiter
8+
...
9+
LL | }
10+
| ^ mismatched closing delimiter
11+
12+
error: mismatched closing delimiter: `}`
13+
--> $DIR/constrain-suggest-ice.rs:2:8
14+
|
15+
LL | struct Bug<S>{
16+
| - closing delimiter possibly meant for this
17+
LL | A: [(); {
18+
| ^ unclosed delimiter
19+
...
20+
LL | }
21+
| ^ mismatched closing delimiter
22+
23+
error[E0425]: cannot find value `F` in this scope
24+
--> $DIR/constrain-suggest-ice.rs:6:9
25+
|
26+
LL | F
27+
| ^
28+
|
29+
help: a local variable with a similar name exists
30+
|
31+
LL | x
32+
| ~
33+
help: you might be missing a type parameter
34+
|
35+
LL | struct Bug<S, F>{
36+
| +++
37+
38+
error: generic `Self` types are currently not permitted in anonymous constants
39+
--> $DIR/constrain-suggest-ice.rs:3:21
40+
|
41+
LL | let x: [u8; Self::W] = [0; Self::W];
42+
| ^^^^
43+
44+
error: generic `Self` types are currently not permitted in anonymous constants
45+
--> $DIR/constrain-suggest-ice.rs:3:36
46+
|
47+
LL | let x: [u8; Self::W] = [0; Self::W];
48+
| ^^^^
49+
50+
error[E0277]: the size for values of type `S` cannot be known at compilation time
51+
--> $DIR/constrain-suggest-ice.rs:3:36
52+
|
53+
LL | struct Bug<S>{
54+
| - this type parameter needs to be `std::marker::Sized`
55+
LL | A: [(); {
56+
LL | let x: [u8; Self::W] = [0; Self::W];
57+
| ^^^^^^^ doesn't have a size known at compile-time
58+
|
59+
note: required by a bound in `Bug`
60+
--> $DIR/constrain-suggest-ice.rs:1:12
61+
|
62+
LL | struct Bug<S>{
63+
| ^ required by this bound in `Bug`
64+
help: consider relaxing the implicit `Sized` restriction
65+
|
66+
LL | struct Bug<S: ?Sized>{
67+
| ++++++++
68+
69+
error[E0392]: parameter `S` is never used
70+
--> $DIR/constrain-suggest-ice.rs:1:12
71+
|
72+
LL | struct Bug<S>{
73+
| ^ unused parameter
74+
|
75+
= help: consider removing `S`, referring to it in a field, or using a marker such as `PhantomData`
76+
= help: if you intended `S` to be a const parameter, use `const S: usize` instead
77+
78+
error: aborting due to 7 previous errors
79+
80+
Some errors have detailed explanations: E0277, E0392, E0425.
81+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)