diff options
| author | Flying-Toast <38232168+Flying-Toast@users.noreply.github.com> | 2023-05-06 14:12:00 -0400 |
|---|---|---|
| committer | Flying-Toast <38232168+Flying-Toast@users.noreply.github.com> | 2023-05-06 17:05:53 -0400 |
| commit | faa797e7e7bd75fd7dfd5a08fe8cf7bf82e02fd8 (patch) | |
| tree | 4c2395c22c39c5252c645f4cd2cf25f620d1042e | |
| parent | dd9a7bf848e412c81e3045245acbd5a01641a610 (diff) | |
| download | rust-faa797e7e7bd75fd7dfd5a08fe8cf7bf82e02fd8.tar.gz rust-faa797e7e7bd75fd7dfd5a08fe8cf7bf82e02fd8.zip | |
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
```
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index aeb791901bd..87c77a173b3 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -116,8 +116,7 @@ impl EarlyLintPass for WhileTrue { #[inline] fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) { if let ast::ExprKind::While(cond, _, label) = &e.kind - && let cond = pierce_parens(cond) - && let ast::ExprKind::Lit(token_lit) = cond.kind + && let ast::ExprKind::Lit(token_lit) = pierce_parens(cond).kind && let token::Lit { kind: token::Bool, symbol: kw::True, .. } = token_lit && !cond.span.from_expansion() { |
