mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-16 05:56:56 +00:00
Support multiline comments and hopefully fix panic
This commit is contained in:
parent
8753e568bf
commit
5614dcb4ea
@ -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) {
|
||||
|
@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user