Skip to content

Commit c31940d

Browse files
Fix ICE in ptr_metadata_ty_or_tail for recursive associated types
1 parent 5a0d572 commit c31940d

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,8 +1769,9 @@ impl<'tcx> Ty<'tcx> {
17691769

17701770
| ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
17711771

1772-
ty::Infer(ty::TyVar(_))
1773-
| ty::Pat(..)
1772+
ty::Infer(ty::TyVar(_)) => Ok(tcx.types.unit),
1773+
1774+
ty::Pat(..)
17741775
| ty::Bound(..)
17751776
| ty::Placeholder(..)
17761777
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => bug!(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/153431>.
2+
// Used to ICE in `ptr_metadata_ty_or_tail` when computing pointer metadata
3+
// for a struct whose tail field has a recursive associated type.
4+
//~^^^ ERROR overflow evaluating the requirement `<Bar as Trait>::Assoc2 == _`
5+
6+
trait Trait {
7+
type Assoc2;
8+
}
9+
10+
struct Bar;
11+
impl Trait for Bar {
12+
type Assoc2 = Result<(), <Bar as Trait>::Assoc2>;
13+
//~^ ERROR overflow evaluating the requirement `<Bar as Trait>::Assoc2 == _`
14+
}
15+
16+
struct Foo {
17+
field: <Bar as Trait>::Assoc2,
18+
//~^ ERROR overflow evaluating the requirement `<Bar as Trait>::Assoc2 == _`
19+
}
20+
21+
static BAR: u8 = 42;
22+
static FOO2: &Foo = unsafe { std::mem::transmute(&BAR) };
23+
24+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0275]: overflow evaluating the requirement `<Bar as Trait>::Assoc2 == _`
2+
--> $DIR/issue-153431-ptr-metadata-recursive-assoc-type-ice.rs:12:19
3+
|
4+
LL | type Assoc2 = Result<(), <Bar as Trait>::Assoc2>;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error[E0275]: overflow evaluating the requirement `<Bar as Trait>::Assoc2 == _`
8+
--> $DIR/issue-153431-ptr-metadata-recursive-assoc-type-ice.rs:17:12
9+
|
10+
LL | field: <Bar as Trait>::Assoc2,
11+
| ^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error[E0275]: overflow evaluating the requirement `<Bar as Trait>::Assoc2 == _`
14+
15+
error: aborting due to 3 previous errors
16+
17+
For more information about this error, try `rustc --explain E0275`.

0 commit comments

Comments
 (0)