@@ -103,7 +103,7 @@ mod zst_offset;
103
103
use bind_instead_of_map:: BindInsteadOfMap ;
104
104
use clippy_utils:: consts:: { constant, Constant } ;
105
105
use 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} ;
107
107
use clippy_utils:: { contains_return, is_trait_method, iter_input_pats, meets_msrv, msrvs, return_ty} ;
108
108
use if_chain:: if_chain;
109
109
use rustc_hir as hir;
@@ -3394,36 +3394,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
3394
3394
if let hir:: ImplItemKind :: Fn ( _, _) = impl_item. kind {
3395
3395
let ret_ty = return_ty ( cx, impl_item. hir_id ( ) ) ;
3396
3396
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) {
3403
3398
return ;
3404
3399
}
3405
3400
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
-
3427
3401
if name == "new" && ret_ty != self_ty {
3428
3402
span_lint (
3429
3403
cx,
0 commit comments