Skip to content

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Aug 11, 2025

See the description in the test file.

This PR fixes a bug introduced by #141333, where we considered non-Param where clauses to be "inherent" for the purpose of method probing, which leads to both changes in method ambiguity (see test) and also import usage linting (and thus fixes #145185).

r? @lcnr

@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 Aug 11, 2025
@@ -1945,6 +1945,29 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
);
(xform_self_ty, xform_ret_ty) =
self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);

if matches!(probe.kind, WhereClauseCandidate(_)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

We could fast path this for the old trait solver, since we expect things to be normalized always.

Copy link
Contributor

@lcnr lcnr Aug 12, 2025

Choose a reason for hiding this comment

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

hm 🤔

so what's going on is:

  • if the normalized self type is a param we assemble_inherent_candidates_from_param
  • this uses fast-reject in an attempt to filter to where-clauses which only apply for the self type
    • doesn't handle unnormalized where-clauses or alias self types

We can't normalize in assembly because it doesn't use a probe, so we instead do it here. This totally makes sense to me, r=me on this impl

Can you add a comment to assemble_inherent_candidates_from_param that we only filter the bounds as an fast-path optimization and we properly reject non-param self type where-clauses in consider_probe?

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, move this structurally_normalize_ty above the xform and then use the normalized ty in xform_self_ty? This should avoid some work given that this change seems to actually impact perf in the new solver

Copy link
Member Author

@compiler-errors compiler-errors Aug 24, 2025

Choose a reason for hiding this comment

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

I don't see how moving it would change things for the better here, and it makes the structure kinda worse, so I'm not going to do this. I'm happy to review the change if you'd like to make a follow-up.

Copy link
Member Author

Choose a reason for hiding this comment

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

My theory here is that the perf improvement derives from us pruning candidates with this check that would otherwise need to do unnecessary work below.

Maybe structurally normalizing eagerly here would mean we wouldn't normalize when proving things in the un-pruned (i.e. actually param) candidates, but I didn't want to tangle those changes into this PR.

@compiler-errors
Copy link
Member Author

@bors2 try @rust-timer queue

I also want to crater this since it may cause some code to fail due to new ambiguity and missing imports.

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 11, 2025
Make sure to treat only param where clauses as inherent
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 11, 2025
@rust-bors
Copy link

rust-bors bot commented Aug 11, 2025

☀️ Try build successful (CI)
Build commit: 987a165 (987a165cfab916796a8315782b83ac460a651ce2, parent: fce0e74720d199eb7839fdb51af35ac5226da178)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (987a165): comparison URL.

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

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.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@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.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.9% [-1.6%, -0.1%] 5
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 1.2%, secondary -2.6%)

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

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

