Skip to content

Commit 41a2df5

Browse files
authored
Merge pull request #21095 from A4-Tacks/autoderef-skipiter
Fix skipiter not applicable in autoderef
2 parents 32555af + 0234d7c commit 41a2df5

File tree

1 file changed

+37
-3
lines changed
  • src/tools/rust-analyzer/crates/ide-completion/src/completions

1 file changed

+37
-3
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/completions/dot.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ pub(crate) fn complete_dot(
9191
// its return type, so we instead check for `<&Self as IntoIterator>::IntoIter`.
9292
// Does <&receiver_ty as IntoIterator>::IntoIter` exist? Assume `iter` is valid
9393
let iter = receiver_ty
94-
.strip_references()
95-
.add_reference(hir::Mutability::Shared)
96-
.into_iterator_iter(ctx.db)
94+
.autoderef(ctx.db)
95+
.map(|ty| ty.strip_references().add_reference(hir::Mutability::Shared))
96+
.find_map(|ty| ty.into_iterator_iter(ctx.db))
9797
.map(|ty| (ty, SmolStr::new_static("iter()")));
9898
// Does <receiver_ty as IntoIterator>::IntoIter` exist?
9999
let into_iter = || {
@@ -1466,6 +1466,40 @@ fn foo() {
14661466
me into_iter().nth(…) (as Iterator) fn(&mut self, usize) -> Option<<Self as Iterator>::Item>
14671467
"#]],
14681468
);
1469+
check_no_kw(
1470+
r#"
1471+
//- minicore: iterator, deref
1472+
struct Foo;
1473+
impl Foo { fn iter(&self) -> Iter { Iter } }
1474+
impl IntoIterator for &Foo {
1475+
type Item = ();
1476+
type IntoIter = Iter;
1477+
fn into_iter(self) -> Self::IntoIter { Iter }
1478+
}
1479+
struct Ref;
1480+
impl core::ops::Deref for Ref {
1481+
type Target = Foo;
1482+
fn deref(&self) -> &Self::Target { &Foo }
1483+
}
1484+
struct Iter;
1485+
impl Iterator for Iter {
1486+
type Item = ();
1487+
fn next(&mut self) -> Option<Self::Item> { None }
1488+
}
1489+
fn foo() {
1490+
Ref.$0
1491+
}
1492+
"#,
1493+
expect![[r#"
1494+
me deref() (use core::ops::Deref) fn(&self) -> &<Self as Deref>::Target
1495+
me into_iter() (as IntoIterator) fn(self) -> <Self as IntoIterator>::IntoIter
1496+
me iter() fn(&self) -> Iter
1497+
me iter().by_ref() (as Iterator) fn(&mut self) -> &mut Self
1498+
me iter().into_iter() (as IntoIterator) fn(self) -> <Self as IntoIterator>::IntoIter
1499+
me iter().next() (as Iterator) fn(&mut self) -> Option<<Self as Iterator>::Item>
1500+
me iter().nth(…) (as Iterator) fn(&mut self, usize) -> Option<<Self as Iterator>::Item>
1501+
"#]],
1502+
);
14691503
}
14701504

14711505
#[test]

0 commit comments

Comments
 (0)