rust-lang / rust-lang/rust

Incorrect Type Alias picked in Compilation Error Message

Open
#138,055 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
So, I have a 

`create(filename).expect(format!("This failed {}", &filename));`

and somewhere I had declared `pub use String as ExecId;` in some module somewhere.

As a result, the error I am getting is a misleading compilation error message:

I understand `ExecId` is also String alias but it is unrelated thing.
Current output
error[E0308]: mismatched types
   --> services/src/abc.rs:218:25
    |
218 |                   .expect(format!("This failed {}",
    |  _________________________^
219 | |                                             &filename));
    | |_____________________________________________________________________^ expected `&str`, found `ExecId`
    |
Desired output
error[E0308]: mismatched types
   --> services/src/abc.rs:218:25
    |
218 |                   .expect(format!("This failed {}",
    |  _________________________^
219 | |                                             &filename));
    | |_____________________________________________________________________^ expected `&str`, found `String`
    |
Rationale and extra context

No response

Other cases

Rust Version
rustc 1.83.0 (90b35a623 2024-11-26) (Homebrew)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: aarch64-apple-darwin
release: 1.83.0
LLVM version: 19.1.6
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic using the example in services/src/abc.rs with rustc 1.83.0, focusing on how the compiler chooses names for aliased types in the mismatched-types message. Done means the same case reports String rather than the unrelated ExecId alias, with regression coverage for this behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.