mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Support multiline comments and hopefully fix panic
This commit is contained in:
parent
8753e568bf
commit
5614dcb4ea
2 changed files with 17 additions and 4 deletions
|
@ -113,10 +113,10 @@ fn check_if(cx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_starts_with_comment(cx: &EarlyContext<'_>, expr: &ast::Block) -> bool {
|
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.
|
// We trim all opening braces and whitespaces and then check if the next string is a comment.
|
||||||
// Therefore, we check if the first string after that is a comment, i.e. starts with //.
|
let trimmed_block_text =
|
||||||
let trimmed_block_text = snippet_block(cx, expr.span, "..").trim_left().to_owned();
|
snippet_block(cx, expr.span, "..").trim_left_matches(|c: char| c.is_whitespace() || c == '{').to_owned();
|
||||||
trimmed_block_text[1..trimmed_block_text.len()].trim_left().starts_with("//")
|
trimmed_block_text.starts_with("//") || trimmed_block_text.starts_with("/*")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
|
fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
|
||||||
|
|
|
@ -196,4 +196,17 @@ fn main() {
|
||||||
println!("world!")
|
println!("world!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if x == "hello" {
|
||||||
|
/* Not collapsible */
|
||||||
|
if y == "world" {
|
||||||
|
println!("Hello world!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if x == "hello" { /* Not collapsible */
|
||||||
|
if y == "world" {
|
||||||
|
println!("Hello world!");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue