mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
lint: port while true diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
4f7b10f484
commit
588977b350
@ -286,3 +286,6 @@ lint-unused-import-braces = braces around {$node} is unnecessary
|
|||||||
|
|
||||||
lint-unused-allocation = unnecessary allocation, use `&` instead
|
lint-unused-allocation = unnecessary allocation, use `&` instead
|
||||||
lint-unused-allocation-mut = unnecessary allocation, use `&mut` instead
|
lint-unused-allocation-mut = unnecessary allocation, use `&mut` instead
|
||||||
|
|
||||||
|
lint-builtin-while-true = denote infinite loops with `loop {"{"} ... {"}"}`
|
||||||
|
.suggestion = use `loop`
|
||||||
|
@ -31,7 +31,7 @@ use rustc_ast::{self as ast, *};
|
|||||||
use rustc_ast_pretty::pprust::{self, expr_to_string};
|
use rustc_ast_pretty::pprust::{self, expr_to_string};
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_errors::{Applicability, Diagnostic, DiagnosticStyledString, MultiSpan};
|
use rustc_errors::{fluent, Applicability, Diagnostic, DiagnosticStyledString, MultiSpan};
|
||||||
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
|
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
@ -99,13 +99,12 @@ impl EarlyLintPass for WhileTrue {
|
|||||||
if let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind {
|
if let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind {
|
||||||
if let ast::LitKind::Bool(true) = lit.kind {
|
if let ast::LitKind::Bool(true) = lit.kind {
|
||||||
if !lit.span.from_expansion() {
|
if !lit.span.from_expansion() {
|
||||||
let msg = "denote infinite loops with `loop { ... }`";
|
|
||||||
let condition_span = e.span.with_hi(cond.span.hi());
|
let condition_span = e.span.with_hi(cond.span.hi());
|
||||||
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
|
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
|
||||||
lint.build(msg)
|
lint.build(fluent::lint::builtin_while_true)
|
||||||
.span_suggestion_short(
|
.span_suggestion_short(
|
||||||
condition_span,
|
condition_span,
|
||||||
"use `loop`",
|
fluent::lint::suggestion,
|
||||||
format!(
|
format!(
|
||||||
"{}loop",
|
"{}loop",
|
||||||
label.map_or_else(String::new, |label| format!(
|
label.map_or_else(String::new, |label| format!(
|
||||||
|
Loading…
Reference in New Issue
Block a user