Skip to content

Expected/Found does not point to point where type parameter was inferred #134091

Open
@BoxyUwU

Description

@BoxyUwU

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions