Skip to content

Account for type alias projections in E0308 "expected/found" shortening logic#159189

Open
estebank wants to merge 5 commits into
rust-lang:mainfrom
estebank:issue-159043
Open

Account for type alias projections in E0308 "expected/found" shortening logic#159189
estebank wants to merge 5 commits into
rust-lang:mainfrom
estebank:issue-159043

Conversation

@estebank

@estebank estebank commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

When encountering a E0308 error involving ty::Projections, highlight only the sub-parts that are actually relevant:

error[E0308]: mismatched types
  --> tests/ui/associated-types/long-type-E0308.rs:19:5
   |
16 | fn foo<'a, T: FooBar>(value: T) -> <<<T::Wrapper<T> as FooBar>::Assoc as FooBar>::Assoc as FooBar>::Wrapper<<T::Assoc as FooBar>::Assoc> {
   |                                    ----------------------------------------------------------------------------------------------------- expected `<<<... as FooBar>::Assoc as FooBar>::Assoc as FooBar>::Wrapper<...>` because of return type
...
19 |     value.assoc().assoc().assoc().wrap(value.assoc().assoc())
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `really_really_really_long_module::FooBar::Wrapper`, found `really_really_really_long_module::FooBar::Assoc`
   |
   = note: expected associated type `<<<<_ as FooBar>::Wrapper<T> as FooBar>::Assoc as FooBar>::Assoc as FooBar>::Wrapper<_>`
              found associated type `<<<<_ as FooBar>::Assoc as FooBar>::Assoc as FooBar>::Assoc as FooBar>::Wrapper<_>`
   = note: an associated type was expected, but a different one was found
   = note: the full name for the type has been written to 'long-type-E0308.long-type-5396540309891820670.txt'
   = note: consider using `--verbose` to print the full type name to the console

Partially address #159043. To close that ticket we also need to modify the type shortening logic to allow for a mechanism to keep relevant sub-types as visible when possible, we need to expand this logic to account for other ty::Aliases, and deduplicate some of the existing highlighting logic.

r? @chenyukang

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 12, 2026
@rust-log-analyzer

This comment has been minimized.

@estebank estebank marked this pull request as ready for review July 12, 2026 20:29
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 12, 2026
Comment thread compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs Outdated
Comment thread compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs
estebank added 5 commits July 13, 2026 19:45
…ng logic

When encountering a E0308 error involving `ty::Projection`s, highlight only the sub-parts that are actually relevant:

```
error[E0308]: mismatched types
  --> tests/ui/associated-types/long-type-E0308.rs:19:5
   |
16 | fn foo<'a, T: FooBar>(value: T) -> <<<T::Wrapper<T> as FooBar>::Assoc as FooBar>::Assoc as FooBar>::Wrapper<<T::Assoc as FooBar>::Assoc> {
   |                                    ----------------------------------------------------------------------------------------------------- expected `<<<... as FooBar>::Assoc as FooBar>::Assoc as FooBar>::Wrapper<...>` because of return type
...
19 |     value.assoc().assoc().assoc().wrap(value.assoc().assoc())
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `really_really_really_long_module::FooBar::Wrapper`, found `really_really_really_long_module::FooBar::Assoc`
   |
   = note: expected associated type `<<<<_ as FooBar>::Wrapper<T> as FooBar>::Assoc as FooBar>::Assoc as FooBar>::Wrapper<_>`
              found associated type `<<<<_ as FooBar>::Assoc as FooBar>::Assoc as FooBar>::Assoc as FooBar>::Wrapper<_>`
   = note: an associated type was expected, but a different one was found
   = note: the full name for the type has been written to 'long-type-E0308.long-type-5396540309891820670.txt'
   = note: consider using `--verbose` to print the full type name to the console
```
@rustbot

rustbot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants