Skip to content

Commit 9cf54f0

Browse files
committed
Fix ICE while normalizing an infer type
Returning an error instead of triggering a debug_assertion when a normalized type still has infer
1 parent 594702e commit 9cf54f0

File tree

4 files changed

+43
-13
lines changed

4 files changed

+43
-13
lines changed

compiler/rustc_traits/src/normalize_erasing_regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<TyCtxt<'tcx>> + Par
4141
// fresh `InferCtxt`. If this assert does trigger, it will give
4242
// us a test case.
4343
debug_assert_eq!(normalized_value, resolved_value);
44+
4445
let erased = infcx.tcx.erase_regions(resolved_value);
45-
debug_assert!(!erased.has_infer(), "{erased:?}");
46-
Ok(erased)
46+
if !erased.has_infer() { Ok(erased) } else { Err(NoSolution) }
4747
}
4848
Err(NoSolution) => Err(NoSolution),
4949
}

tests/crashes/126942.rs

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Regression test for #126942
2+
3+
// Tests that we do not ICE when an attempt
4+
// is made to compute the layout of a type
5+
// that normalizes to an infer type
6+
7+
struct Thing;
8+
9+
pub trait Every {
10+
type Assoc;
11+
}
12+
impl<T: ?Sized> Every for Thing {
13+
//~^ ERROR the type parameter `T` is not constrained by the impl trait, self type, or predicates
14+
type Assoc = T;
15+
}
16+
17+
// The type of this static normalizes to `Infer`
18+
// thanks to the `?Sized` constraint in the impl above
19+
static I: <Thing as Every>::Assoc = 3;
20+
//~^ ERROR type annotations needed
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
2+
--> $DIR/ice-layout-of-invalid-type-126942.rs:12:6
3+
|
4+
LL | impl<T: ?Sized> Every for Thing {
5+
| ^ unconstrained type parameter
6+
7+
error[E0283]: type annotations needed
8+
--> $DIR/ice-layout-of-invalid-type-126942.rs:19:11
9+
|
10+
LL | static I: <Thing as Every>::Assoc = 3;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
12+
|
13+
= note: cannot satisfy `_: Sync`
14+
= note: shared static variables must have a type that implements `Sync`
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0207, E0283.
19+
For more information about an error, try `rustc --explain E0207`.

0 commit comments

Comments
 (0)