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 @@ -1171,19 +1171,23 @@ fn classify_name_ref<'db>(
11711171 Some ( res)
11721172 } ;
11731173
1174- let is_in_condition = | it : & ast:: Expr | {
1174+ fn is_in_condition ( it : & ast:: Expr ) -> bool {
11751175 ( || {
11761176 let parent = it. syntax ( ) . parent ( ) ?;
11771177 if let Some ( expr) = ast:: WhileExpr :: cast ( parent. clone ( ) ) {
11781178 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 ( ) ) {
11801180 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 ( ) ) )
11811185 } else {
11821186 None
11831187 }
11841188 } ) ( )
11851189 . unwrap_or ( false )
1186- } ;
1190+ }
11871191
11881192 let make_path_kind_expr = |expr : ast:: Expr | {
11891193 let it = expr. syntax ( ) ;
Original file line number Diff line number Diff line change @@ -2275,3 +2275,13 @@ fn foo() {
22752275 "# ] ] ,
22762276 ) ;
22772277}
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