Skip to content

List the available field names of a struct instead of reporting "field not found" #42599

Closed
@P-E-Meunier

Description

@P-E-Meunier

Rust errors have improved a lot in this direction over the past year, but this would make it even easier to code without having to look for struct field names in the documentation:

#[derive(Default)]
struct A { a: (), b: (), c:(), d: (), e: () }

fn main() {
   let a = A::default();
   let b = a.z;
}

At the moment, rustc reports "did you mean a?". It would be more convenient to report "no such field. Available fields are: a, b, c, d, e".

In a codebase in a "prototyping stage", it can be the case that several types have similar field names. Listing the fields would even make it easier to refactor, by highlighting similarities.

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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions