]> git.lizzy.rs Git - rust.git/commitdiff
Handle type projections in `iter_not_returning_iterator`
authorJason Newcomb <jsnewcomb@pm.me>
Wed, 5 Jan 2022 18:57:45 +0000 (13:57 -0500)
committerJason Newcomb <jsnewcomb@pm.me>
Wed, 5 Jan 2022 22:19:13 +0000 (17:19 -0500)
clippy_lints/src/iter_not_returning_iterator.rs
tests/ui/iter_not_returning_iterator.rs
tests/ui/iter_not_returning_iterator.stderr

index 91d3c00039a02f5bcc5c862aaaeab400e63ce58e..017a8a779d94290437e3c0655f2803c4888370b4 100644 (file)
@@ -67,6 +67,10 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'tcx>
 fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefId) {
     if sig.decl.implicit_self.has_implicit_self() {
         let ret_ty = cx.tcx.fn_sig(fn_id).skip_binder().output();
+        let ret_ty = cx
+            .tcx
+            .try_normalize_erasing_regions(cx.param_env, ret_ty)
+            .unwrap_or(ret_ty);
         if cx
             .tcx
             .get_diagnostic_item(sym::Iterator)
index f5ee044576c532b44a81660ea64033e4811d83d5..2c91e02e84223cd3257a4b898ac739ac9b675415 100644 (file)
@@ -44,6 +44,7 @@ fn next(&mut self) -> Option<Self::Item> {
     }
 }
 
+// Issue #8225
 trait Iter {
     type I;
     fn iter(&self) -> Self::I;
@@ -56,4 +57,11 @@ fn iter(&self) -> Self::I {
     }
 }
 
+struct S;
+impl S {
+    fn iter(&self) -> <() as Iter>::I {
+        ().iter()
+    }
+}
+
 fn main() {}
index ddb2b88d5f90b60040900560f25f0d843de96cfc..44f0295583695bfadd40376d53fd383c76ad0872 100644 (file)
@@ -13,7 +13,7 @@ LL |     fn iter_mut(&self) -> Counter2 {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: this method is named `iter` but its return type does not implement `Iterator`
-  --> $DIR/iter_not_returning_iterator.rs:49:5
+  --> $DIR/iter_not_returning_iterator.rs:50:5
    |
 LL |     fn iter(&self) -> Self::I;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^