Skip to content

Commit 78dea24

Browse files
committed
Auto merge of rust-lang#17784 - Young-Flash:block_with_label, r=Veykril
feat: support inlay hint for more expr with label follow up rust-lang/rust-analyzer#17635
2 parents 6825324 + f12aca9 commit 78dea24

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/tools/rust-analyzer/crates/ide/src/inlay_hints/closing_brace.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use hir::{HirDisplay, Semantics};
77
use ide_db::{FileRange, RootDatabase};
88
use span::EditionedFileId;
99
use syntax::{
10-
ast::{self, AstNode, HasName},
10+
ast::{self, AstNode, HasLoopBody, HasName},
1111
match_ast, SyntaxKind, SyntaxNode, T,
1212
};
1313

@@ -57,9 +57,24 @@ pub(super) fn hints(
5757
// the actual number of lines in this case should be the line count of the parent BlockExpr,
5858
// which the `min_lines` config cares about
5959
node = node.parent()?;
60-
let block = label.syntax().parent().and_then(ast::BlockExpr::cast)?;
61-
closing_token = block.stmt_list()?.r_curly_token()?;
60+
61+
let parent = label.syntax().parent()?;
62+
let block;
63+
match_ast! {
64+
match parent {
65+
ast::BlockExpr(block_expr) => {
66+
block = block_expr.stmt_list()?;
67+
},
68+
ast::AnyHasLoopBody(loop_expr) => {
69+
block = loop_expr.loop_body()?.stmt_list()?;
70+
},
71+
_ => return None,
72+
}
73+
}
74+
closing_token = block.r_curly_token()?;
75+
6276
let lifetime = label.lifetime().map_or_else(String::new, |it| it.to_string());
77+
6378
(lifetime, Some(label.syntax().text_range()))
6479
} else if let Some(block) = ast::BlockExpr::cast(node.clone()) {
6580
closing_token = block.stmt_list()?.r_curly_token()?;
@@ -219,6 +234,19 @@ fn test() {
219234
//^ 'do_a
220235
}
221236
//^ 'end
237+
238+
'a: loop {
239+
'b: for i in 0..5 {
240+
'c: while true {
241+
242+
243+
}
244+
//^ 'c
245+
}
246+
//^ 'b
247+
}
248+
//^ 'a
249+
222250
}
223251
//^ fn test
224252
"#,

0 commit comments

Comments
 (0)