@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
2
2
use clippy_utils:: source:: { snippet_with_applicability, snippet_with_context} ;
3
3
use clippy_utils:: sugg:: has_enclosing_paren;
4
4
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} ;
6
6
use rustc_ast:: util:: parser:: { PREC_POSTFIX , PREC_PREFIX } ;
7
7
use rustc_data_structures:: fx:: FxIndexMap ;
8
8
use rustc_errors:: Applicability ;
@@ -699,6 +699,19 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, &
699
699
Some ( ty_auto_deref_stability ( cx, output, precedence) . position_for_result ( cx) )
700
700
} ,
701
701
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
+
702
715
Node :: Expr ( parent) if parent. span . ctxt ( ) == ctxt => match parent. kind {
703
716
ExprKind :: Ret ( _) => {
704
717
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, &
788
801
}
789
802
} )
790
803
} ,
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
- } ,
802
804
ExprKind :: Field ( child, name) if child. hir_id == e. hir_id => Some ( Position :: FieldAccess ( name. name ) ) ,
803
805
ExprKind :: Unary ( UnOp :: Deref , child) if child. hir_id == e. hir_id => Some ( Position :: Deref ) ,
804
806
ExprKind :: Match ( child, _, MatchSource :: TryDesugar | MatchSource :: AwaitDesugar )
0 commit comments