Skip to content

Unclear error message for E0283 #45453

Closed
Closed
@Riateche

Description

@Riateche

Code:

fn func1<T: Into<String>>(x: i32) {}
fn main() {
    func1(42);
}

Error:

error[E0283]: type annotations required: cannot resolve `_: std::convert::Into<std::string::String>`
 --> src/main.rs:6:5
  |
6 |     func1(42);
  |     ^^^^^
  |
  = note: required by `func1`

error: aborting due to previous error

The error is actually caused by the function declaration (it was not supposed to have generic parameters), but without looking at the function it's impossible to understand the message. The error message should show signature of func1 and say that type annotation is required for T argument of func1.

By the way, is there a reason func1 doesn't trigger a warning by itself? I imagine there may be cases where you want functions with unbound type parameters, but I'm not sure about that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.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