Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Oct 26, 2022

WF check currently treats WF(for<'a> fn(MyType<'a>)) differently from for<'a> WF(MyType<'a>). The first one uses a bound variable when computing the WF requirements for MyType, 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 because for<'a> &'a T should mean for<'a> where { T: 'a } &'a T instead of &'a T. When adding implied bounds to predicates_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 where HasWfPlaceholder 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.

pub struct Bar
where
for<'a> &'a mut Self:;
fn main() {}

This unblocks future work on implied bounds and feels like an acceptable band-aid until we can correctly deal with implications.

r? types

@lcnr lcnr added A-type-system Area: Type system T-types Relevant to the types team, which will review and decide on the PR/issue. A-implied-bounds Area: Implied bounds / inferred outlives-bounds labels Oct 26, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 26, 2022
@lcnr
Copy link
Contributor Author

lcnr commented Oct 26, 2022

using the reasoning from the PR description

@rfcbot fcp merge

we may also want to quickly talk about this in a meeting.

@rfcbot
Copy link

rfcbot commented Oct 26, 2022

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.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 26, 2022
/// 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 {
Copy link
Contributor

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

@lcnr lcnr force-pushed the wf-no-placeholders branch from 336ba53 to f824552 Compare October 26, 2022 13:12
@bors
Copy link
Contributor

bors commented Nov 25, 2022

☔ The latest upstream changes (presumably #104846) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 28, 2022

So... we are removing some checks now that we'll later (want to?) add in a less whacky/broken way?

@lcnr
Copy link
Contributor Author

lcnr commented Nov 29, 2022

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.

@lcnr lcnr closed this Nov 29, 2022
@rfcbot rfcbot removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-implied-bounds Area: Implied bounds / inferred outlives-bounds A-type-system Area: Type system S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants