mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Fix body selection in while loops
This commit is contained in:
parent
a2cc1d6b7b
commit
87c4a4104d
4 changed files with 34 additions and 3 deletions
|
@ -1245,3 +1245,25 @@ fn test() {
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn while_loop_block_expr_iterable() {
|
||||||
|
check_infer(
|
||||||
|
r#"
|
||||||
|
fn test() {
|
||||||
|
while { true } {
|
||||||
|
let y = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
10..59 '{ ... } }': ()
|
||||||
|
16..57 'while ... }': ()
|
||||||
|
22..30 '{ true }': bool
|
||||||
|
24..28 'true': bool
|
||||||
|
31..57 '{ ... }': ()
|
||||||
|
45..46 'y': i32
|
||||||
|
49..50 '0': i32
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -1035,7 +1035,6 @@ pub struct WhileExpr {
|
||||||
pub(crate) syntax: SyntaxNode,
|
pub(crate) syntax: SyntaxNode,
|
||||||
}
|
}
|
||||||
impl ast::HasAttrs for WhileExpr {}
|
impl ast::HasAttrs for WhileExpr {}
|
||||||
impl ast::HasLoopBody for WhileExpr {}
|
|
||||||
impl WhileExpr {
|
impl WhileExpr {
|
||||||
pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) }
|
pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) }
|
||||||
pub fn condition(&self) -> Option<Expr> { support::child(&self.syntax) }
|
pub fn condition(&self) -> Option<Expr> { support::child(&self.syntax) }
|
||||||
|
|
|
@ -769,6 +769,15 @@ impl ast::HasLoopBody for ast::ForExpr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ast::HasLoopBody for ast::WhileExpr {
|
||||||
|
fn loop_body(&self) -> Option<ast::BlockExpr> {
|
||||||
|
let mut exprs = support::children(self.syntax());
|
||||||
|
let first = exprs.next();
|
||||||
|
let second = exprs.next();
|
||||||
|
second.or(first)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ast::HasAttrs for ast::AnyHasDocComments {}
|
impl ast::HasAttrs for ast::AnyHasDocComments {}
|
||||||
|
|
||||||
impl From<ast::Adt> for ast::Item {
|
impl From<ast::Adt> for ast::Item {
|
||||||
|
|
|
@ -85,8 +85,9 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
|
||||||
.traits
|
.traits
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|trait_name| {
|
.filter(|trait_name| {
|
||||||
// For loops have two expressions so this might collide, therefor manual impl it
|
// Loops have two expressions so this might collide, therefor manual impl it
|
||||||
node.name != "ForExpr" || trait_name.as_str() != "HasLoopBody"
|
node.name != "ForExpr" && node.name != "WhileExpr"
|
||||||
|
|| trait_name.as_str() != "HasLoopBody"
|
||||||
})
|
})
|
||||||
.map(|trait_name| {
|
.map(|trait_name| {
|
||||||
let trait_name = format_ident!("{}", trait_name);
|
let trait_name = format_ident!("{}", trait_name);
|
||||||
|
|
Loading…
Reference in a new issue