rustc hangs with gordian knot of trait bounds
Open
Nobody has claimed this yet.
A-trait-system
C-bug
fixed-by-next-solver
I-compiletime
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Given the following code, rustc hangs:
mod asn1 {
pub trait Asn1Writable: Sized {}
pub trait SimpleAsn1Writable: Sized {}
impl<T: SimpleAsn1Writable> Asn1Writable for T {}
impl<T: SimpleAsn1Writable> SimpleAsn1Writable for &T {}
impl<T: SimpleAsn1Writable> SimpleAsn1Writable for Box<T> {}
impl<T: Asn1Writable> Asn1Writable for Option<T> {}
pub trait Asn1DefinedByWritable: Sized {}
}
mod common {
use crate::asn1;
pub struct AlgorithmIdentifier<'a> {
pub params: AlgorithmParameters<'a>,
}
impl<'a> asn1::SimpleAsn1Writable for AlgorithmIdentifier<'a> where
AlgorithmParameters<'a>: asn1::Asn1DefinedByWritable
{
}
pub enum AlgorithmParameters<'a> {
Sha1,
Pbkdf2(PBKDF2Params<'a>),
}
impl<'a> asn1::Asn1DefinedByWritable for AlgorithmParameters<'a>
where
PBES2Params<'a>: asn1::Asn1Writable,
PBKDF2Params<'a>: asn1::Asn1Writable,
{
}
pub const PSS_SHA1_HASH_ALG: AlgorithmIdentifier<'_> = AlgorithmIdentifier {
params: AlgorithmParameters::Sha1,
};
pub struct RsaPssParameters<'a> {
pub hash_algorithm: AlgorithmIdentifier<'a>,
}
impl<'a> asn1::SimpleAsn1Writable for RsaPssParameters<'a> {}
pub struct PBES2Params<'a> {
pub key_derivation_func: Box<AlgorithmIdentifier<'a>>,
}
impl<'a> asn1::SimpleAsn1Writable for PBES2Params<'a> where
Box<AlgorithmIdentifier<'a>>: asn1::Asn1Writable
{
}
pub struct PBKDF2Params<'a> {
pub salt: &'a [u8],
}
impl<'a> asn1::SimpleAsn1Writable for PBKDF2Params<'a> where
Box<AlgorithmIdentifier<'a>>: asn1::Asn1Writable
{
}
}
pub fn write_element<T: asn1::Asn1Writable>(val: &T) {
todo!()
}
pub fn f(p: &common::RsaPssParameters<'_>) {
write_element(&Some(&p.hash_algorithm));
}
fn main() {}
/t/q ❯❯❯ rustc src/main.rs
[no amount of patience is enough]
This is minimized from https://github.com/pyca/cryptography and https://github.com/alex/rust-asn1.
Meta
rustc --version --verbose:
rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: aarch64-apple-darwin
release: 1.82.0
LLVM version: 19.1.1
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 reproducer in src/main.rs with rustc 1.82.0 and confirm that trait-bound evaluation does not terminate. Trace the compiler's handling of the recursive trait bounds, and consider the issue fixed when this input terminates without hanging while preserving the expected compilation behavior.
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
- Clearly specified
- Newbie friendliness
- 38/100