Skip to content

Commit 588977b

Browse files
committed
lint: port while true diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
1 parent 4f7b10f commit 588977b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

compiler/rustc_error_messages/locales/en-US/lint.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,6 @@ lint-unused-import-braces = braces around {$node} is unnecessary
286286
287287
lint-unused-allocation = unnecessary allocation, use `&` instead
288288
lint-unused-allocation-mut = unnecessary allocation, use `&mut` instead
289+
290+
lint-builtin-while-true = denote infinite loops with `loop {"{"} ... {"}"}`
291+
.suggestion = use `loop`

compiler/rustc_lint/src/builtin.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_ast::{self as ast, *};
3131
use rustc_ast_pretty::pprust::{self, expr_to_string};
3232
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3333
use rustc_data_structures::stack::ensure_sufficient_stack;
34-
use rustc_errors::{Applicability, Diagnostic, DiagnosticStyledString, MultiSpan};
34+
use rustc_errors::{fluent, Applicability, Diagnostic, DiagnosticStyledString, MultiSpan};
3535
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
3636
use rustc_hir as hir;
3737
use rustc_hir::def::{DefKind, Res};
@@ -99,13 +99,12 @@ impl EarlyLintPass for WhileTrue {
9999
if let ast::ExprKind::Lit(ref lit) = pierce_parens(cond).kind {
100100
if let ast::LitKind::Bool(true) = lit.kind {
101101
if !lit.span.from_expansion() {
102-
let msg = "denote infinite loops with `loop { ... }`";
103102
let condition_span = e.span.with_hi(cond.span.hi());
104103
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
105-
lint.build(msg)
104+
lint.build(fluent::lint::builtin_while_true)
106105
.span_suggestion_short(
107106
condition_span,
108-
"use `loop`",
107+
fluent::lint::suggestion,
109108
format!(
110109
"{}loop",
111110
label.map_or_else(String::new, |label| format!(

0 commit comments

Comments
 (0)