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

Do not ICE when trying to get layout of an unexpected type #127803

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions compiler/rustc_traits/src/normalize_erasing_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<TyCtxt<'tcx>> + Par
// fresh `InferCtxt`. If this assert does trigger, it will give
// us a test case.
debug_assert_eq!(normalized_value, resolved_value);

let erased = infcx.tcx.erase_regions(resolved_value);
debug_assert!(!erased.has_infer(), "{erased:?}");
Ok(erased)
if !erased.has_infer() { Ok(erased) } else { Err(NoSolution) }
}
Err(NoSolution) => Err(NoSolution),
}
Expand Down
11 changes: 0 additions & 11 deletions tests/crashes/126942.rs

This file was deleted.

25 changes: 25 additions & 0 deletions tests/ui/layout/ice-layout-of-invalid-type-126942.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Regression test for #126942 and #127804

// Tests that we do not ICE when a projection
// type cannot be fully normalized

struct Thing;

pub trait Every {
type Assoc;
}
impl<T: ?Sized> Every for Thing {
//~^ ERROR the type parameter `T` is not constrained by the impl trait, self type, or predicates
type Assoc = T;
}

// The type of this static normalizes to `Infer`
// thanks to the `?Sized` constraint in the impl above
static I: <Thing as Every>::Assoc = 3;
//~^ ERROR type annotations needed

fn foo(_: <Thing as Every>::Assoc) {}
//~^ ERROR type annotations needed
//~| ERROR type annotations needed

fn main() {}
31 changes: 31 additions & 0 deletions tests/ui/layout/ice-layout-of-invalid-type-126942.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
--> $DIR/ice-layout-of-invalid-type-126942.rs:11:6
|
LL | impl<T: ?Sized> Every for Thing {
| ^ unconstrained type parameter

error[E0283]: type annotations needed
--> $DIR/ice-layout-of-invalid-type-126942.rs:18:11
|
LL | static I: <Thing as Every>::Assoc = 3;
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
|
= note: cannot satisfy `_: Sync`
= note: shared static variables must have a type that implements `Sync`

error[E0282]: type annotations needed
--> $DIR/ice-layout-of-invalid-type-126942.rs:21:11
|
LL | fn foo(_: <Thing as Every>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`

error[E0282]: type annotations needed
--> $DIR/ice-layout-of-invalid-type-126942.rs:21:8
|
LL | fn foo(_: <Thing as Every>::Assoc) {}
| ^ cannot infer type for type parameter `T`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0207, E0282, E0283.
For more information about an error, try `rustc --explain E0207`.
Loading