Skip to content

Conversation

@lcnr
Copy link
Contributor

@lcnr lcnr commented Sep 18, 2025

This strengthens the leak check to match the old trait solver. The new trait solver now also instantiates higher ranked goals in the same scope as candidate selection, so the leak check in each candidate detects placeholder errors involving this higher ranked goal.

E.g. let's look at tests/ui/higher-ranked/leak-check/leak-check-in-selection-2.rs

trait Trait<T, U> {}
impl<'a> Trait<&'a str, &'a str> for () {}
impl<'a> Trait<&'a str, String> for () {}
fn impls_trait<T: for<'a> Trait<&'a str, U>, U>() {}

fn main() {
    impls_trait::<(), _>();
}

Here proving (): for<'a> Trait<&'a str, ?u> via impl<'a> Trait<&'a str, &'a str> for () equates ?u with &'!a str which results in a leak check error as ?u cannot name 'a. If this leak check error happens while considering candidates we drop the first impl and infer ?u to String. If not, this remains ambiguous.

This behavior is a bit iffy, see the FCP proposal in #119820 for more details on why this current behavior is somewhat undesirable. However, considering placeholders from higher-ranked goals for candidate selection does allow more code to compile and a lot of the code feels like it should compile. This caused us to revert the change of #119820 in #127568.

I originally expected that we can avoid breakage with the new solver differently here, e.g. by considering OR-region constraints. However, doing so is a significant change and I don't have a great idea for how that should work. Matching the old solver behavior for now should not make this cleaner approach any more difficult in the future, so let's just go with what actually allows us to stabilize the new solver for now.

This PR changing the new solver to match the behavior of the old one wrt the leak check. As the new solver is already used by default in coherence, this allows more code to compile, see tests/ui/higher-ranked/leak-check/leak-check-in-selection-7-coherence.rs:

struct W<T, U>(T, U);

trait Trait<T> {}
// using this impl results in a higher-ranked region error.
impl<'a> Trait<W<&'a str, &'a str>> for () {}
impl<'a> Trait<W<&'a str, String>> for () {}

trait NotString {}
impl NotString for &str {}
impl NotString for u32 {}


trait Overlap<U> {}
impl<T: for<'a> Trait<W<&'a str, U>>, U> Overlap<U> for T {}
impl<U: NotString> Overlap<U> for () {}

fn main() {}

This behavior is quite arbitrary and not something I expect users to rely on in practice, however, it should still go through an FCP imo.

r? @BoxyUwU originally implemented by @compiler-errors in #136997. Closes rust-lang/trait-system-refactor-initiative#120.

@rustbot
Copy link
Collaborator

rustbot commented Sep 18, 2025

changes to inspect_obligations.rs

cc @compiler-errors, @lcnr

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Sep 18, 2025
@rustbot

This comment was marked as outdated.

@lcnr

This comment was marked as outdated.

@rustbot rustbot assigned BoxyUwU and unassigned fee1-dead Sep 18, 2025
@lcnr lcnr changed the title instantiate predicate binder without recanonicalizing goal -Znext-solver instantiate predicate binder without recanonicalizing goal Sep 18, 2025
@rustbot

This comment was marked as outdated.

@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 Sep 18, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Sep 18, 2025

@rfcbot fcp merge

@rust-rfcbot
Copy link
Collaborator

rust-rfcbot commented Sep 18, 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.

@rust-rfcbot rust-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 Sep 18, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Sep 18, 2025

@bors rollup=never

