Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dead_code: Properly inspect fields in struct patterns with type relative paths #63227

Merged
merged 1 commit into from Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/librustc/middle/dead.rs
Expand Up @@ -269,8 +269,9 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {

fn visit_pat(&mut self, pat: &'tcx hir::Pat) {
match pat.node {
PatKind::Struct(hir::QPath::Resolved(_, ref path), ref fields, _) => {
self.handle_field_pattern_match(pat, path.res, fields);
PatKind::Struct(ref path, ref fields, _) => {
let res = self.tables.qpath_res(path, pat.hir_id);
self.handle_field_pattern_match(pat, res, fields);
}
PatKind::Path(ref qpath @ hir::QPath::TypeRelative(..)) => {
let res = self.tables.qpath_res(qpath, pat.hir_id);
Expand Down
@@ -0,0 +1,26 @@
// check-pass

// Regression test for the issue #63151:
// Spurious unused field warning when matching variants under a `Self` scope
//
// This test checks that the `dead_code` lint properly inspects fields
// in struct patterns that use a type relative path.

#![deny(dead_code)]

enum Enum {
Variant { field: usize }
}

impl Enum {
fn read_field(self) -> usize {
match self {
Self::Variant { field } => field
}
}
}

fn main() {
let e = Enum::Variant { field: 42 };
println!("{}", e.read_field());
}