Skip to content

Better user experience when attempting to call associated functions with dot notation #22692

Closed
@frewsxcv

Description

@frewsxcv

New users might attempt to write something like this, (e.g. if they're coming from Java):

fn main() {
    let _ = String.new();
}

This will not compile since they're not using ::. This is what the compiler outputs when compiling:

~ $ rustc program.rs
program.rs:2:13: 2:19 error: unresolved name `String`
program.rs:2     let _ = String.new();
                         ^~~~~~

I find this error message pretty misleading. It'd be great if there was a lint that would check the available static methods of a struct/enum and if there's one that matches, suggest it instead (in the case above, suggest using String::new()).

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.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions