From d98339d3e002b8b1bddf225e98c3140d7f1cecc7 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Wed, 5 Jan 2022 13:57:45 -0500 Subject: [PATCH] Handle type projections in `iter_not_returning_iterator` --- clippy_lints/src/iter_not_returning_iterator.rs | 4 ++++ tests/ui/iter_not_returning_iterator.rs | 8 ++++++++ tests/ui/iter_not_returning_iterator.stderr | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) 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; | ^^^^^^^^^^^^^^^^^^^^^^^^^^