@@ -936,13 +936,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
936
936
if let hir:: ImplItemKind :: Method ( _, _) = implitem. node {
937
937
let ret_ty = return_ty ( cx, implitem. id ) ;
938
938
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
+ }
941
943
942
- // if return type is impl trait
944
+ // if return type is impl trait, check the associated types
943
945
if let TyKind :: Opaque ( def_id, _) = ret_ty. sty {
944
946
945
- // then one of the associated types must be Self
947
+ // one of the associated types must be Self
946
948
for predicate in cx. tcx . predicates_of ( def_id) . predicates . iter ( ) {
947
949
match predicate {
948
950
( Predicate :: Projection ( poly_projection_predicate) , _) => {
@@ -958,20 +960,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
958
960
}
959
961
}
960
962
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
-
975
963
if name == "new" && !same_tys ( cx, ret_ty, ty) {
976
964
span_lint ( cx,
977
965
NEW_RET_NO_SELF ,
0 commit comments