@@ -936,13 +936,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
936936 if let hir:: ImplItemKind :: Method ( _, _) = implitem. node {
937937 let ret_ty = return_ty ( cx, implitem. id ) ;
938938
939- // println!("ret_ty: {:?}", ret_ty);
940- // println!("ret_ty.sty {:?}", ret_ty.sty);
939+ // walk the return type and check for Self (this does not check associated types)
940+ for inner_type in ret_ty. walk ( ) {
941+ if same_tys ( cx, ty, inner_type) { return ; }
942+ }
941943
942- // if return type is impl trait
944+ // if return type is impl trait, check the associated types
943945 if let TyKind :: Opaque ( def_id, _) = ret_ty. sty {
944946
945- // then one of the associated types must be Self
947+ // one of the associated types must be Self
946948 for predicate in cx. tcx . predicates_of ( def_id) . predicates . iter ( ) {
947949 match predicate {
948950 ( Predicate :: Projection ( poly_projection_predicate) , _) => {
@@ -958,20 +960,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
958960 }
959961 }
960962
961- // if return type is tuple
962- if let TyKind :: Tuple ( list) = ret_ty. sty {
963- // then at least one of the types in the tuple must be Self
964- for ret_type in list {
965- if same_tys ( cx, ty, ret_type) { return ; }
966- }
967- }
968-
969- // if return type is mutable pointer
970- if let TyKind :: RawPtr ( ty:: TypeAndMut { ty : ret_type, ..} ) = ret_ty. sty {
971- // then the pointer must point to Self
972- if same_tys ( cx, ty, ret_type) { return ; }
973- }
974-
975963 if name == "new" && !same_tys ( cx, ret_ty, ty) {
976964 span_lint ( cx,
977965 NEW_RET_NO_SELF ,
0 commit comments