@@ -2,7 +2,10 @@ 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, 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
+ } ;
6
9
use rustc_ast:: util:: parser:: { PREC_POSTFIX , PREC_PREFIX } ;
7
10
use rustc_data_structures:: fx:: FxIndexMap ;
8
11
use rustc_errors:: Applicability ;
@@ -732,6 +735,19 @@ fn walk_parents<'tcx>(
732
735
Some ( ty_auto_deref_stability ( cx, output, precedence) . position_for_result ( cx) )
733
736
} ,
734
737
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
+
735
751
Node :: Expr ( parent) if parent. span . ctxt ( ) == ctxt => match parent. kind {
736
752
ExprKind :: Ret ( _) => {
737
753
let owner_id = cx. tcx . hir ( ) . body_owner ( cx. enclosing_body . unwrap ( ) ) ;
@@ -833,17 +849,6 @@ fn walk_parents<'tcx>(
833
849
}
834
850
} )
835
851
} ,
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
- } ,
847
852
ExprKind :: Field ( child, name) if child. hir_id == e. hir_id => Some ( Position :: FieldAccess ( name. name ) ) ,
848
853
ExprKind :: Unary ( UnOp :: Deref , child) if child. hir_id == e. hir_id => Some ( Position :: Deref ) ,
849
854
ExprKind :: Match ( child, _, MatchSource :: TryDesugar | MatchSource :: AwaitDesugar )
0 commit comments