Skip to content

Commit 0c71c9d

Browse files
committed
Handle normalization failure in struct_tail_erasing_lifetimes
Fixes an ICE that occurred when the struct in question has an error
1 parent 9084601 commit 0c71c9d

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

compiler/rustc_middle/src/ty/layout.rs

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

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)