Skip to content

Better suggestion for unknown method #42386

Closed
@Manishearth

Description

@Manishearth
struct Foo;
fn main() {
    Foo::new();
}

(playpen)

gives the error

error: no associated item named `new` found for type `Foo` in the current scope

It's within a function call, and really we should distinguish between "associated function" (or whatever they're called) and "associated item". I understand that all functions are associated items, but for newcomers this error message isn't really helpful because associated items are an intermediate concept. Error messages shouldn't hit intermediate concepts for beginner code.

ideally we would notice the difference between something being used within a call expression and something not being used that way, however that's a bit tricky since in the typechecking code by the time we reach this we only know that it's a path. The "are we checking the callee" info could be propagated, but I'm not sure if it's worth it.

A more straightforward bandaid fix would be to say "function or associated item" if the first character is lowercase, and "associated item" if the first character is uppercase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions