Skip to content

Commit 664cdd2

Browse files
committed
Minor docs improvement
1 parent 548d70f commit 664cdd2

File tree

2 files changed

+17
-16
lines changed
  • src/tools/rust-analyzer/crates

2 files changed

+17
-16
lines changed

src/tools/rust-analyzer/crates/hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4855,6 +4855,7 @@ impl Type {
48554855
self.normalize_trait_assoc_type(db, &[], iterator_item.into())
48564856
}
48574857

4858+
/// Resolves the projection `<Self as IntoIterator>::IntoIter` and returns the resulting type
48584859
pub fn into_iterator_iter(self, db: &dyn HirDatabase) -> Option<Type> {
48594860
let trait_ = db.lang_item(self.env.krate, LangItem::IntoIterIntoIter).and_then(|it| {
48604861
let into_iter_fn = it.as_function()?;

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ pub(crate) fn complete_dot(
3232

3333
// Suggest .await syntax for types that implement Future trait
3434
if let Some(future_output) = receiver_ty.into_future_output(ctx.db) {
35+
let await_str = SmolStr::new_static("await");
3536
let mut item = CompletionItem::new(
3637
CompletionItemKind::Keyword,
3738
ctx.source_range(),
38-
SmolStr::new_static("await"),
39+
await_str.clone(),
3940
ctx.edition,
4041
);
4142
item.detail("expr.await");
@@ -58,17 +59,13 @@ pub(crate) fn complete_dot(
5859
acc,
5960
ctx,
6061
&future_output,
61-
|acc, field, ty| {
62-
acc.add_field(ctx, &dot_access, Some(SmolStr::new_static("await")), field, &ty)
63-
},
64-
|acc, field, ty| {
65-
acc.add_tuple_field(ctx, Some(SmolStr::new_static("await")), field, &ty)
66-
},
62+
|acc, field, ty| acc.add_field(ctx, &dot_access, Some(await_str.clone()), field, &ty),
63+
|acc, field, ty| acc.add_tuple_field(ctx, Some(await_str.clone()), field, &ty),
6764
is_field_access,
6865
is_method_access_with_parens,
6966
);
7067
complete_methods(ctx, &future_output, &traits_in_scope, |func| {
71-
acc.add_method(ctx, &dot_access, func, Some(SmolStr::new_static("await")), None)
68+
acc.add_method(ctx, &dot_access, func, Some(await_str.clone()), None)
7269
});
7370
}
7471

@@ -85,20 +82,23 @@ pub(crate) fn complete_dot(
8582
acc.add_method(ctx, dot_access, func, None, None)
8683
});
8784

85+
// FIXME:
8886
// Checking for the existence of `iter()` is complicated in our setup, because we need to substitute
8987
// its return type, so we instead check for `<&Self as IntoIterator>::IntoIter`.
88+
// Does <&receiver_ty as IntoIterator>::IntoIter` exist? Assume `iter` is valid
9089
let iter = receiver_ty
9190
.strip_references()
9291
.add_reference(hir::Mutability::Shared)
9392
.into_iterator_iter(ctx.db)
94-
.map(|ty| (ty, SmolStr::new_static("iter()")))
95-
.or_else(|| {
96-
receiver_ty
97-
.clone()
98-
.into_iterator_iter(ctx.db)
99-
.map(|ty| (ty, SmolStr::new_static("into_iter()")))
100-
});
101-
if let Some((iter, iter_sym)) = iter {
93+
.map(|ty| (ty, SmolStr::new_static("iter()")));
94+
// Does <receiver_ty as IntoIterator>::IntoIter` exist?
95+
let into_iter = || {
96+
receiver_ty
97+
.clone()
98+
.into_iterator_iter(ctx.db)
99+
.map(|ty| (ty, SmolStr::new_static("into_iter()")))
100+
};
101+
if let Some((iter, iter_sym)) = iter.or_else(into_iter) {
102102
// Skip iterators, e.g. complete `.iter().filter_map()`.
103103
let dot_access_kind = match &dot_access.kind {
104104
DotAccessKind::Field { receiver_is_ambiguous_float_literal: _ } => {

0 commit comments

Comments
 (0)