Skip to content

Commit a1b7169

Browse files
Update tests
Unfortunately, we lost some recovery for expressions.
1 parent 13ac5c3 commit a1b7169

27 files changed

+616
-796
lines changed

crates/hir_def/src/body/scope.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,4 +542,26 @@ fn test() {
542542
93,
543543
);
544544
}
545+
546+
#[test]
547+
fn let_chains_can_reference_previous_lets() {
548+
do_check_local_name(
549+
r#"
550+
fn test() {
551+
let foo: Option<i32> = None;
552+
if let Some(spam) = foo && spa$0m > 1 && let Some(spam) = foo && spam > 1 {}
553+
}
554+
"#,
555+
61,
556+
);
557+
do_check_local_name(
558+
r#"
559+
fn test() {
560+
let foo: Option<i32> = None;
561+
if let Some(spam) = foo && spam > 1 && let Some(spam) = foo && sp$0am > 1 {}
562+
}
563+
"#,
564+
100,
565+
);
566+
}
545567
}

crates/hir_ty/src/tests/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,14 @@ fn expr_macro_def_expanded_in_various_places() {
190190
!0..6 '1isize': isize
191191
!0..6 '1isize': isize
192192
!0..6 '1isize': isize
193-
!0..6 '1isize': isize
194193
39..442 '{ ...!(); }': ()
195194
73..94 'spam!(...am!())': {unknown}
196195
100..119 'for _ ...!() {}': ()
197196
104..105 '_': {unknown}
198197
117..119 '{}': ()
199198
124..134 '|| spam!()': || -> isize
200199
140..156 'while ...!() {}': ()
200+
146..153 'spam!()': bool
201201
154..156 '{}': ()
202202
161..174 'break spam!()': !
203203
180..194 'return spam!()': !
@@ -271,14 +271,14 @@ fn expr_macro_rules_expanded_in_various_places() {
271271
!0..6 '1isize': isize
272272
!0..6 '1isize': isize
273273
!0..6 '1isize': isize
274-
!0..6 '1isize': isize
275274
53..456 '{ ...!(); }': ()
276275
87..108 'spam!(...am!())': {unknown}
277276
114..133 'for _ ...!() {}': ()
278277
118..119 '_': {unknown}
279278
131..133 '{}': ()
280279
138..148 '|| spam!()': || -> isize
281280
154..170 'while ...!() {}': ()
281+
160..167 'spam!()': bool
282282
168..170 '{}': ()
283283
175..188 'break spam!()': !
284284
194..208 'return spam!()': !

crates/ide_assists/src/handlers/move_guard.rs

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,31 @@ fn main() {
266266
);
267267
}
268268

269+
#[test]
270+
fn move_let_guard_to_arm_body_works() {
271+
check_assist(
272+
move_guard_to_arm_body,
273+
r#"
274+
fn main() {
275+
match 92 {
276+
x $0if (let 1 = x) => false,
277+
_ => true
278+
}
279+
}
280+
"#,
281+
r#"
282+
fn main() {
283+
match 92 {
284+
x => if (let 1 = x) {
285+
false
286+
},
287+
_ => true
288+
}
289+
}
290+
"#,
291+
);
292+
}
293+
269294
#[test]
270295
fn move_guard_to_arm_body_works_complex_match() {
271296
check_assist(
@@ -426,13 +451,21 @@ fn main() {
426451
}
427452

428453
#[test]
429-
fn move_arm_cond_to_match_guard_if_let_not_works() {
430-
check_assist_not_applicable(
454+
fn move_arm_cond_to_match_guard_if_let_works() {
455+
check_assist(
431456
move_arm_cond_to_match_guard,
432457
r#"
433458
fn main() {
434459
match 92 {
435-
x => if let 62 = x { $0false },
460+
x => if let 62 = x && true { $0false },
461+
_ => true
462+
}
463+
}
464+
"#,
465+
r#"
466+
fn main() {
467+
match 92 {
468+
x if let 62 = x && true => false,
436469
_ => true
437470
}
438471
}
@@ -884,7 +917,7 @@ fn main() {
884917

885918
#[test]
886919
fn move_arm_cond_to_match_guard_elseif_iflet() {
887-
check_assist_not_applicable(
920+
check_assist(
888921
move_arm_cond_to_match_guard,
889922
r#"
890923
fn main() {
@@ -901,9 +934,21 @@ fn main() {
901934
4
902935
},
903936
}
904-
}
905-
"#,
906-
)
937+
}"#,
938+
r#"
939+
fn main() {
940+
match 92 {
941+
3 => 0,
942+
x if x > 10 => 1,
943+
x if x > 5 => 2,
944+
x if let 4 = 4 => {
945+
42;
946+
3
947+
}
948+
x => 4,
949+
}
950+
}"#,
951+
);
907952
}
908953

909954
#[test]

crates/ide_assists/src/handlers/replace_if_let_with_match.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,18 @@ impl VariantData {
381381
)
382382
}
383383

384+
#[test]
385+
fn test_if_let_with_match_let_chain() {
386+
check_assist_not_applicable(
387+
replace_if_let_with_match,
388+
r#"
389+
fn main() {
390+
if $0let true = true && let Some(1) = None {}
391+
}
392+
"#,
393+
)
394+
}
395+
384396
#[test]
385397
fn test_if_let_with_match_basic() {
386398
check_assist(

crates/parser/src/tests/top_entries.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,19 @@ fn expr() {
289289
TopEntryPoint::Expr,
290290
"let _ = 0;",
291291
expect![[r#"
292-
ERROR
293-
LET_KW "let"
294-
WHITESPACE " "
295-
UNDERSCORE "_"
296-
WHITESPACE " "
297-
EQ "="
298-
WHITESPACE " "
299-
INT_NUMBER "0"
300-
SEMICOLON ";"
301-
error 0: expected expression
302-
"#]],
292+
ERROR
293+
LET_EXPR
294+
LET_KW "let"
295+
WHITESPACE " "
296+
WILDCARD_PAT
297+
UNDERSCORE "_"
298+
WHITESPACE " "
299+
EQ "="
300+
WHITESPACE " "
301+
LITERAL
302+
INT_NUMBER "0"
303+
SEMICOLON ";"
304+
"#]],
303305
);
304306
}
305307

crates/parser/test_data/parser/err/0008_item_block_recovery.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ SOURCE_FILE
2929
IF_EXPR
3030
IF_KW "if"
3131
WHITESPACE " "
32-
CONDITION
33-
LITERAL
34-
TRUE_KW "true"
32+
LITERAL
33+
TRUE_KW "true"
3534
WHITESPACE " "
3635
BLOCK_EXPR
3736
STMT_LIST

crates/parser/test_data/parser/err/0019_let_recover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn foo() {
2-
let foo =
2+
let foo = 11
33
let bar = 1;
44
let
55
let baz = 92;

crates/parser/test_data/parser/err/0019_let_recover.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ SOURCE_FILE
2020
IDENT "foo"
2121
WHITESPACE " "
2222
EQ "="
23+
WHITESPACE " "
24+
LITERAL
25+
INT_NUMBER "11"
2326
WHITESPACE "\n "
2427
LET_STMT
2528
LET_KW "let"
@@ -57,9 +60,8 @@ SOURCE_FILE
5760
IF_EXPR
5861
IF_KW "if"
5962
WHITESPACE " "
60-
CONDITION
61-
LITERAL
62-
TRUE_KW "true"
63+
LITERAL
64+
TRUE_KW "true"
6365
WHITESPACE " "
6466
BLOCK_EXPR
6567
STMT_LIST
@@ -73,9 +75,8 @@ SOURCE_FILE
7375
WHILE_EXPR
7476
WHILE_KW "while"
7577
WHITESPACE " "
76-
CONDITION
77-
LITERAL
78-
TRUE_KW "true"
78+
LITERAL
79+
TRUE_KW "true"
7980
WHITESPACE " "
8081
BLOCK_EXPR
8182
STMT_LIST
@@ -95,13 +96,12 @@ SOURCE_FILE
9596
WHITESPACE "\n"
9697
R_CURLY "}"
9798
WHITESPACE "\n"
98-
error 24: expected expression
99-
error 24: expected SEMICOLON
100-
error 49: expected pattern
101-
error 49: expected SEMICOLON
102-
error 75: expected pattern
103-
error 75: expected SEMICOLON
104-
error 98: expected pattern
105-
error 98: expected SEMICOLON
106-
error 124: expected pattern
107-
error 124: expected SEMICOLON
99+
error 27: expected SEMICOLON
100+
error 52: expected pattern
101+
error 52: expected SEMICOLON
102+
error 78: expected pattern
103+
error 78: expected SEMICOLON
104+
error 101: expected pattern
105+
error 101: expected SEMICOLON
106+
error 127: expected pattern
107+
error 127: expected SEMICOLON

0 commit comments

Comments
 (0)