Skip to content

Confusing error message due to type parameter name #35030

Closed
@waywardmonkeys

Description

@waywardmonkeys

This code is wrong, but the error message is confusing:

trait Parser<T> {
    fn parse(text: &str) -> Option<T>;
}

impl<bool> Parser<bool> for bool {
    fn parse(text: &str) -> Option<bool> {
        Some(true)
    }
}

fn main() {
    println!("{}", bool::parse("ok").unwrap_or(false));
}

Because I used bool accidentally as a type name when not using the right syntax ... this is pretty confusing:

error: mismatched types [--explain E0308]
 --> <anon>:7:14
7 |>         Some(true)
  |>              ^^^^ expected type parameter, found bool
note: expected type `bool`
note:    found type `bool`

error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions