Skip to content

Commit d98339d

Browse files
committed
Handle type projections in iter_not_returning_iterator
1 parent 2cc38a2 commit d98339d

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

clippy_lints/src/iter_not_returning_iterator.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ impl LateLintPass<'_> for IterNotReturningIterator {
6767
fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefId) {
6868
if sig.decl.implicit_self.has_implicit_self() {
6969
let ret_ty = cx.tcx.fn_sig(fn_id).skip_binder().output();
70+
let ret_ty = cx
71+
.tcx
72+
.try_normalize_erasing_regions(cx.param_env, ret_ty)
73+
.unwrap_or(ret_ty);
7074
if cx
7175
.tcx
7276
.get_diagnostic_item(sym::Iterator)

tests/ui/iter_not_returning_iterator.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl Iterator for Counter {
4444
}
4545
}
4646

47+
// Issue #8225
4748
trait Iter {
4849
type I;
4950
fn iter(&self) -> Self::I;
@@ -56,4 +57,11 @@ impl Iter for () {
5657
}
5758
}
5859

60+
struct S;
61+
impl S {
62+
fn iter(&self) -> <() as Iter>::I {
63+
().iter()
64+
}
65+
}
66+
5967
fn main() {}

tests/ui/iter_not_returning_iterator.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | fn iter_mut(&self) -> Counter2 {
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

1515
error: this method is named `iter` but its return type does not implement `Iterator`
16-
--> $DIR/iter_not_returning_iterator.rs:49:5
16+
--> $DIR/iter_not_returning_iterator.rs:50:5
1717
|
1818
LL | fn iter(&self) -> Self::I;
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)