rust-lang / rust-lang/rust

`apply_member_constraints` is incomplete

Open
#142,073 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-impl-trait A-member-constraints T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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:

https://github.com/rust-lang/rust/blob/425e142686242c7e73f5e32c79071ae266f0f355/compiler/rustc_borrowck/src/region_infer/mod.rs#L743-L759

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked apply_member_constraints code in compiler/rustc_borrowck/src/region_infer/mod.rs around lines 743-759. Reproduce both Rust snippets and trace how defining uses choose region constraints; done means the rpit case avoids an overly strong constraint while the unconstrained-region example still does not lift regions to 'static.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.