Skip to content

Commit f4e7094

Browse files
authored
Rollup merge of #102455 - nnethercote:WhileTrue-check_expr, r=lqd
Use let-chaining in `WhileTrue::check_expr`. This has been bugging me for a while. r? `@lqd`
2 parents 34f02c3 + 269ff92 commit f4e7094

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

compiler/rustc_lint/src/builtin.rs

+22-24
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,28 @@ fn pierce_parens(mut expr: &ast::Expr) -> &ast::Expr {
9797

9898
impl EarlyLintPass for WhileTrue {
9999
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
100-
if let ast::ExprKind::While(cond, _, label) = &e.kind {
101-
if let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind {
102-
if let ast::LitKind::Bool(true) = lit.kind {
103-
if !lit.span.from_expansion() {
104-
let condition_span = e.span.with_hi(cond.span.hi());
105-
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
106-
lint.build(fluent::lint::builtin_while_true)
107-
.span_suggestion_short(
108-
condition_span,
109-
fluent::lint::suggestion,
110-
format!(
111-
"{}loop",
112-
label.map_or_else(String::new, |label| format!(
113-
"{}: ",
114-
label.ident,
115-
))
116-
),
117-
Applicability::MachineApplicable,
118-
)
119-
.emit();
120-
})
121-
}
122-
}
123-
}
100+
if let ast::ExprKind::While(cond, _, label) = &e.kind
101+
&& let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind
102+
&& let ast::LitKind::Bool(true) = lit.kind
103+
&& !lit.span.from_expansion()
104+
{
105+
let condition_span = e.span.with_hi(cond.span.hi());
106+
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
107+
lint.build(fluent::lint::builtin_while_true)
108+
.span_suggestion_short(
109+
condition_span,
110+
fluent::lint::suggestion,
111+
format!(
112+
"{}loop",
113+
label.map_or_else(String::new, |label| format!(
114+
"{}: ",
115+
label.ident,
116+
))
117+
),
118+
Applicability::MachineApplicable,
119+
)
120+
.emit();
121+
})
124122
}
125123
}
126124
}

0 commit comments

Comments
 (0)