Skip to content

Commit 88a0204

Browse files
authored
Rollup merge of rust-lang#111300 - Flying-Toast:while_true_span_condition, r=compiler-errors
Emit while_true lint spanning the entire loop condition The lint that suggests `loop {}` instead of `while true {}` has functionality to 'pierce' parenthesis in cases like `while (true) {}`. In these cases, the emitted span only went to the hi of the `true` itself, not spanning the entire loop condition. Before: ``` warning: denote infinite loops with `loop { ... }` --> /tmp/foobar.rs:2:5 | 2 | while ((((((true)))))) {} | ^^^^^^^^^^^^^^^^ help: use `loop` | = note: `#[warn(while_true)]` on by default ``` After: ``` warning: denote infinite loops with `loop { ... }` --> /tmp/foobar.rs:2:5 | 2 | while ((((((true)))))) {} | ^^^^^^^^^^^^^^^^^^^^^^ help: use `loop` | = note: `#[warn(while_true)]` on by default ``` This is especially a problem for rustfix.
2 parents 4e4e5bf + faa797e commit 88a0204

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

compiler/rustc_lint/src/builtin.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ impl EarlyLintPass for WhileTrue {
117117
#[inline]
118118
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
119119
if let ast::ExprKind::While(cond, _, label) = &e.kind
120-
&& let cond = pierce_parens(cond)
121-
&& let ast::ExprKind::Lit(token_lit) = cond.kind
120+
&& let ast::ExprKind::Lit(token_lit) = pierce_parens(cond).kind
122121
&& let token::Lit { kind: token::Bool, symbol: kw::True, .. } = token_lit
123122
&& !cond.span.from_expansion()
124123
{

0 commit comments

Comments
 (0)