Use let-chaining in WhileTrue::check_expr
.
This has been bugging me for a while.
This commit is contained in:
parent
307dd938d7
commit
269ff92975
1 changed files with 22 additions and 24 deletions
|
@ -97,30 +97,28 @@ fn pierce_parens(mut expr: &ast::Expr) -> &ast::Expr {
|
||||||
|
|
||||||
impl EarlyLintPass for WhileTrue {
|
impl EarlyLintPass for WhileTrue {
|
||||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
|
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
|
||||||
if let ast::ExprKind::While(cond, _, label) = &e.kind {
|
if let ast::ExprKind::While(cond, _, label) = &e.kind
|
||||||
if let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind {
|
&& let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind
|
||||||
if let ast::LitKind::Bool(true) = lit.kind {
|
&& let ast::LitKind::Bool(true) = lit.kind
|
||||||
if !lit.span.from_expansion() {
|
&& !lit.span.from_expansion()
|
||||||
let condition_span = e.span.with_hi(cond.span.hi());
|
{
|
||||||
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
|
let condition_span = e.span.with_hi(cond.span.hi());
|
||||||
lint.build(fluent::lint::builtin_while_true)
|
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
|
||||||
.span_suggestion_short(
|
lint.build(fluent::lint::builtin_while_true)
|
||||||
condition_span,
|
.span_suggestion_short(
|
||||||
fluent::lint::suggestion,
|
condition_span,
|
||||||
format!(
|
fluent::lint::suggestion,
|
||||||
"{}loop",
|
format!(
|
||||||
label.map_or_else(String::new, |label| format!(
|
"{}loop",
|
||||||
"{}: ",
|
label.map_or_else(String::new, |label| format!(
|
||||||
label.ident,
|
"{}: ",
|
||||||
))
|
label.ident,
|
||||||
),
|
))
|
||||||
Applicability::MachineApplicable,
|
),
|
||||||
)
|
Applicability::MachineApplicable,
|
||||||
.emit();
|
)
|
||||||
})
|
.emit();
|
||||||
}
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue