@@ -2,7 +2,10 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
22use clippy_utils:: source:: { snippet_with_applicability, snippet_with_context} ;
33use clippy_utils:: sugg:: has_enclosing_paren;
44use clippy_utils:: ty:: { expr_sig, is_copy, peel_mid_ty_refs, ty_sig, variant_of_res} ;
5- use clippy_utils:: { fn_def_id, get_parent_expr, is_lint_allowed, meets_msrv, msrvs, path_to_local, walk_to_expr_usage} ;
5+ use clippy_utils:: {
6+ fn_def_id, get_parent_expr, get_parent_expr_for_hir, is_lint_allowed, meets_msrv, msrvs, path_to_local,
7+ walk_to_expr_usage,
8+ } ;
69use rustc_ast:: util:: parser:: { PREC_POSTFIX , PREC_PREFIX } ;
710use rustc_data_structures:: fx:: FxIndexMap ;
811use rustc_errors:: Applicability ;
@@ -732,6 +735,19 @@ fn walk_parents<'tcx>(
732735 Some ( ty_auto_deref_stability ( cx, output, precedence) . position_for_result ( cx) )
733736 } ,
734737
738+ Node :: ExprField ( field) if field. span . ctxt ( ) == ctxt => match get_parent_expr_for_hir ( cx, field. hir_id ) {
739+ Some ( Expr {
740+ hir_id,
741+ kind : ExprKind :: Struct ( path, ..) ,
742+ ..
743+ } ) => variant_of_res ( cx, cx. qpath_res ( path, * hir_id) )
744+ . and_then ( |variant| variant. fields . iter ( ) . find ( |f| f. name == field. ident . name ) )
745+ . map ( |field_def| {
746+ ty_auto_deref_stability ( cx, cx. tcx . type_of ( field_def. did ) , precedence) . position_for_arg ( )
747+ } ) ,
748+ _ => None ,
749+ } ,
750+
735751 Node :: Expr ( parent) if parent. span . ctxt ( ) == ctxt => match parent. kind {
736752 ExprKind :: Ret ( _) => {
737753 let owner_id = cx. tcx . hir ( ) . body_owner ( cx. enclosing_body . unwrap ( ) ) ;
@@ -833,17 +849,6 @@ fn walk_parents<'tcx>(
833849 }
834850 } )
835851 } ,
836- ExprKind :: Struct ( path, fields, _) => {
837- let variant = variant_of_res ( cx, cx. qpath_res ( path, parent. hir_id ) ) ;
838- fields
839- . iter ( )
840- . find ( |f| f. expr . hir_id == child_id)
841- . zip ( variant)
842- . and_then ( |( field, variant) | variant. fields . iter ( ) . find ( |f| f. name == field. ident . name ) )
843- . map ( |field| {
844- ty_auto_deref_stability ( cx, cx. tcx . type_of ( field. did ) , precedence) . position_for_arg ( )
845- } )
846- } ,
847852 ExprKind :: Field ( child, name) if child. hir_id == e. hir_id => Some ( Position :: FieldAccess ( name. name ) ) ,
848853 ExprKind :: Unary ( UnOp :: Deref , child) if child. hir_id == e. hir_id => Some ( Position :: Deref ) ,
849854 ExprKind :: Match ( child, _, MatchSource :: TryDesugar | MatchSource :: AwaitDesugar )
0 commit comments