@@ -824,7 +824,17 @@ declare_lint! {
824
824
"`if`, `match`, `while` and `return` do not need parentheses"
825
825
}
826
826
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 ] ) ;
828
838
829
839
impl UnusedDelimLint for UnusedParens {
830
840
const DELIM_STR : & ' static str = "parentheses" ;
@@ -999,20 +1009,22 @@ impl EarlyLintPass for UnusedParens {
999
1009
}
1000
1010
1001
1011
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
+ }
1002
1022
if let ast:: TyKind :: Paren ( r) = & ty. kind {
1003
1023
match & r. kind {
1004
1024
ast:: TyKind :: TraitObject ( ..) => { }
1025
+ ast:: TyKind :: BareFn ( b)
1026
+ if self . with_self_ty_parens && b. generic_params . len ( ) > 0 => { }
1005
1027
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
- }
1016
1028
_ => {
1017
1029
let spans = if let Some ( r) = r. span . find_ancestor_inside ( ty. span ) {
1018
1030
Some ( ( ty. span . with_hi ( r. lo ( ) ) , ty. span . with_lo ( r. hi ( ) ) ) )
@@ -1028,6 +1040,23 @@ impl EarlyLintPass for UnusedParens {
1028
1040
fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & ast:: Item ) {
1029
1041
<Self as UnusedDelimLint >:: check_item ( self , cx, item)
1030
1042
}
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
+ }
1031
1060
}
1032
1061
1033
1062
declare_lint ! {
0 commit comments