Skip to content

error message claims struct does not have field that it clearly does have #14541

Closed
@pnkfelix

Description

@pnkfelix

This is one of those bugs where an earlier error is leading to poor error reporting later on in the output. So it should not be considered high priority.

Nonetheless, it would be nice if we could strive for error messages to be sane when considered in isolation, which this example violates:

bug.rs

#![crate_type="lib"]

pub struct vec2 { y: f32, }
pub struct vec3 { y: f32, z: f32, }

pub trait Foo { fn make(self); }

impl Foo for vec2 {
    fn make(self) {
        let vec3{y:_,z:_} = self;
    }
}

Transcript:

% rustc /tmp/bug.rs
/tmp/bug.rs:10:13: 10:26 error: mismatched types: expected `vec2` but found `vec3`
/tmp/bug.rs:10         let vec3{y:_,z:_} = self;
                           ^~~~~~~~~~~~~
/tmp/bug.rs:10:13: 10:26 error: struct `vec3` does not have a field named `z`
/tmp/bug.rs:10         let vec3{y:_,z:_} = self;
                           ^~~~~~~~~~~~~
error: aborting due to 2 previous errors

The issue is that the second message claims that vec3 does not have a field named z, but it clearly does. I could understand this message if it said vec2 does not have a field named z.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions