Skip to content

Commit faa797e

Browse files
committed
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 ```
1 parent dd9a7bf commit faa797e

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
@@ -116,8 +116,7 @@ impl EarlyLintPass for WhileTrue {
116116
#[inline]
117117
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
118118
if let ast::ExprKind::While(cond, _, label) = &e.kind
119-
&& let cond = pierce_parens(cond)
120-
&& let ast::ExprKind::Lit(token_lit) = cond.kind
119+
&& let ast::ExprKind::Lit(token_lit) = pierce_parens(cond).kind
121120
&& let token::Lit { kind: token::Bool, symbol: kw::True, .. } = token_lit
122121
&& !cond.span.from_expansion()
123122
{

0 commit comments

Comments
 (0)