File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
src/tools/rust-analyzer/crates/ide-completion/src Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -1176,19 +1176,23 @@ fn classify_name_ref<'db>(
11761176 Some ( res)
11771177 } ;
11781178
1179- let is_in_condition = | it : & ast:: Expr | {
1179+ fn is_in_condition ( it : & ast:: Expr ) -> bool {
11801180 ( || {
11811181 let parent = it. syntax ( ) . parent ( ) ?;
11821182 if let Some ( expr) = ast:: WhileExpr :: cast ( parent. clone ( ) ) {
11831183 Some ( expr. condition ( ) ? == * it)
1184- } else if let Some ( expr) = ast:: IfExpr :: cast ( parent) {
1184+ } else if let Some ( expr) = ast:: IfExpr :: cast ( parent. clone ( ) ) {
11851185 Some ( expr. condition ( ) ? == * it)
1186+ } else if let Some ( expr) = ast:: BinExpr :: cast ( parent)
1187+ && expr. op_token ( ) ?. kind ( ) == T ! [ &&]
1188+ {
1189+ Some ( is_in_condition ( & expr. into ( ) ) )
11861190 } else {
11871191 None
11881192 }
11891193 } ) ( )
11901194 . unwrap_or ( false )
1191- } ;
1195+ }
11921196
11931197 let make_path_kind_expr = |expr : ast:: Expr | {
11941198 let it = expr. syntax ( ) ;
Original file line number Diff line number Diff line change @@ -2622,3 +2622,13 @@ fn foo() {
26222622 "# ] ] ,
26232623 ) ;
26242624}
2625+
2626+ #[ test]
2627+ fn let_in_condition ( ) {
2628+ check_edit ( "let" , r#"fn f() { if $0 {} }"# , r#"fn f() { if let $1 = $0 {} }"# ) ;
2629+ }
2630+
2631+ #[ test]
2632+ fn let_in_let_chain ( ) {
2633+ check_edit ( "let" , r#"fn f() { if true && $0 {} }"# , r#"fn f() { if true && let $1 = $0 {} }"# ) ;
2634+ }
You can’t perform that action at this time.
0 commit comments