rustc hangs / infinite loop on small example with generic_const_exprs and specialization
Open
Nobody has claimed this yet.
A-const-generics
C-bug
F-generic_const_exprs
I-hang
P-low
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
This code hangs on nightly
#![feature(specialization)]
#![feature(generic_const_exprs)]
use std::mem;
use std::marker::PhantomData;
trait Repr1 {
type Elem;
}
struct TypeWithSize<T, const TSize: usize>(PhantomData<T>);
impl<T> Repr1 for TypeWithSize<T, 1> {
type Elem = u8;
}
impl<T: Sized> Repr1 for T
where
TypeWithSize<T, { mem::size_of::<T>() }>: Repr1,
{
type Elem = <TypeWithSize<T, { mem::size_of::<T>() }> as Repr1>::Elem;
}
It works fine if there is a Repr2 to apparently break the cycle
#![feature(specialization)]
#![feature(generic_const_exprs)]
use std::mem;
use std::marker::PhantomData;
trait Repr1 {
type Elem;
}
struct TypeWithSize<T, const TSize: usize>(PhantomData<T>);
impl<T> Repr1 for TypeWithSize<T, 1> {
type Elem = u8;
}
trait Repr2 {
type Elem;
}
impl<T: Sized> Repr2 for T
where
TypeWithSize<T, { mem::size_of::<T>() }>: Repr1,
{
type Elem = <TypeWithSize<T, { mem::size_of::<T>() }> as Repr1>::Elem;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the minimal reproducer from the first Rust Playground link on nightly and compare it with the second example, which does not hang. Trace the compiler behavior around specialization and generic_const_exprs; done means the first example no longer loops indefinitely while the related example continues to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100