Skip to content

Commit e997508

Browse files
authored
Rollup merge of #124548 - gurry:113272-ice-failed-to-normalize, r=compiler-errors
Handle normalization failure in `struct_tail_erasing_lifetimes` Fixes #113272 The ICE occurred because the struct being normalized had an error. This PR adds some defensive code to guard against that.
2 parents e3029d2 + 0c71c9d commit e997508

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

Diff for: compiler/rustc_middle/src/ty/layout.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,22 @@ impl<'tcx> SizeSkeleton<'tcx> {
333333
match *ty.kind() {
334334
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
335335
let non_zero = !ty.is_unsafe_ptr();
336-
let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env);
336+
337+
let tail = tcx.struct_tail_with_normalize(
338+
pointee,
339+
|ty| match tcx.try_normalize_erasing_regions(param_env, ty) {
340+
Ok(ty) => ty,
341+
Err(_e) => {
342+
if let Some(guar) = tcx.dcx().has_errors() {
343+
Ty::new_error(tcx, guar)
344+
} else {
345+
bug!("normalization failed, but no errors reported");
346+
}
347+
}
348+
},
349+
|| {},
350+
);
351+
337352
match tail.kind() {
338353
ty::Param(_) | ty::Alias(ty::Projection | ty::Inherent, _) => {
339354
debug_assert!(tail.has_non_region_param());

Diff for: tests/crashes/113272.rs renamed to tests/ui/structs/ice-struct-tail-normalization-113272.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
//@ known-bug: #113272
21
trait Trait {
32
type RefTarget;
43
}
54

65
impl Trait for () where Missing: Trait {}
6+
//~^ ERROR cannot find type `Missing` in this scope
7+
//~| ERROR not all trait items implemented, missing: `RefTarget`
78

89
struct Other {
910
data: <() as Trait>::RefTarget,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0412]: cannot find type `Missing` in this scope
2+
--> $DIR/ice-struct-tail-normalization-113272.rs:5:25
3+
|
4+
LL | impl Trait for () where Missing: Trait {}
5+
| ^^^^^^^ not found in this scope
6+
7+
error[E0046]: not all trait items implemented, missing: `RefTarget`
8+
--> $DIR/ice-struct-tail-normalization-113272.rs:5:1
9+
|
10+
LL | type RefTarget;
11+
| -------------- `RefTarget` from trait
12+
...
13+
LL | impl Trait for () where Missing: Trait {}
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `RefTarget` in implementation
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0046, E0412.
19+
For more information about an error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)