Skip to content

No warning for unused struct member if explicitly ignored #26353

Closed
@ghost

Description

The compiler gives no warning for an unused struct member if explicitly ignored.

This code:

struct MyStruct { foo: i32, bar: i32 }

fn main() {
    let my_struct = MyStruct { foo: 2, bar: 3 };
    match my_struct {
        MyStruct { foo, .. } => println!("foo is {}", foo)
    }
}

yields a warning:

<anon>:1:29: 1:37 warning: struct field is never used: `bar`, #[warn(dead_code)] on by default
<anon>:1 struct MyStruct { foo: i32, bar: i32 }
                                     ^~~~~~~~

While this code does not:

struct MyStruct { foo: i32, bar: i32 }

fn main() {
    let my_struct = MyStruct { foo: 2, bar: 3 };
    match my_struct {
        MyStruct { foo, bar: _ } => println!("foo is {}", foo)
    }
}

Meta

rustc --version --verbose:
rustc 1.0.0 (a59de37 2015-05-13) (built 2015-05-14)
binary: rustc
commit-hash: a59de37
commit-date: 2015-05-13
build-date: 2015-05-14
host: x86_64-unknown-linux-gnu
release: 1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions