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 @@ -1171,19 +1171,23 @@ fn classify_name_ref<'db>(
1171
1171
Some ( res)
1172
1172
} ;
1173
1173
1174
- let is_in_condition = | it : & ast:: Expr | {
1174
+ fn is_in_condition ( it : & ast:: Expr ) -> bool {
1175
1175
( || {
1176
1176
let parent = it. syntax ( ) . parent ( ) ?;
1177
1177
if let Some ( expr) = ast:: WhileExpr :: cast ( parent. clone ( ) ) {
1178
1178
Some ( expr. condition ( ) ? == * it)
1179
- } else if let Some ( expr) = ast:: IfExpr :: cast ( parent) {
1179
+ } else if let Some ( expr) = ast:: IfExpr :: cast ( parent. clone ( ) ) {
1180
1180
Some ( expr. condition ( ) ? == * it)
1181
+ } else if let Some ( expr) = ast:: BinExpr :: cast ( parent)
1182
+ && expr. op_token ( ) ?. kind ( ) == T ! [ &&]
1183
+ {
1184
+ Some ( is_in_condition ( & expr. into ( ) ) )
1181
1185
} else {
1182
1186
None
1183
1187
}
1184
1188
} ) ( )
1185
1189
. unwrap_or ( false )
1186
- } ;
1190
+ }
1187
1191
1188
1192
let make_path_kind_expr = |expr : ast:: Expr | {
1189
1193
let it = expr. syntax ( ) ;
Original file line number Diff line number Diff line change @@ -2275,3 +2275,13 @@ fn foo() {
2275
2275
"# ] ] ,
2276
2276
) ;
2277
2277
}
2278
+
2279
+ #[ test]
2280
+ fn let_in_condition ( ) {
2281
+ check_edit ( "let" , r#"fn f() { if $0 {} }"# , r#"fn f() { if let $1 = $0 {} }"# ) ;
2282
+ }
2283
+
2284
+ #[ test]
2285
+ fn let_in_let_chain ( ) {
2286
+ check_edit ( "let" , r#"fn f() { if true && $0 {} }"# , r#"fn f() { if true && let $1 = $0 {} }"# ) ;
2287
+ }
You can’t perform that action at this time.
0 commit comments