Skip to content

Commit 673ae99

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 673ae99

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

compiler/rustc_middle/src/ty/util.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,20 @@ impl<'tcx> TyCtxt<'tcx> {
190190
param_env: ty::ParamEnv<'tcx>,
191191
) -> Ty<'tcx> {
192192
let tcx = self;
193-
tcx.struct_tail_with_normalize(ty, |ty| tcx.normalize_erasing_regions(param_env, ty), || {})
193+
tcx.struct_tail_with_normalize(
194+
ty,
195+
|ty| match tcx.try_normalize_erasing_regions(param_env, ty) {
196+
Ok(ty) => ty,
197+
Err(_e) => {
198+
if let Some(guar) = tcx.dcx().has_errors() {
199+
Ty::new_error(tcx, guar)
200+
} else {
201+
bug!("normalization failed, but no errors reported");
202+
}
203+
}
204+
},
205+
|| {},
206+
)
194207
}
195208

196209
/// Returns the deeply last field of nested structures, or the same type if
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,
@@ -12,5 +13,6 @@ struct Other {
1213
fn main() {
1314
unsafe {
1415
std::mem::transmute::<Option<()>, Option<&Other>>(None);
16+
//~^ ERROR cannot transmute between types of different sizes, or dependently-sized types
1517
}
1618
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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[E0512]: cannot transmute between types of different sizes, or dependently-sized types
17+
--> $DIR/ice-struct-tail-normalization-113272.rs:15:9
18+
|
19+
LL | std::mem::transmute::<Option<()>, Option<&Other>>(None);
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
|
22+
= note: source type: `Option<()>` (8 bits)
23+
= note: target type: `Option<&Other>` (unable to determine layout for `Other` because `<() as Trait>::RefTarget` cannot be normalized)
24+
25+
error: aborting due to 3 previous errors
26+
27+
Some errors have detailed explanations: E0046, E0412, E0512.
28+
For more information about an error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)