Confusing "the caller chooses a type which can be different" [E308] · Issue #126547 · rust-lang/rust (original) (raw)
Code
fn f(t: &T) -> T { t }
Current output
error[E0308]: mismatched types
--> src/lib.rs:2:5
|
1 | fn f(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 {
| - - 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.7
Anything else?
No response