Support multiline comments and hopefully fix panic

This commit is contained in:
Lukas Stevens 2018-10-18 18:57:16 +02:00
parent 8753e568bf
commit 5614dcb4ea
2 changed files with 17 additions and 4 deletions

View file

@ -113,10 +113,10 @@ fn check_if(cx: &EarlyContext<'_>, expr: &ast::Expr) {
}
fn block_starts_with_comment(cx: &EarlyContext<'_>, expr: &ast::Block) -> bool {
// The zeroth character in the trimmed block text is "{", which marks the beginning of the block.
// Therefore, we check if the first string after that is a comment, i.e. starts with //.
let trimmed_block_text = snippet_block(cx, expr.span, "..").trim_left().to_owned();
trimmed_block_text[1..trimmed_block_text.len()].trim_left().starts_with("//")
// We trim all opening braces and whitespaces and then check if the next string is a comment.
let trimmed_block_text =
snippet_block(cx, expr.span, "..").trim_left_matches(|c: char| c.is_whitespace() || c == '{').to_owned();
trimmed_block_text.starts_with("//") || trimmed_block_text.starts_with("/*")
}
fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {

View file

@ -196,4 +196,17 @@ fn main() {
println!("world!")
}
}
if x == "hello" {
/* Not collapsible */
if y == "world" {
println!("Hello world!");
}
}
if x == "hello" { /* Not collapsible */
if y == "world" {
println!("Hello world!");
}
}
}