@@ -7,7 +7,7 @@ use clippy_utils::{
7
7
peel_middle_ty_refs,
8
8
} ;
9
9
use core:: mem;
10
- use rustc_ast:: util:: parser:: { PREC_PREFIX , PREC_UNAMBIGUOUS } ;
10
+ use rustc_ast:: util:: parser:: ExprPrecedence ;
11
11
use rustc_data_structures:: fx:: FxIndexMap ;
12
12
use rustc_errors:: Applicability ;
13
13
use rustc_hir:: def_id:: DefId ;
@@ -814,12 +814,13 @@ impl TyCoercionStability {
814
814
| TyKind :: Tup ( _)
815
815
| TyKind :: Path ( _) => Self :: Deref ,
816
816
TyKind :: OpaqueDef ( ..)
817
+ | TyKind :: TraitAscription ( ..)
817
818
| TyKind :: Infer
818
819
| TyKind :: Typeof ( ..)
819
820
| TyKind :: TraitObject ( ..)
820
821
| TyKind :: InferDelegation ( ..)
821
- | TyKind :: AnonAdt ( ..)
822
822
| TyKind :: Err ( _) => Self :: Reborrow ,
823
+ TyKind :: UnsafeBinder ( ..) => Self :: None ,
823
824
} ;
824
825
}
825
826
}
@@ -963,7 +964,7 @@ fn report<'tcx>(
963
964
// expr_str (the suggestion) is never shown if is_final_ufcs is true, since it's
964
965
// `expr.kind == ExprKind::Call`. Therefore, this is, afaik, always unnecessary.
965
966
/*
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 {
967
968
Cow::Owned(format!("({expr_str})"))
968
969
} else {
969
970
expr_str
@@ -999,13 +1000,16 @@ fn report<'tcx>(
999
1000
data. first_expr . span ,
1000
1001
state. msg ,
1001
1002
|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 ) {
1003
1004
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 ( ) ,
1007
1011
} ,
1008
- _ => ( 0 , false ) ,
1012
+ _ => false ,
1009
1013
} ;
1010
1014
let is_in_tuple = matches ! (
1011
1015
get_parent_expr( cx, data. first_expr) ,
@@ -1015,11 +1019,7 @@ fn report<'tcx>(
1015
1019
} )
1016
1020
) ;
1017
1021
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 {
1023
1023
format ! ( "({snip})" )
1024
1024
} else {
1025
1025
snip. into ( )
@@ -1049,16 +1049,16 @@ fn report<'tcx>(
1049
1049
}
1050
1050
}
1051
1051
1052
- let ( prefix, precedence ) = match mutability {
1052
+ let ( prefix, needs_paren ) = match mutability {
1053
1053
Some ( mutability) if !ty. is_ref ( ) => {
1054
1054
let prefix = match mutability {
1055
1055
Mutability :: Not => "&" ,
1056
1056
Mutability :: Mut => "&mut " ,
1057
1057
} ;
1058
- ( prefix, PREC_PREFIX )
1058
+ ( prefix, expr . precedence ( ) < ExprPrecedence :: Prefix )
1059
1059
} ,
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 ) ,
1062
1062
} ;
1063
1063
span_lint_hir_and_then (
1064
1064
cx,
@@ -1070,7 +1070,7 @@ fn report<'tcx>(
1070
1070
let mut app = Applicability :: MachineApplicable ;
1071
1071
let ( snip, snip_is_macro) =
1072
1072
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) {
1074
1074
format ! ( "{prefix}({snip})" )
1075
1075
} else {
1076
1076
format ! ( "{prefix}{snip}" )
@@ -1157,7 +1157,7 @@ impl<'tcx> Dereferencing<'tcx> {
1157
1157
} ,
1158
1158
Some ( parent) if !parent. span . from_expansion ( ) => {
1159
1159
// Double reference might be needed at this point.
1160
- if parent. precedence ( ) == PREC_UNAMBIGUOUS {
1160
+ if parent. precedence ( ) == ExprPrecedence :: Unambiguous {
1161
1161
// Parentheses would be needed here, don't lint.
1162
1162
* outer_pat = None ;
1163
1163
} else {
0 commit comments