Cycles

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)
6.7% [6.2%, 7.1%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.6% [-2.6%, -2.6%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 464.993s -> 463.982s (-0.22%)
Artifact size: 377.36 MiB -> 377.47 MiB (0.03%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 11, 2025
@compiler-errors
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-145262 created and queued.
🤖 Automatically detected try build 987a165
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 11, 2025
@compiler-errors
Copy link
Member Author

0.0% perf regression is definitely important good job perfbot 👍

@theemathas
Copy link
Contributor

This code compiles on 1.89.0. But it doesn't compile on 1.88.0, and doesn't compile with this PR. Is this intended? I don't think the test checks for this case properly.

pub mod module {
    pub trait Trait {
        fn method(&self);
    }
}

// No import of Trait
use std::ops::Deref;

pub fn foo(x: impl Deref<Target: module::Trait>) {
    x.method();
}

@compiler-errors
Copy link
Member Author

compiler-errors commented Aug 12, 2025

This code compiles on 1.89.0. But it doesn't compile on 1.88.0, and doesn't compile with this PR. Is this intended?

Yes, this is intended breakage.

The whole point of this PR is that there was a regression in 1.89 where we were accepting code that we shouldn't have. As a side effect, this regression also affects how we compute the lint for unused imports, but that's kinda the least important part of this PR.

This is the whole point of the crater run I started. I'd like to ensure that nobody is relying on this behavior.

I don't think the test checks for this case properly.

The test I included is effectively equivalent to that one, since they are both originating from the same root cause around how we treat where clauses from param types specially in method selection. Both the test I included and the one you've shared go from fail (1.88) -> pass (1.89) -> fail (this PR).

@traviscross traviscross added T-lang Relevant to the language team and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 12, 2025
@traviscross
Copy link
Contributor

traviscross commented Aug 12, 2025

Given that there was an accidental stabilization here and that we'll be accepting a breaking change to take it back, let's go ahead and nominate for review.

@rustbot labels +I-lang-nominated

It hasn't been out there long, but it is particularly the kind of thing that would be easy for people to unknowingly rely on.

In fact, I'm going to go ahead kick off the proposed FCP because I don't suspect the crater run is going to tell us very much. The release has been out for less than a week. Most of the people who are going to accidentally rely on this probably haven't done so yet1 -- they'll do it after we land this but before we release it and they adopt that release.

@rfcbot fcp merge

Footnotes

  1. And if they have, they probably haven't released it yet.

@rfcbot
Copy link

rfcbot commented Aug 12, 2025

Team member @traviscross 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!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Aug 12, 2025
@rustbot rustbot added the I-lang-nominated Nominated for discussion during a lang team meeting. label Aug 12, 2025
@rfcbot rfcbot added the disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. label Aug 12, 2025
@traviscross traviscross added the needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. label Aug 12, 2025
@rfcbot
Copy link

rfcbot commented Aug 14, 2025

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

@lcnr
Copy link
Contributor

lcnr commented Aug 14, 2025

please also add more tests

use std::ops::Deref;
trait Trait1 {
    fn call_me(&self) {}
}
impl<T> Trait1 for T {}
trait Trait2 {
    fn call_me(&self) {}
}
impl<T> Trait2 for T {}

pub fn foo<T, U>(x: T)
where
    T: Deref<Target = U>,
    U: Trait1,
{
    // This should be ambiguous. The fact that there's an inherent where-bound
    // candidate for `U` should not impact the candidates for `T`
    x.call_me();
}

bors added a commit that referenced this pull request Aug 16, 2025
[BETA] Revert "Use DeepRejectCtxt in assemble_inherent_candidates_from_param"

Fixes #145185.

Backporting this to stable and beta in favor of #145262 (comment).

r? lcnr
bors added a commit that referenced this pull request Aug 16, 2025
[BETA] Revert "Use DeepRejectCtxt in assemble_inherent_candidates_from_param"

Fixes #145185.

Backporting this to stable and beta in favor of #145262 (comment).

r? lcnr
bors added a commit that referenced this pull request Aug 16, 2025
[BETA] Revert "Use DeepRejectCtxt in assemble_inherent_candidates_from_param"

Fixes #145185.

Backporting this to stable and beta in favor of #145262 (comment).

r? lcnr
bors added a commit that referenced this pull request Aug 16, 2025
[BETA] Revert "Use DeepRejectCtxt in assemble_inherent_candidates_from_param"

Fixes #145185.

Backporting this to stable and beta in favor of #145262 (comment).

r? lcnr
@traviscross traviscross added I-lang-radar Items that are on lang's radar and will need eventual work or consideration. and removed I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-0 Lang team prioritization drag level 0.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. labels Aug 20, 2025
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Aug 24, 2025
@rfcbot
Copy link

rfcbot commented Aug 24, 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.

@rustbot
Copy link
Collaborator

rustbot commented Aug 24, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Aug 24, 2025

📌 Commit c2b9a8a has been approved by lcnr

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 24, 2025
@bors
Copy link
Collaborator

bors commented Aug 24, 2025

⌛ Testing commit c2b9a8a with merge a1dbb44...

@bors
Copy link
Collaborator

bors commented Aug 25, 2025

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing a1dbb44 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 25, 2025
@bors bors merged commit a1dbb44 into rust-lang:master Aug 25, 2025
11 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 25, 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 809200e (parent) -> a1dbb44 (this PR)

Test differences

Show 16 test diffs

Stage 1

  • [ui] tests/ui/methods/rigid-alias-bound-is-not-inherent-2.rs: [missing] -> pass (J1)
  • [ui] tests/ui/methods/rigid-alias-bound-is-not-inherent-3.rs: [missing] -> pass (J1)
  • [ui] tests/ui/methods/rigid-alias-bound-is-not-inherent.rs#current: [missing] -> pass (J1)
  • [ui] tests/ui/methods/rigid-alias-bound-is-not-inherent.rs#next: [missing] -> pass (J1)

Stage 2

  • [ui] tests/ui/methods/rigid-alias-bound-is-not-inherent-2.rs: [missing] -> pass (J0)
  • [ui] tests/ui/methods/rigid-alias-bound-is-not-inherent-3.rs: [missing] -> pass (J0)
  • [ui] tests/ui/methods/rigid-alias-bound-is-not-inherent.rs#current: [missing] -> pass (J0)
  • [ui] tests/ui/methods/rigid-alias-bound-is-not-inherent.rs#next: [missing] -> pass (J0)

Additionally, 8 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 a1dbb443527bd126452875eb5d5860c1d001d761 --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. aarch64-apple: 5727.6s -> 7247.2s (26.5%)
  2. dist-aarch64-msvc: 5439.8s -> 6019.3s (10.7%)
  3. dist-apple-various: 5239.3s -> 4714.1s (-10.0%)
  4. tidy: 182.4s -> 193.4s (6.0%)
  5. dist-x86_64-solaris: 5454.1s -> 5144.4s (-5.7%)
  6. dist-i586-gnu-i586-i686-musl: 5528.1s -> 5814.7s (5.2%)
  7. dist-ohos-x86_64: 4418.9s -> 4190.6s (-5.2%)
  8. aarch64-msvc-1: 6639.5s -> 6975.6s (5.1%)
  9. aarch64-msvc-2: 4726.0s -> 4931.5s (4.3%)
  10. x86_64-mingw-2: 7660.7s -> 7977.2s (4.1%)
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 (a1dbb44): 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)
- - 0
Improvements ✅
(secondary)
-1.4% [-1.6%, -0.9%] 3
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 2.7%)

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

Cycles

Results (primary 2.3%)

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

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

Binary size

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

Bootstrap: 469.654s -> 469.015s (-0.14%)
Artifact size: 378.39 MiB -> 378.43 MiB (0.01%)

@rustbot rustbot removed the perf-regression Performance regression. label Aug 25, 2025
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Aug 28, 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. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. I-types-nominated Nominated for discussion during a types team meeting. merged-by-bors This PR was explicitly merged by bors. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team 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.

Latest rustc tags unused_imports on trait imports spuriously