@@ -80,6 +80,7 @@ mod needless_character_iteration;
80
80
mod needless_collect;
81
81
mod needless_option_as_deref;
82
82
mod needless_option_take;
83
+ mod new_ret_no_self;
83
84
mod no_effect_replace;
84
85
mod obfuscated_if_else;
85
86
mod ok_expect;
@@ -148,11 +149,9 @@ mod zst_offset;
148
149
149
150
use clippy_config:: Conf ;
150
151
use clippy_utils:: consts:: { ConstEvalCtxt , Constant } ;
151
- use clippy_utils:: diagnostics:: span_lint;
152
152
use clippy_utils:: macros:: FormatArgsStorage ;
153
153
use clippy_utils:: msrvs:: { self , Msrv } ;
154
- use clippy_utils:: ty:: contains_ty_adt_constructor_opaque;
155
- use clippy_utils:: { contains_return, is_trait_method, iter_input_pats, peel_blocks, return_ty, sym} ;
154
+ use clippy_utils:: { contains_return, is_trait_method, iter_input_pats, peel_blocks, sym} ;
156
155
pub use path_ends_with_ext:: DEFAULT_ALLOWED_DOTFILES ;
157
156
use rustc_data_structures:: fx:: FxHashSet ;
158
157
use rustc_hir:: { self as hir, Expr , ExprKind , Node , Stmt , StmtKind , TraitItem , TraitItemKind } ;
@@ -4921,20 +4920,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
4921
4920
) ;
4922
4921
}
4923
4922
4924
- // if this impl block implements a trait, lint in trait definition instead
4925
- if !implements_trait
4926
- && impl_item. ident . name == sym:: new
4927
- && let ret_ty = return_ty ( cx, impl_item. owner_id )
4928
- && ret_ty != self_ty
4929
- && !contains_ty_adt_constructor_opaque ( cx, ret_ty, self_ty)
4930
- {
4931
- span_lint (
4932
- cx,
4933
- NEW_RET_NO_SELF ,
4934
- impl_item. span ,
4935
- "methods called `new` usually return `Self`" ,
4936
- ) ;
4937
- }
4923
+ new_ret_no_self:: check_impl_item ( cx, impl_item, self_ty, implements_trait) ;
4938
4924
}
4939
4925
}
4940
4926
@@ -4966,18 +4952,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
4966
4952
) ;
4967
4953
}
4968
4954
4969
- if item. ident . name == sym:: new
4970
- && let ret_ty = return_ty ( cx, item. owner_id )
4971
- && let self_ty = TraitRef :: identity ( cx. tcx , item. owner_id . to_def_id ( ) ) . self_ty ( )
4972
- && !ret_ty. contains ( self_ty)
4973
- {
4974
- span_lint (
4975
- cx,
4976
- NEW_RET_NO_SELF ,
4977
- item. span ,
4978
- "methods called `new` usually return `Self`" ,
4979
- ) ;
4980
- }
4955
+ new_ret_no_self:: check_trait_item ( cx, item) ;
4981
4956
}
4982
4957
}
4983
4958
}
0 commit comments