-
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
wf: discard nested obligations with placeholders #103565
Conversation
using the reasoning from the PR description @rfcbot fcp merge we may also want to quickly talk about this in a meeting. |
Team member @lcnr has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
/// trivially implied from the `param_env`. | ||
/// | ||
/// This means that we WF bounds aren't always sufficiently checked for now. | ||
fn emit_obligations_for<'tcx, T: TypeVisitable<'tcx>>(value: T) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make this a method on TypeVisitable and add warning doc comments on has_escaping_bound_var
336ba53
to
f824552
Compare
☔ The latest upstream changes (presumably #104846) made this pull request unmergeable. Please resolve the merge conflicts. |
So... we are removing some checks now that we'll later (want to?) add in a less whacky/broken way? |
closing as it is pretty much only needed to deal with my new approach to implied bounds, as that one is stuck on coinductive trait obligations. Might reopen this PR once we have those. |
WF check currently treats
WF(for<'a> fn(MyType<'a>))
differently fromfor<'a> WF(MyType<'a>)
. The first one uses a bound variable when computing the WF requirements forMyType
, while the second one starts by instantiating the bound variable with a placeholder. This means that currently, we emit WF requirements in the second case while discarding them for the first.However, checking WF for the second one is also broken by binders not having any implications. See
src/test/ui/wf/higher-ranked/on-impl.rs
which currently fails. (playground) This happens becausefor<'a> &'a T
should meanfor<'a> where { T: 'a } &'a T
instead of&'a T
. When adding implied bounds topredicates_of
, this kind of issue happens pretty much all the time we have a higher ranked trait bound. We should therefore also skip nested obligations in wf if they have placeholders.As long as we do not consider explicit WF bounds for implied-bounds, this should not cause any additional unsoundness. It may allow for more instances of an undesirable pattern but doing so is difficult. For impls, most of the time the placeholders when using the impl were free regions when checking the impl, at which point we did consider to nested obligations. It is possible using higher ranked bounds, see
src/test/ui/wf/higher-ranked/ignored-trait-bound.rs
whereHasWfPlaceholder
currently results in an error but is allowed with this PR.I don't expect this change to meaningfully impact the prevalence of this pattern. In our test suite there is a single existing test for which we now skip a nested obligation while there are far more tests where we discard obligations due to escaping bound vars.
rust/src/test/ui/higher-rank-trait-bounds/issue-95230.rs
Lines 3 to 7 in d49e7e7
This unblocks future work on implied bounds and feels like an acceptable band-aid until we can correctly deal with implications.
r? types