@@ -7,7 +7,7 @@ use clippy_utils::{
77 peel_middle_ty_refs,
88} ;
99use core:: mem;
10- use rustc_ast:: util:: parser:: { PREC_PREFIX , PREC_UNAMBIGUOUS } ;
10+ use rustc_ast:: util:: parser:: ExprPrecedence ;
1111use rustc_data_structures:: fx:: FxIndexMap ;
1212use rustc_errors:: Applicability ;
1313use rustc_hir:: def_id:: DefId ;
@@ -814,12 +814,13 @@ impl TyCoercionStability {
814814 | TyKind :: Tup ( _)
815815 | TyKind :: Path ( _) => Self :: Deref ,
816816 TyKind :: OpaqueDef ( ..)
817+ | TyKind :: TraitAscription ( ..)
817818 | TyKind :: Infer
818819 | TyKind :: Typeof ( ..)
819820 | TyKind :: TraitObject ( ..)
820821 | TyKind :: InferDelegation ( ..)
821- | TyKind :: AnonAdt ( ..)
822822 | TyKind :: Err ( _) => Self :: Reborrow ,
823+ TyKind :: UnsafeBinder ( ..) => Self :: None ,
823824 } ;
824825 }
825826 }
@@ -963,7 +964,7 @@ fn report<'tcx>(
963964 // expr_str (the suggestion) is never shown if is_final_ufcs is true, since it's
964965 // `expr.kind == ExprKind::Call`. Therefore, this is, afaik, always unnecessary.
965966 /*
966- expr_str = if !expr_is_macro_call && is_final_ufcs && expr.precedence() < PREC_PREFIX {
967+ expr_str = if !expr_is_macro_call && is_final_ufcs && expr.precedence() < ExprPrecedence::Prefix {
967968 Cow::Owned(format!("({expr_str})"))
968969 } else {
969970 expr_str
@@ -999,13 +1000,16 @@ fn report<'tcx>(
9991000 data. first_expr . span ,
10001001 state. msg ,
10011002 |diag| {
1002- let ( precedence , calls_field ) = match cx. tcx . parent_hir_node ( data. first_expr . hir_id ) {
1003+ let needs_paren = match cx. tcx . parent_hir_node ( data. first_expr . hir_id ) {
10031004 Node :: Expr ( e) => match e. kind {
1004- ExprKind :: Call ( callee, _) if callee. hir_id != data. first_expr . hir_id => ( 0 , false ) ,
1005- ExprKind :: Call ( ..) => ( PREC_UNAMBIGUOUS , matches ! ( expr. kind, ExprKind :: Field ( ..) ) ) ,
1006- _ => ( e. precedence ( ) , false ) ,
1005+ ExprKind :: Call ( callee, _) if callee. hir_id != data. first_expr . hir_id => false ,
1006+ ExprKind :: Call ( ..) => {
1007+ expr. precedence ( ) < ExprPrecedence :: Unambiguous
1008+ || matches ! ( expr. kind, ExprKind :: Field ( ..) )
1009+ } ,
1010+ _ => expr. precedence ( ) < e. precedence ( ) ,
10071011 } ,
1008- _ => ( 0 , false ) ,
1012+ _ => false ,
10091013 } ;
10101014 let is_in_tuple = matches ! (
10111015 get_parent_expr( cx, data. first_expr) ,
@@ -1015,11 +1019,7 @@ fn report<'tcx>(
10151019 } )
10161020 ) ;
10171021
1018- let sugg = if !snip_is_macro
1019- && ( calls_field || expr. precedence ( ) < precedence)
1020- && !has_enclosing_paren ( & snip)
1021- && !is_in_tuple
1022- {
1022+ let sugg = if !snip_is_macro && needs_paren && !has_enclosing_paren ( & snip) && !is_in_tuple {
10231023 format ! ( "({snip})" )
10241024 } else {
10251025 snip. into ( )
@@ -1049,16 +1049,16 @@ fn report<'tcx>(
10491049 }
10501050 }
10511051
1052- let ( prefix, precedence ) = match mutability {
1052+ let ( prefix, needs_paren ) = match mutability {
10531053 Some ( mutability) if !ty. is_ref ( ) => {
10541054 let prefix = match mutability {
10551055 Mutability :: Not => "&" ,
10561056 Mutability :: Mut => "&mut " ,
10571057 } ;
1058- ( prefix, PREC_PREFIX )
1058+ ( prefix, expr . precedence ( ) < ExprPrecedence :: Prefix )
10591059 } ,
1060- None if !ty. is_ref ( ) && data. adjusted_ty . is_ref ( ) => ( "&" , 0 ) ,
1061- _ => ( "" , 0 ) ,
1060+ None if !ty. is_ref ( ) && data. adjusted_ty . is_ref ( ) => ( "&" , false ) ,
1061+ _ => ( "" , false ) ,
10621062 } ;
10631063 span_lint_hir_and_then (
10641064 cx,
@@ -1070,7 +1070,7 @@ fn report<'tcx>(
10701070 let mut app = Applicability :: MachineApplicable ;
10711071 let ( snip, snip_is_macro) =
10721072 snippet_with_context ( cx, expr. span , data. first_expr . span . ctxt ( ) , ".." , & mut app) ;
1073- let sugg = if !snip_is_macro && expr . precedence ( ) < precedence && !has_enclosing_paren ( & snip) {
1073+ let sugg = if !snip_is_macro && needs_paren && !has_enclosing_paren ( & snip) {
10741074 format ! ( "{prefix}({snip})" )
10751075 } else {
10761076 format ! ( "{prefix}{snip}" )
@@ -1157,7 +1157,7 @@ impl<'tcx> Dereferencing<'tcx> {
11571157 } ,
11581158 Some ( parent) if !parent. span . from_expansion ( ) => {
11591159 // Double reference might be needed at this point.
1160- if parent. precedence ( ) == PREC_UNAMBIGUOUS {
1160+ if parent. precedence ( ) == ExprPrecedence :: Unambiguous {
11611161 // Parentheses would be needed here, don't lint.
11621162 * outer_pat = None ;
11631163 } else {
0 commit comments