Skip to content

"try using a variant of the expected type" suggesting a peculiar syntax #65494

Closed
@Patryk27

Description

@Patryk27

Hi,

I've got following code:

#[derive(Eq, PartialEq)]
pub struct Foo;

impl Foo {
    fn new() -> Self { Foo }
}

fn main() {
    if None == Foo::new() {
            // ^^^^^^^^^^
            // |
            // expected enum `std::option::Option`, found struct `Foo`
            // help: try using a variant of the expected type: `Some(<Foo>::new())`
    }
}

(playground link)

The suggested <Foo>::new() syntax is valid, but - quite frankly - spooky (and it seems to be this way from the very beginning of this feature). Could it suggest just Foo::new()?

I'd like to tackle this myself, but I'd need at least a hint where to look :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-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