-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nightly: Trait resolution picks the wrong trait impl with higher ranked bounds #126006
Comments
I just discovered that swapping the bounds on the (not working) trait Raise{
type Higher<'lt, 'ctx, B>: for<'a, 'b> Lower<'a, 'b, Bound<'a, 'b>> + Lower<'lt, 'ctx, B, T = Self>;
} (working) trait Raise{
type Higher<'lt, 'ctx, B>: Lower<'lt, 'ctx, B, T = Self> + for<'a, 'b> Lower<'a, 'b, Bound<'a, 'b>>;
} |
I have simplified the code to this fn main() {}
trait Raise{
type Higher<'lt>: for<'a> Lower<'a> + Lower<'lt, T = Self>;
}
trait Lower<'lt> {
type T: Raise<Higher<'lt> = Self>;
}
fn use_lower<'a, T: Raise>(x: T) {
use_higher::<<T as Raise>::Higher::<'a>>(x);
}
fn use_higher<'a, H: for<'b> Lower<'b>>(x: <H as Lower<'a>>::T) {} As before switching it with type Higher<'lt>: Lower<'lt, T = Self> + for<'a> Lower<'a>; works |
cc @lcnr |
has already been reverted on beta in #125629. |
the unstable result depending on whether the associated type bounds are swapped is caused by rust/compiler/rustc_trait_selection/src/traits/select/mod.rs Lines 1965 to 1970 in a330e49
before #119820 we already discarded the non-hr item bounds - |
Here is a smaller example that doesn't use GATs. pub trait ForLt<'a> {
type T;
}
pub trait Hrt: for<'a> ForLt<'a> {}
pub trait Other<'a> {
type Higher: Hrt + ForLt<'a>;
} error: implementation of `ForLt` is not general enough
--> src/main.rs:10:18
|
7 | pub trait Hrt: for<'a> ForLt<'a> {}
| --------------------------------
| | |
| | doesn't satisfy where-clause
| due to a where-clause on `Hrt`...
...
10 | type Higher: Hrt + ForLt<'a>;
| ^^^
|
= note: ...`<Self as Other<'a>>::Higher` must implement `ForLt<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `ForLt<'a>` (A more meaningful example is to use Is the |
Same as #125194 . Changes in #119820 were reverted so in theory this regression should be neutralized in the current nightly. Can you check @konnorandrews ? thanks |
I only reverted it on beta, it still affects nightly (and the new beta) |
THis has since been fully reverted, closing as fixed. We already have added tests for this. |
Code
I tried this code:
I expected to see this happen: For it to compile (based on rustc previously accepting this code)
I am not 100% sure this code is supposed to be allowed.
Instead, this happened: A compiler error
Version it worked on
It most recently worked on: Rust 1.78.0
Version with regression
Rust 1.79.0 and later. Bisected to commit 43f4f2a
@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged
The text was updated successfully, but these errors were encountered: