Open
Description
Code
fn foo<'a, T>(b: &'a T) -> &'a T { b }
fn main() {
let f = foo;
f(&String::new());
f(&Vec::new());
}
Current output
error[E0308]: mismatched types
--> src/main.rs:7:7
|
7 | f(&Vec::new());
| - ^^^^^^^^^^^ expected `&String`, found `&Vec<_>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&String`
found reference `&Vec<_>`
note: function defined here
--> src/main.rs:1:4
|
1 | fn foo<'a, T>(b: &'a T) -> &'a T { b }
| ^^^ --------
Desired output
error[E0308]: mismatched types
--> src/main.rs:7:7
|
7 | f(&Vec::new());
| - ^^^^^^^^^^^ expected `&String`, found `&Vec<_>`
| |
| arguments to this function are incorrect
|
= note: expected reference `&String`
found reference `&Vec<_>`
note: function defined here
--> src/main.rs:1:4
|
1 | fn foo<'a, T>(b: &'a T) -> &'a T { b }
| ^^^ --------
note: generic argument was inferred to `String` here
--> src/main.rs:6:7
|
6 | f(&String::new());
| ^^^^^^^^^^^^^
Rationale and extra context
No response
Other cases
Rust Version
playground version:
Build using the Nightly version: 1.85.0-nightly
(2024-12-08 4d669fb34e7db6f3825d)
Anything else?
No response