@@ -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