Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5857836

Browse files
committed
Fix preorder_expr skipping the else block of let-else statements
Fixes exit/yield points not getting highlighted in such blocks for `highlight_related` (rust-lang#14813; and possibly other bugs in features that use `preorder_expr`).
1 parent 54129fa commit 5857836

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

crates/ide-db/src/syntax_helpers/node_ext.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ pub fn preorder_expr(start: &ast::Expr, cb: &mut dyn FnMut(WalkEvent<ast::Expr>)
5252
}
5353
};
5454
if let Some(let_stmt) = node.parent().and_then(ast::LetStmt::cast) {
55-
if Some(node.clone()) != let_stmt.initializer().map(|it| it.syntax().clone()) {
55+
let node = Some(node.clone());
56+
if node != let_stmt.initializer().map(|it| it.syntax().clone())
57+
&& node != let_stmt.let_else().map(|it| it.syntax().clone())
58+
{
5659
// skipping potential const pat expressions in let statements
5760
preorder.skip_subtree();
5861
continue;

crates/ide/src/highlight_related.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,29 @@ pub async$0 fn foo() {
692692
);
693693
}
694694

695+
#[test]
696+
fn test_hl_let_else_yield_points() {
697+
check(
698+
r#"
699+
pub async fn foo() {
700+
// ^^^^^
701+
let x = foo()
702+
.await$0
703+
// ^^^^^
704+
.await;
705+
// ^^^^^
706+
|| { 0.await };
707+
let Some(_) = None else {
708+
foo().await
709+
// ^^^^^
710+
};
711+
(async { 0.await }).await
712+
// ^^^^^
713+
}
714+
"#,
715+
);
716+
}
717+
695718
#[test]
696719
fn test_hl_yield_nested_fn() {
697720
check(
@@ -788,6 +811,26 @@ async fn foo() {
788811
);
789812
}
790813

814+
#[test]
815+
fn test_hl_let_else_exit_points() {
816+
check(
817+
r#"
818+
fn$0 foo() -> u32 {
819+
//^^
820+
let Some(bar) = None else {
821+
return 0;
822+
// ^^^^^^
823+
};
824+
825+
0?;
826+
// ^
827+
0xDEAD_BEEF
828+
// ^^^^^^^^^^^
829+
}
830+
"#,
831+
);
832+
}
833+
791834
#[test]
792835
fn test_hl_prefer_ref_over_tail_exit() {
793836
check(

0 commit comments

Comments
 (0)