Skip to content

apply_member_constraints is incomplete #142073

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

Open
lcnr opened this issue Jun 5, 2025 · 0 comments
Open

apply_member_constraints is incomplete #142073

lcnr opened this issue Jun 5, 2025 · 0 comments
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-member-constraints `#[feature(member_constraints)]` needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Jun 5, 2025

Applying member constraints can result in overly strong constraints, causing the following test to fail:

fn new_defining_use<'a, F: FnOnce(T) -> &'a (), T>(_: F) {}
fn rpit<'a,  'b: 'b>(x: &'b ()) -> impl Sized + use<'a, 'b> {
    // currently a separate defining use, chooses `'static`
    new_defining_use(rpit::<'a, 'b>);
    x // this defining use needs to be `&'b ()`
}

This is caused by the following code:

// At this point we can pick any member of `choice_regions` and would like to choose
// it to be a small as possible. To avoid potential non-determinism we will pick the
// smallest such choice.
//
// Because universal regions are only partially ordered (i.e, not every two regions are
// comparable), we will ignore any region that doesn't compare to all others when picking
// the minimum choice.
//
// For example, consider `choice_regions = ['static, 'a, 'b, 'c, 'd, 'e]`, where
// `'static: 'a, 'static: 'b, 'a: 'c, 'b: 'c, 'c: 'd, 'c: 'e`.
// `['d, 'e]` are ignored because they do not compare - the same goes for `['a, 'b]`.
let totally_ordered_subset = choice_regions.iter().copied().filter(|&r1| {
choice_regions.iter().all(|&r2| {
self.universal_region_relations.outlives(r1, r2)
|| self.universal_region_relations.outlives(r2, r1)
})
});

This sort of incompleteness is unfortunately required as we can use this to lift otherwise unconstrained regions to 'static, e.g. the following snippet otherwise fails to compile

fn foo<'a, 'b>() -> impl Sized + use<'a, 'b> {
    &()
}

This may become a larger concern as we're working towards the new solver which introduces a significant amount of additional uses of opaques.

@lcnr lcnr added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-member-constraints `#[feature(member_constraints)]` T-types Relevant to the types team, which will review and decide on the PR/issue. labels Jun 5, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-member-constraints `#[feature(member_constraints)]` needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants