mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 13:05:18 +03:00
Rollup merge of #63227 - jakubadamw:issue-63151, r=estebank
dead_code: Properly inspect fields in struct patterns with type relative paths Closes #63151.
This commit is contained in:
@@ -269,8 +269,9 @@ fn visit_arm(&mut self, arm: &'tcx hir::Arm) {
|
||||
|
||||
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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
Reference in New Issue
Block a user