Skip to content

Commit 9c78fec

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 9c78fec

File tree

4 files changed

+58
-13
lines changed

4 files changed

+58
-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,25 @@
1+
// Regression test for #126942 and #127804
2+
3+
// Tests that we do not ICE when a projection
4+
// type cannot be fully normalized
5+
6+
struct Thing;
7+
8+
pub trait Every {
9+
type Assoc;
10+
}
11+
impl<T: ?Sized> Every for Thing {
12+
//~^ ERROR the type parameter `T` is not constrained by the impl trait, self type, or predicates
13+
type Assoc = T;
14+
}
15+
16+
// The type of this static normalizes to `Infer`
17+
// thanks to the `?Sized` constraint in the impl above
18+
static I: <Thing as Every>::Assoc = 3;
19+
//~^ ERROR type annotations needed
20+
21+
fn foo(_: <Thing as Every>::Assoc) {}
22+
//~^ ERROR type annotations needed
23+
//~| ERROR type annotations needed
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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:11: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:18: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[E0282]: type annotations needed
17+
--> $DIR/ice-layout-of-invalid-type-126942.rs:21:11
18+
|
19+
LL | fn foo(_: <Thing as Every>::Assoc) {}
20+
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
21+
22+
error[E0282]: type annotations needed
23+
--> $DIR/ice-layout-of-invalid-type-126942.rs:21:8
24+
|
25+
LL | fn foo(_: <Thing as Every>::Assoc) {}
26+
| ^ cannot infer type for type parameter `T`
27+
28+
error: aborting due to 4 previous errors
29+
30+
Some errors have detailed explanations: E0207, E0282, E0283.
31+
For more information about an error, try `rustc --explain E0207`.

0 commit comments

Comments
 (0)