@@ -824,7 +824,17 @@ declare_lint! {
824824 "`if`, `match`, `while` and `return` do not need parentheses"
825825}
826826
827- declare_lint_pass ! ( UnusedParens => [ UNUSED_PARENS ] ) ;
827+ pub struct UnusedParens {
828+ with_self_ty_parens : bool ,
829+ }
830+
831+ impl UnusedParens {
832+ pub fn new ( ) -> Self {
833+ Self { with_self_ty_parens : false }
834+ }
835+ }
836+
837+ impl_lint_pass ! ( UnusedParens => [ UNUSED_PARENS ] ) ;
828838
829839impl UnusedDelimLint for UnusedParens {
830840 const DELIM_STR : & ' static str = "parentheses" ;
@@ -999,20 +1009,22 @@ impl EarlyLintPass for UnusedParens {
9991009 }
10001010
10011011 fn check_ty ( & mut self , cx : & EarlyContext < ' _ > , ty : & ast:: Ty ) {
1012+ if let ast:: TyKind :: Array ( _, len) = & ty. kind {
1013+ self . check_unused_delims_expr (
1014+ cx,
1015+ & len. value ,
1016+ UnusedDelimsCtx :: ArrayLenExpr ,
1017+ false ,
1018+ None ,
1019+ None ,
1020+ ) ;
1021+ }
10021022 if let ast:: TyKind :: Paren ( r) = & ty. kind {
10031023 match & r. kind {
10041024 ast:: TyKind :: TraitObject ( ..) => { }
1025+ ast:: TyKind :: BareFn ( b)
1026+ if self . with_self_ty_parens && b. generic_params . len ( ) > 0 => { }
10051027 ast:: TyKind :: ImplTrait ( _, bounds) if bounds. len ( ) > 1 => { }
1006- ast:: TyKind :: Array ( _, len) => {
1007- self . check_unused_delims_expr (
1008- cx,
1009- & len. value ,
1010- UnusedDelimsCtx :: ArrayLenExpr ,
1011- false ,
1012- None ,
1013- None ,
1014- ) ;
1015- }
10161028 _ => {
10171029 let spans = if let Some ( r) = r. span . find_ancestor_inside ( ty. span ) {
10181030 Some ( ( ty. span . with_hi ( r. lo ( ) ) , ty. span . with_lo ( r. hi ( ) ) ) )
@@ -1028,6 +1040,23 @@ impl EarlyLintPass for UnusedParens {
10281040 fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & ast:: Item ) {
10291041 <Self as UnusedDelimLint >:: check_item ( self , cx, item)
10301042 }
1043+
1044+ fn enter_where_predicate ( & mut self , _: & EarlyContext < ' _ > , pred : & ast:: WherePredicate ) {
1045+ use rustc_ast:: { WhereBoundPredicate , WherePredicate } ;
1046+ if let WherePredicate :: BoundPredicate ( WhereBoundPredicate {
1047+ bounded_ty,
1048+ bound_generic_params,
1049+ ..
1050+ } ) = pred &&
1051+ let ast:: TyKind :: Paren ( _) = & bounded_ty. kind &&
1052+ bound_generic_params. is_empty ( ) {
1053+ self . with_self_ty_parens = true ;
1054+ }
1055+ }
1056+
1057+ fn exit_where_predicate ( & mut self , _: & EarlyContext < ' _ > , _: & ast:: WherePredicate ) {
1058+ self . with_self_ty_parens = false ;
1059+ }
10311060}
10321061
10331062declare_lint ! {
0 commit comments