Skip to content

Confusing error message when accessing non-existing field #14721

Closed
@nwin

Description

@nwin

The snippet

fn main() {
    let foo = "str";
    println!("{}", foo.desc);
}

produces the two error messages

error: attempted access of field `desc` on type `&'static str`, but no field with that name was found
bug.rs:3     println!("{}", foo.desc);
                            ^~~~~~~~
error: cannot determine a type for this bounded type parameter: unconstrained type
bug.rs:3     println!("{}", foo.desc);
                            ^~~~~~~~

that are possibly separated by some notes from the compiler such that the first one is not directly visible.

The problem is, that the second message is absolutely not helpful and leads to confusion if the first one is overlooked. I get why the second message is issued but I don't think that it's relevant since the first error is the sole cause for the second error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions