@@ -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,36 +1009,58 @@ impl EarlyLintPass for UnusedParens {
9991009 }
10001010
10011011 fn check_ty ( & mut self , cx : & EarlyContext < ' _ > , ty : & ast:: Ty ) {
1002- if let ast:: TyKind :: Paren ( r) = & ty. kind {
1003- match & r. kind {
1004- ast:: TyKind :: TraitObject ( ..) => { }
1005- ast:: TyKind :: BareFn ( b) if b. generic_params . len ( ) > 0 => { }
1006- ast:: TyKind :: ImplTrait ( _, bounds) if bounds. len ( ) > 1 => { }
1007- ast:: TyKind :: Array ( _, len) => {
1008- self . check_unused_delims_expr (
1009- cx,
1010- & len. value ,
1011- UnusedDelimsCtx :: ArrayLenExpr ,
1012- false ,
1013- None ,
1014- None ,
1015- ) ;
1016- }
1017- _ => {
1018- let spans = if let Some ( r) = r. span . find_ancestor_inside ( ty. span ) {
1019- Some ( ( ty. span . with_hi ( r. lo ( ) ) , ty. span . with_lo ( r. hi ( ) ) ) )
1020- } else {
1021- None
1022- } ;
1023- self . emit_unused_delims ( cx, ty. span , spans, "type" , ( false , false ) ) ;
1012+ match & ty. kind {
1013+ ast:: TyKind :: Array ( _, len) => {
1014+ self . check_unused_delims_expr (
1015+ cx,
1016+ & len. value ,
1017+ UnusedDelimsCtx :: ArrayLenExpr ,
1018+ false ,
1019+ None ,
1020+ None ,
1021+ ) ;
1022+ }
1023+ ast:: TyKind :: Paren ( r) => {
1024+ match & r. kind {
1025+ ast:: TyKind :: TraitObject ( ..) => { }
1026+ ast:: TyKind :: BareFn ( b)
1027+ if self . with_self_ty_parens && b. generic_params . len ( ) > 0 => { }
1028+ ast:: TyKind :: ImplTrait ( _, bounds) if bounds. len ( ) > 1 => { }
1029+ _ => {
1030+ let spans = if let Some ( r) = r. span . find_ancestor_inside ( ty. span ) {
1031+ Some ( ( ty. span . with_hi ( r. lo ( ) ) , ty. span . with_lo ( r. hi ( ) ) ) )
1032+ } else {
1033+ None
1034+ } ;
1035+ self . emit_unused_delims ( cx, ty. span , spans, "type" , ( false , false ) ) ;
1036+ }
10241037 }
1038+ self . with_self_ty_parens = false ;
10251039 }
1040+ _ => { }
10261041 }
10271042 }
10281043
10291044 fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & ast:: Item ) {
10301045 <Self as UnusedDelimLint >:: check_item ( self , cx, item)
10311046 }
1047+
1048+ fn enter_where_predicate ( & mut self , _: & EarlyContext < ' _ > , pred : & ast:: WherePredicate ) {
1049+ use rustc_ast:: { WhereBoundPredicate , WherePredicate } ;
1050+ if let WherePredicate :: BoundPredicate ( WhereBoundPredicate {
1051+ bounded_ty,
1052+ bound_generic_params,
1053+ ..
1054+ } ) = pred &&
1055+ let ast:: TyKind :: Paren ( _) = & bounded_ty. kind &&
1056+ bound_generic_params. is_empty ( ) {
1057+ self . with_self_ty_parens = true ;
1058+ }
1059+ }
1060+
1061+ fn exit_where_predicate ( & mut self , _: & EarlyContext < ' _ > , _: & ast:: WherePredicate ) {
1062+ assert ! ( !self . with_self_ty_parens) ;
1063+ }
10321064}
10331065
10341066declare_lint ! {
0 commit comments