about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2022-01-05 13:57:45 -0500
committerJason Newcomb <jsnewcomb@pm.me>2022-01-05 17:19:13 -0500
commitd98339d3e002b8b1bddf225e98c3140d7f1cecc7 (patch)
tree48492d3b193b25772f96b33cd5321faddc9ee50e
parent2cc38a23227e743aa24b7656ccbcee768ebef5ac (diff)
downloadrust-d98339d3e002b8b1bddf225e98c3140d7f1cecc7.tar.gz
rust-d98339d3e002b8b1bddf225e98c3140d7f1cecc7.zip
Handle type projections in `iter_not_returning_iterator`
-rw-r--r--clippy_lints/src/iter_not_returning_iterator.rs4
-rw-r--r--tests/ui/iter_not_returning_iterator.rs8
-rw-r--r--tests/ui/iter_not_returning_iterator.stderr2
3 files changed, 13 insertions, 1 deletions
diff --git a/clippy_lints/src/iter_not_returning_iterator.rs b/clippy_lints/src/iter_not_returning_iterator.rs
index 91d3c00039a..017a8a779d9 100644
--- a/clippy_lints/src/iter_not_returning_iterator.rs
+++ b/clippy_lints/src/iter_not_returning_iterator.rs
@@ -67,6 +67,10 @@ impl LateLintPass<'_> for IterNotReturningIterator {
 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)
diff --git a/tests/ui/iter_not_returning_iterator.rs b/tests/ui/iter_not_returning_iterator.rs
index f5ee044576c..2c91e02e842 100644
--- a/tests/ui/iter_not_returning_iterator.rs
+++ b/tests/ui/iter_not_returning_iterator.rs
@@ -44,6 +44,7 @@ impl Iterator for Counter {
     }
 }
 
+// Issue #8225
 trait Iter {
     type I;
     fn iter(&self) -> Self::I;
@@ -56,4 +57,11 @@ impl Iter for () {
     }
 }
 
+struct S;
+impl S {
+    fn iter(&self) -> <() as Iter>::I {
+        ().iter()
+    }
+}
+
 fn main() {}
diff --git a/tests/ui/iter_not_returning_iterator.stderr b/tests/ui/iter_not_returning_iterator.stderr
index ddb2b88d5f9..44f02955836 100644
--- a/tests/ui/iter_not_returning_iterator.stderr
+++ b/tests/ui/iter_not_returning_iterator.stderr
@@ -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;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^