File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
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>(
1176
1176
Some ( res)
1177
1177
} ;
1178
1178
1179
- let is_in_condition = | it : & ast:: Expr | {
1179
+ fn is_in_condition ( it : & ast:: Expr ) -> bool {
1180
1180
( || {
1181
1181
let parent = it. syntax ( ) . parent ( ) ?;
1182
1182
if let Some ( expr) = ast:: WhileExpr :: cast ( parent. clone ( ) ) {
1183
1183
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 ( ) ) {
1185
1185
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 ( ) ) )
1186
1190
} else {
1187
1191
None
1188
1192
}
1189
1193
} ) ( )
1190
1194
. unwrap_or ( false )
1191
- } ;
1195
+ }
1192
1196
1193
1197
let make_path_kind_expr = |expr : ast:: Expr | {
1194
1198
let it = expr. syntax ( ) ;
Original file line number Diff line number Diff line change @@ -2622,3 +2622,13 @@ fn foo() {
2622
2622
"# ] ] ,
2623
2623
) ;
2624
2624
}
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