Skip to content

Commit f1d08bc

Browse files
authored
Rollup merge of rust-lang#104202 - camsteffen:103748, r=estebank
Fix ICE rust-lang#103748 Fixes rust-lang#103748
2 parents a969253 + 76cab67 commit f1d08bc

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

compiler/rustc_middle/src/values.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ fn find_item_ty_spans(
185185
});
186186
if check_params && let Some(args) = path.segments.last().unwrap().args {
187187
let params_in_repr = tcx.params_in_repr(def_id);
188-
for (i, arg) in args.args.iter().enumerate() {
188+
// the domain size check is needed because the HIR may not be well-formed at this point
189+
for (i, arg) in args.args.iter().enumerate().take(params_in_repr.domain_size()) {
189190
if let hir::GenericArg::Type(ty) = arg && params_in_repr.contains(i as u32) {
190191
find_item_ty_spans(tcx, ty, needle, spans, seen_representable);
191192
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![crate_type = "lib"]
2+
3+
struct Apple((Apple, Option(Banana ? Citron)));
4+
//~^ ERROR invalid `?` in type
5+
//~| ERROR expected one of `)` or `,`, found `Citron`
6+
//~| ERROR cannot find type `Citron` in this scope [E0412]
7+
//~| ERROR parenthesized type parameters may only be used with a `Fn` trait [E0214]
8+
//~| ERROR recursive type `Apple` has infinite size [E0072]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
error: invalid `?` in type
2+
--> $DIR/issue-103748-ICE-wrong-braces.rs:3:36
3+
|
4+
LL | struct Apple((Apple, Option(Banana ? Citron)));
5+
| ^ `?` is only allowed on expressions, not types
6+
|
7+
help: if you meant to express that the type might not contain a value, use the `Option` wrapper type
8+
|
9+
LL | struct Apple((Apple, Option(Option<Banana > Citron)));
10+
| +++++++ ~
11+
12+
error: expected one of `)` or `,`, found `Citron`
13+
--> $DIR/issue-103748-ICE-wrong-braces.rs:3:38
14+
|
15+
LL | struct Apple((Apple, Option(Banana ? Citron)));
16+
| -^^^^^^ expected one of `)` or `,`
17+
| |
18+
| help: missing `,`
19+
20+
error[E0412]: cannot find type `Citron` in this scope
21+
--> $DIR/issue-103748-ICE-wrong-braces.rs:3:38
22+
|
23+
LL | struct Apple((Apple, Option(Banana ? Citron)));
24+
| ^^^^^^ not found in this scope
25+
26+
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
27+
--> $DIR/issue-103748-ICE-wrong-braces.rs:3:22
28+
|
29+
LL | struct Apple((Apple, Option(Banana ? Citron)));
30+
| ^^^^^^^^^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses
31+
|
32+
help: use angle brackets instead
33+
|
34+
LL | struct Apple((Apple, Option<Banana ? Citron>));
35+
| ~ ~
36+
37+
error[E0072]: recursive type `Apple` has infinite size
38+
--> $DIR/issue-103748-ICE-wrong-braces.rs:3:1
39+
|
40+
LL | struct Apple((Apple, Option(Banana ? Citron)));
41+
| ^^^^^^^^^^^^ ----- recursive without indirection
42+
|
43+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
44+
|
45+
LL | struct Apple((Box<Apple>, Option(Banana ? Citron)));
46+
| ++++ +
47+
48+
error: aborting due to 5 previous errors
49+
50+
Some errors have detailed explanations: E0072, E0214, E0412.
51+
For more information about an error, try `rustc --explain E0072`.

0 commit comments

Comments
 (0)