Trait bound order-dependent type errors using non_lifetime_binders
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#![feature(non_lifetime_binders)]
pub trait Trait1 {
type Target;
type This<T>: for<U> Trait1<This<U> = Self::This<U>> + Trait1<This<Self::Target> = Self>;
fn cast<T>(self) -> Self::This<T>;
}
pub trait Trait2 {
type Target;
type This<T>: Trait2<This<Self::Target> = Self> + for<U> Trait2<This<U> = Self::This<U>>;
fn cast<T>(self) -> Self::This<T>;
}
fn use1<T: Trait1>(val: T) -> T {
val.cast::<()>().cast::<T::Target>()
}
fn use2<T: Trait2>(val: T) -> T {
val.cast::<()>().cast::<T::Target>()
}
I expected to see this happen: Both versions of the trait to behave the same
Instead, this happened: One version works as expected, succeeding, but the other has a Mismatched Type error
Other details: When using -Znext-solver, both code blocks error out with the same message:
error[E0284]: type annotations needed: cannot satisfy `<<T as Trait2>::This<()> as Trait2>::This<<T as Trait2>::Target> == T`
--> src\lib.rs:22:5
|
22 | val.cast::<()>().cast::<T::Target>()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `<<T as Trait2>::This<()> as Trait2>::This<<T as Trait2>::Target> == T`
Meta
rustc --version --verbose:
rustc 1.80.0-nightly (98489f248 2024-06-06)
binary: rustc
commit-hash: 98489f2487465f3765e5dd28d7305ebfd40f0865
commit-date: 2024-06-06
host: x86_64-pc-windows-msvc
release: 1.80.0-nightly
LLVM version: 18.1.7
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 reproducing the Trait1 and Trait2 examples from the issue in the linked Rust Playground using the reported nightly version, then compare the results with and without -Znext-solver. Trace how the compiler handles the reordered associated-type bounds and verify that equivalent bound orders receive consistent type-checking 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
- Needs clarification
- Newbie friendliness
- 35/100