Skip to content

Commit

Permalink
Rollup merge of #102455 - nnethercote:WhileTrue-check_expr, r=lqd
Browse files Browse the repository at this point in the history
Use let-chaining in `WhileTrue::check_expr`.

This has been bugging me for a while.

r? `@lqd`
  • Loading branch information
Dylan-DPC authored Sep 29, 2022
2 parents 34f02c3 + 269ff92 commit f4e7094
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,30 +97,28 @@ fn pierce_parens(mut expr: &ast::Expr) -> &ast::Expr {

impl EarlyLintPass for WhileTrue {
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
if let ast::ExprKind::While(cond, _, label) = &e.kind {
if let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind {
if let ast::LitKind::Bool(true) = lit.kind {
if !lit.span.from_expansion() {
let condition_span = e.span.with_hi(cond.span.hi());
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
lint.build(fluent::lint::builtin_while_true)
.span_suggestion_short(
condition_span,
fluent::lint::suggestion,
format!(
"{}loop",
label.map_or_else(String::new, |label| format!(
"{}: ",
label.ident,
))
),
Applicability::MachineApplicable,
)
.emit();
})
}
}
}
if let ast::ExprKind::While(cond, _, label) = &e.kind
&& let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind
&& let ast::LitKind::Bool(true) = lit.kind
&& !lit.span.from_expansion()
{
let condition_span = e.span.with_hi(cond.span.hi());
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
lint.build(fluent::lint::builtin_while_true)
.span_suggestion_short(
condition_span,
fluent::lint::suggestion,
format!(
"{}loop",
label.map_or_else(String::new, |label| format!(
"{}: ",
label.ident,
))
),
Applicability::MachineApplicable,
)
.emit();
})
}
}
}
Expand Down

0 comments on commit f4e7094

Please sign in to comment.