Skip to content

fix: show qualified paths when type names collide in E0308 - #22964

Merged
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
rit3sh-x:fix/22331-qualified-paths-on-type-name-collision
Jul 31, 2026
Merged

fix: show qualified paths when type names collide in E0308#22964
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
rit3sh-x:fix/22331-qualified-paths-on-type-name-collision

Conversation

@rit3sh-x

@rit3sh-x rit3sh-x commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

A type mismatch between two same-named types from different modules currently renders with no usable information:

mod foo { pub struct S; }
mod bar { pub struct S; }

fn test(_: foo::S) {
    test(bar::S);
}

Before: expected S, found S
After: expected foo::S, found bar::S

When both sides of the mismatch render to the same string, they are re-rendered with display_source_code, which resolves module paths via find_path. The extra work only happens when the strings are equal, so the common path is unchanged. If either side has no renderable path, both keep their plain names, half-qualified message would read worse than the current one.

Nesting falls out of the existing recursion, so Option<foo::S> vs Option<bar::S> is covered too.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 30, 2026

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The real fix is to only print the ambiguous paths as fully-qualified, but this is complicated to implement and this PR is a reasonable middle-ground.

View changes since this review

Comment thread crates/ide-diagnostics/src/handlers/type_mismatch.rs Outdated
Comment thread crates/ide-diagnostics/src/handlers/type_mismatch.rs Outdated
@rustbot

This comment has been minimized.

@rit3sh-x
rit3sh-x force-pushed the fix/22331-qualified-paths-on-type-name-collision branch from 378bccb to f467deb Compare July 31, 2026 10:13
@rustbot

rustbot commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

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.

@rit3sh-x
rit3sh-x requested a review from ChayimFriedman2 July 31, 2026 10:14
@rit3sh-x

Copy link
Copy Markdown
Contributor Author

@ChayimFriedman2 I shortened the test suite for this implementation. Let me know if you think anything could be improved or changed.

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ChayimFriedman2
ChayimFriedman2 added this pull request to the merge queue Jul 31, 2026
Merged via the queue into rust-lang:master with commit a4b5ba5 Jul 31, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 31, 2026
@rit3sh-x
rit3sh-x deleted the fix/22331-qualified-paths-on-type-name-collision branch July 31, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants