Skip to content

apply_member_constraints: fix placeholder check #142071

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

Merged
merged 1 commit into from
Aug 15, 2025

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Jun 5, 2025

Checking whether the member region is an existential region from a higher universe is just wrong and I am pretty sure we've added that check by accident as the naming was just horribly confusing before #140466.

I've encountered this issue separately while working on #139587, but feel like it's probably easier to separately FCP this change. This allows the following code to compile

trait Proj<'a> {
    type Assoc;
}
impl<'a, 'b, F: FnOnce() -> &'b ()> Proj<'a> for F {
    type Assoc = ();
}

fn is_proj<F: for<'a> Proj<'a>>(f: F) {}
fn define<'a>() -> impl Sized + use<'a> {
    // This adds a use of `opaque::<'a>` with hidden type `&'unconstrained_b ()`.
    // 'unconstrained_b is an inference variable from a higher universe as it gets
    // created inside of the binder of `F: for<'a> Proj<'a>`. This previously
    // caused us to not apply member constraints. We now do, constraining
    // it to `'a`.
    is_proj(define::<'a>);
    &()
}

fn main() {}

This should not be breaking change, even in theory. Applying member constraints is incomplete in rare circumstances which means that applying them in more cases can cause spurious errors, cc #140569/#142073. However, as we always skipped these member regions in apply_member_constraints the skipped region is guaranteed to cause an error in check_member_constraints later on.

@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 2025

r? @oli-obk

rustbot has assigned @oli-obk.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 5, 2025
@lcnr lcnr added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 5, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Jun 5, 2025

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Jun 5, 2025

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 Jun 5, 2025
@compiler-errors compiler-errors added S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 11, 2025
Comment on lines +22 to +24
// This was unnecessary. It is totally acceptable for member regions
// to be able to name placeholders from higher universes, as long as
// they don't actually do so.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is weird: "It is totally acceptable ... as long as they don't actually do so"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"to be able to" vs "to do"

As in: it's fine for the member region to be an existential region created in a higher universe, as long as it doesn't actually name any placeholder from that higher universe.

How would you restructure this comment? Is the following clearer?

It is totally acceptable for member regions to be able to name placeholders from higher universes, as long as they don't actually refer to a placeholder.

Copy link
Member

@jackh726 jackh726 Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fine for the member region to be an existential region created in a higher universe, as long as it doesn't actually name any placeholder from that higher universe.

This is the most clear

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Jul 28, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Jul 28, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

@nikomatsakis
Copy link
Contributor

@rfcbot reviewed

That example is pretty mind-binding -- the key thing that took me a while to understand was that the universal variable created by proving for<'a> Proj<'a> is not the thing you are talking about which gets constrained by 'a -- it is rather the extra 'b that appears in the self type. OK.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Aug 7, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Aug 7, 2025

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@lcnr
Copy link
Contributor Author

lcnr commented Aug 8, 2025

@rustbot ready

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 8, 2025
@compiler-errors
Copy link
Member

@bors r+ rollup=never

@bors
Copy link
Collaborator

bors commented Aug 14, 2025

📌 Commit cde14e6 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2025
@bors
Copy link
Collaborator

bors commented Aug 14, 2025

⌛ Testing commit cde14e6 with merge a43ff36...

bors added a commit that referenced this pull request Aug 14, 2025
`apply_member_constraints`: fix placeholder check

Checking whether the member region is *an existential region from a higher universe* is just wrong and I am pretty sure we've added that check by accident as the naming was just horribly confusing before #140466.

I've encountered this issue separately while working on #139587, but feel like it's probably easier to separately FCP this change. This allows the following code to compile
```rust
trait Proj<'a> {
    type Assoc;
}
impl<'a, 'b, F: FnOnce() -> &'b ()> Proj<'a> for F {
    type Assoc = ();
}

fn is_proj<F: for<'a> Proj<'a>>(f: F) {}
fn define<'a>() -> impl Sized + use<'a> {
    // This adds a use of `opaque::<'a>` with hidden type `&'unconstrained_b ()`.
    // 'unconstrained_b is an inference variable from a higher universe as it gets
    // created inside of the binder of `F: for<'a> Proj<'a>`. This previously
    // caused us to not apply member constraints. We now do, constraining
    // it to `'a`.
    is_proj(define::<'a>);
    &()
}

fn main() {}
```

This should not be breaking change, even in theory. Applying member constraints is incomplete in rare circumstances which means that applying them in more cases can cause spurious errors, cc #140569/#142073. However, as we always skipped these member regions in `apply_member_constraints` the skipped region is guaranteed to cause an error in `check_member_constraints` later on.
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-mingw-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] windows_targets test:false 0.187
error: could not compile `windows-targets` (lib)

Caused by:
  process didn't exit successfully: `C:\a\rust\rust\build\bootstrap\debug\rustc C:\a\rust\rust\build\bootstrap\debug\rustc --crate-name windows_targets --edition=2021 C:\Users\runneradmin\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\windows-targets-0.52.6\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no --warn=rust_2018_idioms --warn=unexpected_cfgs --warn=missing_docs --check-cfg "cfg(windows_raw_dylib, windows_debugger_visualizer, windows_slim_errors)" --check-cfg cfg(docsrs,test) --check-cfg "cfg(feature, values())" -C metadata=34ce080c45117a20 -C extra-filename=-28bb00e79ea7a2cb --out-dir C:\a\rust\rust\build\bootstrap\x86_64-pc-windows-gnu\debug\deps --target x86_64-pc-windows-gnu -C strip=debuginfo -L dependency=C:\a\rust\rust\build\bootstrap\x86_64-pc-windows-gnu\debug\deps -L dependency=C:\a\rust\rust\build\bootstrap\debug\deps --cap-lints allow --cfg=bootstrap --cfg=windows_raw_dylib -Csymbol-mangling-version=v0 -Zunstable-options -Zmacro-backtrace -Csplit-debuginfo=packed -Alinker-messages -Zunstable-options -Cdebuginfo=2 -Z binary-dep-depinfo` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)
warning: build failed, waiting for other jobs to finish...
[RUSTC-TIMING] version_check test:false 0.361
[RUSTC-TIMING] build_script_build test:false 0.430
[RUSTC-TIMING] windows_sys test:false 3.371
Build completed unsuccessfully in 0:03:04

@bors
Copy link
Collaborator

bors commented Aug 14, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 14, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Aug 15, 2025

unrelated

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 15, 2025
@bors
Copy link
Collaborator

bors commented Aug 15, 2025

⌛ Testing commit cde14e6 with merge cd7cbe8...

@bors
Copy link
Collaborator

bors commented Aug 15, 2025

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing cd7cbe8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 15, 2025
@bors bors merged commit cd7cbe8 into rust-lang:master Aug 15, 2025
11 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 15, 2025
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 8b1889c (parent) -> cd7cbe8 (this PR)

Test differences

Show 9 test diffs

Stage 1

  • [ui] tests/ui/nll/member-constraints/non-root-universe-existential-1.rs#current: [missing] -> pass (J0)
  • [ui] tests/ui/nll/member-constraints/non-root-universe-existential-1.rs#next: [missing] -> pass (J0)
  • [ui] tests/ui/nll/member-constraints/non-root-universe-existential-2.rs: [missing] -> pass (J0)

Stage 2

  • [ui] tests/ui/nll/member-constraints/non-root-universe-existential-1.rs#current: [missing] -> pass (J1)
  • [ui] tests/ui/nll/member-constraints/non-root-universe-existential-1.rs#next: [missing] -> pass (J1)
  • [ui] tests/ui/nll/member-constraints/non-root-universe-existential-2.rs: [missing] -> pass (J1)

Additionally, 3 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard cd7cbe818e4a66d46fe2df993d1b8518eba8a5cd --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-x86_64-apple: 9726.3s -> 14491.2s (49.0%)
  2. dist-apple-various: 5628.7s -> 7271.1s (29.2%)
  3. dist-aarch64-apple: 7486.2s -> 5803.3s (-22.5%)
  4. pr-check-2: 2718.4s -> 2265.6s (-16.7%)
  5. arm-android: 7025.4s -> 5871.7s (-16.4%)
  6. aarch64-gnu-debug: 5222.7s -> 4410.4s (-15.6%)
  7. dist-x86_64-netbsd: 5598.7s -> 4805.8s (-14.2%)
  8. x86_64-gnu-llvm-20-1: 3777.4s -> 3303.1s (-12.6%)
  9. x86_64-gnu-llvm-19-1: 3774.5s -> 3312.4s (-12.2%)
  10. pr-check-1: 1628.8s -> 1444.1s (-11.3%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (cd7cbe8): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
12.3% [12.3%, 12.3%] 1
Regressions ❌
(secondary)
0.6% [0.2%, 1.8%] 4
Improvements ✅
(primary)
-3.0% [-3.0%, -3.0%] 1
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 1
All ❌✅ (primary) 4.7% [-3.0%, 12.3%] 2

Max RSS (memory usage)

Results (secondary 3.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.6% [3.6%, 3.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (primary -2.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.6% [-2.6%, -2.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.6% [-2.6%, -2.6%] 1

Binary size

Results (primary -0.6%, secondary 0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.9% [0.9%, 0.9%] 1
Improvements ✅
(primary)
-0.6% [-0.6%, -0.6%] 1
Improvements ✅
(secondary)
-0.0% [-0.1%, -0.0%] 4
All ❌✅ (primary) -0.6% [-0.6%, -0.6%] 1

Bootstrap: 470.263s -> 469.562s (-0.15%)
Artifact size: 377.48 MiB -> 377.55 MiB (0.02%)

@Kobzol
Copy link
Member

Kobzol commented Aug 16, 2025

clap_derive and tt_muncher are noise.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Aug 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. T-types Relevant to the types team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.