@lcnr lcnr added the I-types-nominated Nominated for discussion during a types team meeting. label Sep 18, 2025
@BoxyUwU BoxyUwU added the S-no-work-capacity-tracking Status: Exempted from triagebot work capacity tracking. label Sep 18, 2025
ty::PredicateKind::Ambiguous => {
self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
}
self.enter_forall(kind, |ecx, kind| match kind {
Copy link
Member

Choose a reason for hiding this comment

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

much cleaner, nice :>

@BoxyUwU BoxyUwU 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 Sep 24, 2025
@rust-rfcbot rust-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 Oct 7, 2025
@rust-rfcbot
Copy link
Collaborator

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

@rust-rfcbot rust-rfcbot added the finished-final-comment-period The final comment period is finished for this PR / Issue. label Oct 17, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Oct 20, 2025

@bors try @rust-timer queeu

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 20, 2025
`-Znext-solver` instantiate predicate binder without recanonicalizing goal
@lcnr
Copy link
Contributor Author

lcnr commented Oct 20, 2025

@rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 20, 2025
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#4 [auth] library/ubuntu:pull token for registry-1.docker.io
#4 DONE 0.0s

#3 [internal] load metadata for docker.io/library/ubuntu:25.10
#3 ERROR: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 503 Service Unavailable: <html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>


------
---
   1 | >>> FROM ubuntu:25.10
   2 |     
   3 |     ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to build: failed to solve: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 503 Service Unavailable: <html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>


Command failed. Attempt 2/5:
---
#2 [auth] library/ubuntu:pull token for registry-1.docker.io
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/ubuntu:25.10
#3 ERROR: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 503 Service Unavailable: <html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>


------
---
   1 | >>> FROM ubuntu:25.10
   2 |     
   3 |     ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to build: failed to solve: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 503 Service Unavailable: <html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>


Command failed. Attempt 3/5:
---
#2 [auth] library/ubuntu:pull token for registry-1.docker.io
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/ubuntu:25.10
#3 ERROR: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 503 Service Unavailable: <html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>


------
---
   1 | >>> FROM ubuntu:25.10
   2 |     
   3 |     ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to build: failed to solve: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 503 Service Unavailable: <html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>


Command failed. Attempt 4/5:
---
#2 [auth] library/ubuntu:pull token for registry-1.docker.io
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/ubuntu:25.10
#3 ERROR: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 503 Service Unavailable: <html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>


------
---
   1 | >>> FROM ubuntu:25.10
   2 |     
   3 |     ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to build: failed to solve: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 503 Service Unavailable: <html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>


Command failed. Attempt 5/5:
---
#2 [auth] library/ubuntu:pull token for registry-1.docker.io
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/ubuntu:25.10
#3 ERROR: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 503 Service Unavailable: <html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>


------
---
   1 | >>> FROM ubuntu:25.10
   2 |     
   3 |     ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to build: failed to solve: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 503 Service Unavailable: <html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>


The command has failed after 5 attempts.

@rust-bors
Copy link

rust-bors bot commented Oct 20, 2025

☀️ Try build successful (CI)
Build commit: e5a41b8 (e5a41b8d8a870a9050679fb33fe54ee3e0e7d81d, parent: ebe145eca703c74525d4a38ed8021d575a23fa30)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e5a41b8): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

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)
- - 0
Regressions ❌
(secondary)
0.7% [0.7%, 0.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 3.9%)

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.9% [2.0%, 5.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (secondary 4.4%)

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)
4.4% [4.4%, 4.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 473.415s -> 471.736s (-0.35%)
Artifact size: 388.68 MiB -> 388.69 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 20, 2025
@lcnr lcnr closed this Oct 21, 2025
@lcnr lcnr reopened this Oct 21, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 21, 2025
@BoxyUwU
Copy link
Member

BoxyUwU commented Oct 21, 2025

r=me if CI passes

@lcnr
Copy link
Contributor Author

lcnr commented Oct 21, 2025

@bors r=BoxyUwU

@bors
Copy link
Collaborator

bors commented Oct 21, 2025

📌 Commit 5508b47 has been approved by BoxyUwU

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 Oct 21, 2025
@lcnr lcnr removed the I-types-nominated Nominated for discussion during a types team meeting. label Oct 21, 2025
@bors
Copy link
Collaborator

bors commented Oct 21, 2025

⌛ Testing commit 5508b47 with merge 37ec98f...

@bors
Copy link
Collaborator

bors commented Oct 22, 2025

☀️ Test successful - checks-actions
Approved by: BoxyUwU
Pushing 37ec98f to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 22, 2025
@bors bors merged commit 37ec98f into rust-lang:master Oct 22, 2025
15 of 24 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 22, 2025
@github-actions
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 695857b (parent) -> 37ec98f (this PR)

Test differences

Show 21 test diffs

Stage 1

  • [crashes] tests/crashes/140609.rs: pass -> [missing] (J0)
  • [ui] tests/ui/const-generics/generic_const_exprs/negative-coherence-ice-140609.rs: [missing] -> pass (J0)
  • [ui] tests/ui/higher-ranked/leak-check/leak-check-in-selection-7-coherence.rs: [missing] -> pass (J0)

Stage 2

  • [ui] tests/ui/const-generics/generic_const_exprs/negative-coherence-ice-140609.rs: [missing] -> pass (J1)
  • [ui] tests/ui/higher-ranked/leak-check/leak-check-in-selection-7-coherence.rs: [missing] -> pass (J1)
  • [crashes] tests/crashes/140609.rs: pass -> [missing] (J2)

Additionally, 15 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 37ec98f5d33c0876a9ffa5ee17dc0895659efe37 --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. pr-check-1: 1480.4s -> 1832.4s (23.8%)
  2. dist-x86_64-windows-gnullvm: 5995.1s -> 4855.7s (-19.0%)
  3. aarch64-apple: 9526.3s -> 8042.2s (-15.6%)
  4. x86_64-gnu-debug: 6548.9s -> 7430.9s (13.5%)
  5. dist-ohos-armv7: 4531.6s -> 3944.3s (-13.0%)
  6. i686-gnu-2: 5514.6s -> 6216.3s (12.7%)
  7. x86_64-gnu-gcc: 3052.9s -> 3421.5s (12.1%)
  8. i686-gnu-nopt-1: 7178.1s -> 7998.6s (11.4%)
  9. dist-loongarch64-musl: 5744.1s -> 5164.1s (-10.1%)
  10. dist-powerpc64le-linux-musl: 5848.7s -> 5303.9s (-9.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 (37ec98f): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 1
Improvements ✅
(secondary)
-0.4% [-1.1%, -0.1%] 4
All ❌✅ (primary) -1.1% [-1.1%, -1.1%] 1

Max RSS (memory usage)

Results (primary -0.8%)

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)
-0.8% [-0.8%, -0.8%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.8% [-0.8%, -0.8%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 472.072s -> 472.516s (0.09%)
Artifact size: 388.64 MiB -> 388.62 MiB (-0.01%)

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. S-no-work-capacity-tracking Status: Exempted from triagebot work capacity tracking. 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 WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

higher-ranked goals in trait goal candidate selection

10 participants