Skip to content

Commit 72acb12

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 72acb12

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

compiler/rustc_middle/src/ty/layout.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,23 @@ 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) => Ty::new_error_with_message(
341+
tcx,
342+
DUMMY_SP,
343+
format!(
344+
"normalization failed for {} but no errors reported",
345+
e.get_type_for_failure()
346+
),
347+
),
348+
},
349+
|| {},
350+
);
351+
336352
match tail.kind() {
337353
ty::Param(_) | ty::Alias(ty::Projection | ty::Inherent, _) => {
338354
debug_assert!(tail.has_non_region_param());

tests/crashes/113272.rs 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)