Skip to content

Commit 900a9d3

Browse files
committed
Update clippy for introduction of Node::ExprField
1 parent 1c70b86 commit 900a9d3

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Diff for: src/tools/clippy/clippy_lints/src/dereference.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
22
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
33
use clippy_utils::sugg::has_enclosing_paren;
44
use clippy_utils::ty::{expr_sig, peel_mid_ty_refs, ty_sig, variant_of_res};
5-
use clippy_utils::{get_parent_expr, is_lint_allowed, path_to_local, walk_to_expr_usage};
5+
use clippy_utils::{get_parent_expr, get_parent_expr_for_hir, is_lint_allowed, path_to_local, walk_to_expr_usage};
66
use rustc_ast::util::parser::{PREC_POSTFIX, PREC_PREFIX};
77
use rustc_data_structures::fx::FxIndexMap;
88
use rustc_errors::Applicability;
@@ -699,6 +699,19 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, &
699699
Some(ty_auto_deref_stability(cx, output, precedence).position_for_result(cx))
700700
},
701701

702+
Node::ExprField(field) if field.span.ctxt() == ctxt => match get_parent_expr_for_hir(cx, field.hir_id) {
703+
Some(Expr {
704+
hir_id,
705+
kind: ExprKind::Struct(path, ..),
706+
..
707+
}) => variant_of_res(cx, cx.qpath_res(path, *hir_id))
708+
.and_then(|variant| variant.fields.iter().find(|f| f.name == field.ident.name))
709+
.map(|field_def| {
710+
ty_auto_deref_stability(cx, cx.tcx.type_of(field_def.did), precedence).position_for_arg()
711+
}),
712+
_ => None,
713+
},
714+
702715
Node::Expr(parent) if parent.span.ctxt() == ctxt => match parent.kind {
703716
ExprKind::Ret(_) => {
704717
let owner_id = cx.tcx.hir().body_owner(cx.enclosing_body.unwrap());
@@ -788,17 +801,6 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, &
788801
}
789802
})
790803
},
791-
ExprKind::Struct(path, fields, _) => {
792-
let variant = variant_of_res(cx, cx.qpath_res(path, parent.hir_id));
793-
fields
794-
.iter()
795-
.find(|f| f.expr.hir_id == child_id)
796-
.zip(variant)
797-
.and_then(|(field, variant)| variant.fields.iter().find(|f| f.name == field.ident.name))
798-
.map(|field| {
799-
ty_auto_deref_stability(cx, cx.tcx.type_of(field.did), precedence).position_for_arg()
800-
})
801-
},
802804
ExprKind::Field(child, name) if child.hir_id == e.hir_id => Some(Position::FieldAccess(name.name)),
803805
ExprKind::Unary(UnOp::Deref, child) if child.hir_id == e.hir_id => Some(Position::Deref),
804806
ExprKind::Match(child, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar)

0 commit comments

Comments
 (0)