- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn f<T>(t: &T) -> T {
    t
}Current output
error[E0308]: mismatched types
 --> src/lib.rs:2:5
  |
1 | fn f<T>(t: &T) -> T {
  |      -            - expected `T` because of return type
  |      |
  |      expected this type parameter
2 |     t
  |     ^ expected type parameter `T`, found `&T`
  |
  = note: expected type parameter `_`
                  found reference `&_`
  = note: the caller chooses a type for `T` which can be different from `&T`Desired output
error[E0308]: mismatched types
 --> src/lib.rs:2:5
  |
1 | fn f<T>(t: &T) -> T {
  |      -            - expected `T` because of return type
  |      |
  |      expected this type parameter
2 |     t
  |     ^ expected type parameter `T`, found `&T`
  |
  = note: expected type parameter `_`
                  found reference `&_`Rationale and extra context
The statement "the caller chooses a type for T which can be different from &T" is confusing because T and &T are always different. I think it would be best to supress that note when the types only differ in reference-ness. The message was introduced in #122195.
Other cases
No response
Rust Version
rustc 1.81.0-nightly (3cf924b93 2024-06-15)
binary: rustc
commit-hash: 3cf924b934322fd7b514600a7dc84fc517515346
commit-date: 2024-06-15
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7Anything else?
No response
fmease and jieyouxu
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.