Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICE #103748 #104202

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ fn find_item_ty_spans(
});
if check_params && let Some(args) = path.segments.last().unwrap().args {
let params_in_repr = tcx.params_in_repr(def_id);
for (i, arg) in args.args.iter().enumerate() {
// the domain size check is needed because the HIR may not be well-formed at this point
for (i, arg) in args.args.iter().enumerate().take(params_in_repr.domain_size()) {
if let hir::GenericArg::Type(ty) = arg && params_in_repr.contains(i as u32) {
find_item_ty_spans(tcx, ty, needle, spans, seen_representable);
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/parser/issue-103748-ICE-wrong-braces.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![crate_type = "lib"]

struct Apple((Apple, Option(Banana ? Citron)));
//~^ ERROR invalid `?` in type
//~| ERROR expected one of `)` or `,`, found `Citron`
//~| ERROR cannot find type `Citron` in this scope [E0412]
//~| ERROR parenthesized type parameters may only be used with a `Fn` trait [E0214]
//~| ERROR recursive type `Apple` has infinite size [E0072]
51 changes: 51 additions & 0 deletions src/test/ui/parser/issue-103748-ICE-wrong-braces.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
error: invalid `?` in type
--> $DIR/issue-103748-ICE-wrong-braces.rs:3:36
|
LL | struct Apple((Apple, Option(Banana ? Citron)));
| ^ `?` is only allowed on expressions, not types
|
help: if you meant to express that the type might not contain a value, use the `Option` wrapper type
|
LL | struct Apple((Apple, Option(Option<Banana > Citron)));
| +++++++ ~

error: expected one of `)` or `,`, found `Citron`
--> $DIR/issue-103748-ICE-wrong-braces.rs:3:38
|
LL | struct Apple((Apple, Option(Banana ? Citron)));
| -^^^^^^ expected one of `)` or `,`
| |
| help: missing `,`

error[E0412]: cannot find type `Citron` in this scope
--> $DIR/issue-103748-ICE-wrong-braces.rs:3:38
|
LL | struct Apple((Apple, Option(Banana ? Citron)));
| ^^^^^^ not found in this scope

error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
--> $DIR/issue-103748-ICE-wrong-braces.rs:3:22
|
LL | struct Apple((Apple, Option(Banana ? Citron)));
| ^^^^^^^^^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses
|
help: use angle brackets instead
|
LL | struct Apple((Apple, Option<Banana ? Citron>));
| ~ ~

error[E0072]: recursive type `Apple` has infinite size
--> $DIR/issue-103748-ICE-wrong-braces.rs:3:1
|
LL | struct Apple((Apple, Option(Banana ? Citron)));
| ^^^^^^^^^^^^ ----- recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | struct Apple((Box<Apple>, Option(Banana ? Citron)));
| ++++ +

error: aborting due to 5 previous errors

Some errors have detailed explanations: E0072, E0214, E0412.
For more information about an error, try `rustc --explain E0072`.