This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +31
-7
lines changed
src/tools/rust-analyzer/crates/ide-completion/src Expand file tree Collapse file tree 4 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -62,21 +62,20 @@ pub(crate) fn complete_expr_path(
6262 in_condition,
6363 incomplete_let,
6464 ref ref_expr_parent,
65+ after_amp,
6566 ref is_func_update,
6667 ref innermost_ret_ty,
6768 ref impl_,
6869 in_match_guard,
6970 ..
7071 } = expr_ctx;
7172
72- let has_raw_token =
73- ref_expr_parent. as_ref ( ) . map ( |it| it. raw_token ( ) . is_some ( ) ) . unwrap_or ( false ) ;
74- let has_const_token =
75- ref_expr_parent. as_ref ( ) . map ( |it| it. const_token ( ) . is_some ( ) ) . unwrap_or ( false ) ;
76- let has_mut_token =
77- ref_expr_parent. as_ref ( ) . map ( |it| it. mut_token ( ) . is_some ( ) ) . unwrap_or ( false ) ;
73+ let ( has_raw_token, has_const_token, has_mut_token) = ref_expr_parent
74+ . as_ref ( )
75+ . map ( |it| ( it. raw_token ( ) . is_some ( ) , it. const_token ( ) . is_some ( ) , it. mut_token ( ) . is_some ( ) ) )
76+ . unwrap_or ( ( false , false , false ) ) ;
7877
79- let wants_raw_token = ref_expr_parent. is_some ( ) && !has_raw_token;
78+ let wants_raw_token = ref_expr_parent. is_some ( ) && !has_raw_token && after_amp ;
8079 let wants_const_token =
8180 ref_expr_parent. is_some ( ) && has_raw_token && !has_const_token && !has_mut_token;
8281 let wants_mut_token = if ref_expr_parent. is_some ( ) {
Original file line number Diff line number Diff line change @@ -146,6 +146,7 @@ pub(crate) struct PathExprCtx {
146146 pub ( crate ) in_condition : bool ,
147147 pub ( crate ) incomplete_let : bool ,
148148 pub ( crate ) ref_expr_parent : Option < ast:: RefExpr > ,
149+ pub ( crate ) after_amp : bool ,
149150 /// The surrounding RecordExpression we are completing a functional update
150151 pub ( crate ) is_func_update : Option < ast:: RecordExpr > ,
151152 pub ( crate ) self_param : Option < hir:: SelfParam > ,
Original file line number Diff line number Diff line change @@ -1151,6 +1151,9 @@ fn classify_name_ref(
11511151 let after_if_expr = after_if_expr ( it. clone ( ) ) ;
11521152 let ref_expr_parent =
11531153 path. as_single_name_ref ( ) . and_then ( |_| it. parent ( ) ) . and_then ( ast:: RefExpr :: cast) ;
1154+ let after_amp = non_trivia_sibling ( it. clone ( ) . into ( ) , Direction :: Prev )
1155+ . map ( |it| it. kind ( ) == SyntaxKind :: AMP )
1156+ . unwrap_or ( false ) ;
11541157 let ( innermost_ret_ty, self_param) = {
11551158 let find_ret_ty = |it : SyntaxNode | {
11561159 if let Some ( item) = ast:: Item :: cast ( it. clone ( ) ) {
@@ -1220,6 +1223,7 @@ fn classify_name_ref(
12201223 after_if_expr,
12211224 in_condition,
12221225 ref_expr_parent,
1226+ after_amp,
12231227 is_func_update,
12241228 innermost_ret_ty,
12251229 self_param,
Original file line number Diff line number Diff line change @@ -522,6 +522,26 @@ fn completes_after_ref_expr() {
522522 kw while
523523 kw while let
524524 "# ] ] ,
525+ ) ;
526+ check (
527+ r#"fn main() { let _ = &mut $0 }"# ,
528+ expect ! [ [ r#"
529+ fn main() fn()
530+ bt u32 u32
531+ kw crate::
532+ kw false
533+ kw for
534+ kw if
535+ kw if let
536+ kw loop
537+ kw match
538+ kw return
539+ kw self::
540+ kw true
541+ kw unsafe
542+ kw while
543+ kw while let
544+ "# ] ] ,
525545 )
526546}
527547
You can’t perform that action at this time.
0 commit comments