]> git.lizzy.rs Git - rust.git/commitdiff
new_ret_no_self walk return type to check for self
authorJosh Mcguigan <joshmcg88@gmail.com>
Sat, 20 Oct 2018 00:54:25 +0000 (17:54 -0700)
committerJosh Mcguigan <joshmcg88@gmail.com>
Sat, 20 Oct 2018 00:54:25 +0000 (17:54 -0700)
clippy_lints/src/methods/mod.rs

index 0992067636ed839e25ef6324aaee8ceba2c37e63..f0810c906eff8f86726d970fe5137ccd7261a6d8 100644 (file)
@@ -936,13 +936,15 @@ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, implitem: &'tcx hir::I
         if let hir::ImplItemKind::Method(_, _) = implitem.node {
             let ret_ty = return_ty(cx, implitem.id);
 
-//            println!("ret_ty: {:?}", ret_ty);
-//            println!("ret_ty.sty {:?}", ret_ty.sty);
+            // walk the return type and check for Self (this does not check associated types)
+            for inner_type in ret_ty.walk() {
+                if same_tys(cx, ty, inner_type) { return; }
+            }
 
-            // if return type is impl trait
+            // if return type is impl trait, check the associated types
             if let TyKind::Opaque(def_id, _) = ret_ty.sty {
 
-                // then one of the associated types must be Self
+                // one of the associated types must be Self
                 for predicate in cx.tcx.predicates_of(def_id).predicates.iter() {
                     match predicate {
                         (Predicate::Projection(poly_projection_predicate), _) => {
@@ -958,20 +960,6 @@ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, implitem: &'tcx hir::I
                 }
             }
 
-            // if return type is tuple
-            if let TyKind::Tuple(list) = ret_ty.sty {
-                // then at least one of the types in the tuple must be Self
-                for ret_type in list {
-                    if same_tys(cx, ty, ret_type) { return; }
-                }
-            }
-
-            // if return type is mutable pointer
-            if let TyKind::RawPtr(ty::TypeAndMut{ty: ret_type, ..}) = ret_ty.sty {
-                // then the pointer must point to Self
-                if same_tys(cx, ty, ret_type) { return; }
-            }
-
             if name == "new" && !same_tys(cx, ret_ty, ty) {
                 span_lint(cx,
                           NEW_RET_NO_SELF,