Skip to content

Conversation

@jdonszelmann
Copy link
Contributor

@jdonszelmann jdonszelmann commented Oct 18, 2025

Replaces #141926, contains:

  • a commit adding tests that fail before this work
  • the two commits from the previous PR
  • a commit in which these tests are fixed
  • finally, a fixup for an in my opinion rather large regression in diagnostics. It's still not perfect, but better?

I hope this is roughly what you had in mind

Fixes rust-lang/trait-system-refactor-initiative#241 and rust-lang/trait-system-refactor-initiative#238, adding tests for both

r? @lcnr

@rustbot
Copy link
Collaborator

rustbot commented Oct 18, 2025

Some changes occurred to the core trait solver

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

changes to inspect_obligations.rs

cc @compiler-errors, @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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Oct 18, 2025
@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Oct 18, 2025

can you split the old solver custom fulfillment loop out into its own function? named something that makes it clear that its old solver specific too

@lcnr lcnr changed the title Reowork unsizing coercions in the new solver Rework unsizing coercions in the new solver Oct 19, 2025
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

please add comments to the added tests explaining why we've added them and also link to the relevant issues

View changes since this review

fn foo<'a>(x: Box<dyn Trait<'a>>) -> Box<dyn Super<'a>> {
x
//~^ ERROR type annotations needed: cannot satisfy `dyn Trait<'_>: Unsize<dyn Super<'_>>
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why does this one not use revisions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good question 🤔 it should get some :)

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Oct 20, 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.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@jdonszelmann
Copy link
Contributor Author

@rustbot review

&& let ty::Infer(ty::TyVar(vid)) = *pred.self_ty().skip_binder().kind()
&& self.fcx.type_var_is_sized(vid)
{
// Here we detected that an unszing to `dyn Trait` is possible, yay!
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment does not quite seem right 🤔

So what's going on is that we end up with a coercion from ?is_sized to some dyn Trait. The only way that can succeed is via unsizing, so we just unsize here. If we don't know whether the infer var has to be Sized, this could also just end up being an ordinary assignment, in which case trying to coerce would be wrong.

As the error messages when coercing where we shouldn't are worse than the error messages when not coercing when we should, we fall back to equality/subtyping if it's unclear whether we should coerce

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, I think I understand what you mean here, and I think the comment explains that better now

@lcnr
Copy link
Contributor

lcnr commented Oct 27, 2025

pls link to the fixed trait-system-refactor-initiative issues 😁

@jdonszelmann
Copy link
Contributor Author

@rustbot review

@lcnr
Copy link
Contributor

lcnr commented Oct 27, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 27, 2025

📌 Commit 1756622 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 Oct 27, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 27, 2025
…=lcnr

Rework unsizing coercions in the new solver

Replaces rust-lang#141926, contains:

- a commit adding tests that fail before this work
- the two commits from the previous PR
- a commit in which these tests are fixed
- finally, a fixup for an in my opinion rather large regression in diagnostics. It's still not perfect, but better?

I hope this is roughly what you had in mind

Fixes rust-lang/trait-system-refactor-initiative#241 and rust-lang/trait-system-refactor-initiative#238, adding tests for both

r? `@lcnr`
bors added a commit that referenced this pull request Oct 28, 2025
Rollup of 6 pull requests

Successful merges:

 - #147840 (Rework unsizing coercions in the new solver)
 - #148139 (Add `coverage` scope for controlling paths in code coverage)
 - #148154 (Add a mailmap entry)
 - #148158 (ci: loongarch64: use medium code model to avoid relocation overflows)
 - #148172 (rustc-dev-guide subtree update)
 - #148175 (Fix typos: duplicate words in comments)

r? `@ghost`
`@rustbot` modify labels: rollup
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 28, 2025
…=lcnr

Rework unsizing coercions in the new solver

Replaces rust-lang#141926, contains:

- a commit adding tests that fail before this work
- the two commits from the previous PR
- a commit in which these tests are fixed
- finally, a fixup for an in my opinion rather large regression in diagnostics. It's still not perfect, but better?

I hope this is roughly what you had in mind

Fixes rust-lang/trait-system-refactor-initiative#241 and rust-lang/trait-system-refactor-initiative#238, adding tests for both

r? ``@lcnr``
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 28, 2025
…=lcnr

Rework unsizing coercions in the new solver

Replaces rust-lang#141926, contains:

- a commit adding tests that fail before this work
- the two commits from the previous PR
- a commit in which these tests are fixed
- finally, a fixup for an in my opinion rather large regression in diagnostics. It's still not perfect, but better?

I hope this is roughly what you had in mind

Fixes rust-lang/trait-system-refactor-initiative#241 and rust-lang/trait-system-refactor-initiative#238, adding tests for both

r? ```@lcnr```
bors added a commit that referenced this pull request Oct 28, 2025
Rollup of 14 pull requests

Successful merges:

 - #144936 (CFI: Fix types that implement Fn, FnMut, or FnOnce)
 - #147185 (repr(transparent): do not consider repr(C) types to be 1-ZST)
 - #147840 (Rework unsizing coercions in the new solver)
 - #147915 (Update target maintainers android.md)
 - #148013 (1.91.0 release notes)
 - #148044 (compiletest: show output in debug logging)
 - #148057 (tests/ui/sanitizer/hwaddress.rs: Run on aarch64 and remove cgu hack)
 - #148139 (Add `coverage` scope for controlling paths in code coverage)
 - #148154 (Add a mailmap entry)
 - #148158 (ci: loongarch64: use medium code model to avoid relocation overflows)
 - #148166 (Re-enable macro-stepping test for AArch64)
 - #148172 (rustc-dev-guide subtree update)
 - #148175 (Fix typos: duplicate words in comments)
 - #148186 (rustdoc-search: add an integration test for CCI)

Failed merges:

 - #147935 (Add LLVM realtime sanitizer)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 1cf3dc6 into rust-lang:master Oct 28, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Oct 28, 2025
bors added a commit that referenced this pull request Oct 28, 2025
Rollup of 6 pull requests

Successful merges:

 - #147840 (Rework unsizing coercions in the new solver)
 - #148139 (Add `coverage` scope for controlling paths in code coverage)
 - #148154 (Add a mailmap entry)
 - #148158 (ci: loongarch64: use medium code model to avoid relocation overflows)
 - #148172 (rustc-dev-guide subtree update)
 - #148175 (Fix typos: duplicate words in comments)

r? `@ghost`
`@rustbot` modify labels: rollup
rust-timer added a commit that referenced this pull request Oct 28, 2025
Rollup merge of #147840 - jdonszelmann:unsizing-coercions, r=lcnr

Rework unsizing coercions in the new solver

Replaces #141926, contains:

- a commit adding tests that fail before this work
- the two commits from the previous PR
- a commit in which these tests are fixed
- finally, a fixup for an in my opinion rather large regression in diagnostics. It's still not perfect, but better?

I hope this is roughly what you had in mind

Fixes rust-lang/trait-system-refactor-initiative#241 and rust-lang/trait-system-refactor-initiative#238, adding tests for both

r? ````@lcnr````
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.

unsized coercion: select vs trait goal mismatch

7 participants