Skip to content
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

handle global trait bounds defining assoc types #135766

Merged
merged 2 commits into from
Jan 24, 2025

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Jan 20, 2025

This also fixes the compare-mode for

  • tests/ui/coherence/coherent-due-to-fulfill.rs
  • tests/ui/codegen/mono-impossible-2.rs
  • tests/ui/trivial-bounds/trivial-bounds-inconsistent-projection.rs
  • tests/ui/nll/issue-61320-normalize.rs

I first considered the alternative to always prefer where-bounds during normalization, regardless of how the trait goal has been proven by changing fn merge_candidates instead.

TraitGoalProvenVia::Misc => candidates.iter().map(|c| c.result).collect(),

This approach is more restrictive than behavior of the old solver to avoid mismatches between trait and normalization goals. This may be breaking in case the where-bound adds unnecessary region constraints and we currently don't ever try to normalize an associated type. I would like to detect these cases and change the approach to exactly match the old solver if required. I want to minimize cases where attempting to normalize in more places causes code to break.

r? @compiler-errors

@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 Jan 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 20, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@lcnr lcnr changed the title handle global trait bounds defining assoc type handle global trait bounds defining assoc types Jan 20, 2025
@@ -1198,34 +1197,42 @@ where
// We prefer trivial builtin candidates, i.e. builtin impls without any
// nested requirements, over all others. This is a fix for #53123 and
// prevents where-bounds from accidentally extending the lifetime of a
// variable.

This comment was marked as resolved.

// for an example where this is necessary.
for p in goal.param_env.caller_bounds().iter() {
if let ty::ClauseKind::Projection(proj) = p.kind().skip_binder() {
if proj.projection_term.trait_ref(self.cx()) == trait_pred.trait_ref {
Copy link
Member

Choose a reason for hiding this comment

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

structural equality seems sketchy here 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Like, this seems like it will not interact well with HRTBs due to anonymization.

@compiler-errors
Copy link
Member

Also the commit history is weird -- commit named "add where clause" which definitely does not add where clause lol

@lcnr lcnr force-pushed the candidate-assembly-3 branch from 66a3afb to 09b784f Compare January 20, 2025 17:51
@rustbot
Copy link
Collaborator

rustbot commented Jan 20, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 23, 2025

📌 Commit 09b784f 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 Jan 23, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 24, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#135073 (Implement `ByteStr` and `ByteString` types)
 - rust-lang#135492 (Add missing check for async body when suggesting await on futures.)
 - rust-lang#135766 (handle global trait bounds defining assoc types)
 - rust-lang#135880 (Get rid of RunCompiler)
 - rust-lang#135908 (rustc_codegen_llvm: remove outdated asm-to-obj codegen note)
 - rust-lang#135911 (Allow `arena_cache` queries to return `Option<&'tcx T>`)
 - rust-lang#135920 (simplify parse_format::Parser::ws by using next_if)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit dafc861 into rust-lang:master Jan 24, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 24, 2025
@lcnr lcnr deleted the candidate-assembly-3 branch January 28, 2025 11:00
@lcnr lcnr restored the candidate-assembly-3 branch January 30, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants