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

Commit e8ae2d3

Browse files
committed
Auto merge of rust-lang#14848 - bm-w:fix/highlight-let-else-return, r=Veykril
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`).
2 parents e110696 + c0519da commit e8ae2d3

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ 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+
if let_stmt.initializer().map(|it| it.syntax() != &node).unwrap_or(true)
56+
&& let_stmt.let_else().map(|it| it.syntax() != &node).unwrap_or(true)
57+
{
5658
// skipping potential const pat expressions in let statements
5759
preorder.skip_subtree();
5860
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)