@@ -103,7 +103,7 @@ mod zst_offset;
103103use bind_instead_of_map:: BindInsteadOfMap ;
104104use clippy_utils:: consts:: { constant, Constant } ;
105105use clippy_utils:: diagnostics:: { span_lint, span_lint_and_help} ;
106- use clippy_utils:: ty:: { contains_adt_constructor , implements_trait, is_copy, is_type_diagnostic_item} ;
106+ use clippy_utils:: ty:: { contains_ty_adt_constructor_opaque , implements_trait, is_copy, is_type_diagnostic_item} ;
107107use clippy_utils:: { contains_return, is_trait_method, iter_input_pats, meets_msrv, msrvs, return_ty} ;
108108use if_chain:: if_chain;
109109use rustc_hir as hir;
@@ -3394,36 +3394,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
33943394 if let hir:: ImplItemKind :: Fn ( _, _) = impl_item. kind {
33953395 let ret_ty = return_ty ( cx, impl_item. hir_id ( ) ) ;
33963396
3397- // walk the return type and check for Self (this does not check associated types)
3398- if let Some ( self_adt) = self_ty. ty_adt_def ( ) {
3399- if contains_adt_constructor ( ret_ty, self_adt) {
3400- return ;
3401- }
3402- } else if ret_ty. contains ( self_ty) {
3397+ if contains_ty_adt_constructor_opaque ( cx, ret_ty, self_ty) {
34033398 return ;
34043399 }
34053400
3406- // if return type is impl trait, check the associated types
3407- if let ty:: Opaque ( def_id, _) = * ret_ty. kind ( ) {
3408- // one of the associated types must be Self
3409- for & ( predicate, _span) in cx. tcx . explicit_item_bounds ( def_id) {
3410- if let ty:: PredicateKind :: Projection ( projection_predicate) = predicate. kind ( ) . skip_binder ( ) {
3411- let assoc_ty = match projection_predicate. term . unpack ( ) {
3412- ty:: TermKind :: Ty ( ty) => ty,
3413- ty:: TermKind :: Const ( _c) => continue ,
3414- } ;
3415- // walk the associated type and check for Self
3416- if let Some ( self_adt) = self_ty. ty_adt_def ( ) {
3417- if contains_adt_constructor ( assoc_ty, self_adt) {
3418- return ;
3419- }
3420- } else if assoc_ty. contains ( self_ty) {
3421- return ;
3422- }
3423- }
3424- }
3425- }
3426-
34273401 if name == "new" && ret_ty != self_ty {
34283402 span_lint (
34293403 cx,
0 commit comments