-
Notifications
You must be signed in to change notification settings - Fork 13k
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
correctly handle normalization in implied bounds query #109482
Conversation
that's really cool 👍 i remember that we still have that issue during borrowck use std::any::Any;
trait Trait {
type Assoc;
}
impl<T: 'static> Trait for T {
type Assoc = &'static T;
}
fn implies_t_static<T>(t: T, x: <T as Trait>::Assoc) -> Box<dyn Any> {
Box::new(t)
} I forgot why exactly we had to add both the normalized and the unnormalized signature types for implied bounds, maybe that was also an issue solved by opportunistically resolving region vars in the query response? why is this still a draft? |
5001a41
to
8e4a7e1
Compare
This comment has been minimized.
This comment has been minimized.
We now do it automatically inside implied_outlives_bounds query.
7b388ba
to
e9e0e7e
Compare
@lcnr I breaked this code in 00a80b0 only to assess the impact with crater. That said, this only breaks borrowck -- we still accept this in wfcheck: trait Trait {
type Assoc;
}
impl<T: 'static> Trait for Box<T> {
type Assoc = &'static T;
}
impl<T> Trait for (T, <Box<T> as Trait>::Assoc) {
type Assoc = &'static T; // We can still assume T: 'static by wfcheck
} |
@bors try |
⌛ Trying commit 00a80b04fd4235d74626d6e7071e4c58803cbd2f with merge 78392dafb07418956e6952e68a24a94edd0c8dc6... |
☀️ Try build successful - checks-actions |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
☀️ Try build successful - checks-actions |
@craterbot run mode=check-only crates=https://crater-reports.s3.amazonaws.com/pr-109482/retry-regressed-list.txt |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
We currently consider bounds only on impls used during normalization while computing implied bounds. This means that removing bounds on impls is a theoretical breaking change. This PR causes us to only consider implied bounds which are from WF requirements directly and stops considering bounds from normalization. This allows users to safely remove (region) bounds from their impls. The following code currently compiles but will break with this change: use core::any::Any;
trait Trait {
type Assoc;
}
impl<X: 'static> Trait for Vec<X> {
type Assoc = ();
}
struct Foo<T: Trait>(T)
where
T::Assoc: Clone; // any predicate using `T::Assoc` works here
fn foo<X>(x: X, _: Foo<Vec<X>>) -> Box<dyn Any> {
Box::new(x) // gets to assume `X: 'static` from the bound on the impl
} This is relied on by 2 crates: This breakage is fixing a previously underspecified part of the language and is therefore acceptable. I think we should open PRs for both of these crates as soon as possible, fixing this issue. Maybe even asking the bevy devs to emit point releases for some previous versions, and then land this at the start of the next nightly cycle: April 14th. going to start a types FCP after we have the PRs up to fix these 2 crates |
alright, bevy is very annoying to fix. We would have to add Considering that region bounds on trait definitions are already used as implied bounds somewhere? use std::any::Any;
trait Trait: 'static {}
fn foo<T: Trait>(x: T) -> Box<dyn Any> {
Box::new(x)
} Maybe we should apply this consistently to trait predicates in implied bounds, looking at the nested predicates of trait bounds and considering the outlives predicates... not sure why that isn't currently happening/what exactly is happening here. With this we should only have to add a |
closing in favor of the lint version #109763. |
…=<try> correctly handle normalization in implied bounds query v2 Revives rust-lang#109482. I've opened a new PR because Github doesn't allow me to reuse the old one. Updated to refresh the toolchain build in order to test bevy.
One subtle bug with the
implied_outlives_bounds
is that it adds implied bounds from trait impls. Example:This is not a user-visible bug only because wfcheck currently computes implied bounds for fully normalized types only.(edit: this is not correct unfortunately. See #109628) The only place where we use implied bounds for unnormalized types during HIR analysis is incompare_predicate_entailment
.This PR fixes this by using
wf::unnormalized_obligations
instead ofwf::obligations
.Fixes #109628.
Fixes #109799.
Additional changes :
r? @lcnr