From e9f4fc8d406ddd2d75e4aae34fe84abdd1bc479a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 19 Dec 2017 14:45:17 -0800 Subject: [PATCH] Point at `while true` span instead of entire block --- src/librustc_lint/builtin.rs | 6 ++---- src/test/ui/codemap_tests/unicode_3.stderr | 4 +--- src/test/ui/issue-1962.stderr | 11 ++--------- src/test/ui/lint/suggestions.stderr | 14 ++------------ 4 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 5417634144b..783022394cf 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -102,11 +102,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue { if let ast::LitKind::Bool(true) = lit.node { if lit.span.ctxt() == SyntaxContext::empty() { let msg = "denote infinite loops with `loop { ... }`"; - let mut err = cx.struct_span_lint(WHILE_TRUE, e.span, msg); let condition_span = cx.tcx.sess.codemap().def_span(e.span); - err.span_suggestion_short(condition_span, - "use `loop`", - "loop".to_owned()); + let mut err = cx.struct_span_lint(WHILE_TRUE, condition_span, msg); + err.span_suggestion_short(condition_span, "use `loop`", "loop".to_owned()); err.emit(); } } diff --git a/src/test/ui/codemap_tests/unicode_3.stderr b/src/test/ui/codemap_tests/unicode_3.stderr index d2c850d3cbd..3547accd2ed 100644 --- a/src/test/ui/codemap_tests/unicode_3.stderr +++ b/src/test/ui/codemap_tests/unicode_3.stderr @@ -2,9 +2,7 @@ warning: denote infinite loops with `loop { ... }` --> $DIR/unicode_3.rs:14:45 | 14 | let s = "ZͨA͑ͦ͒͋ͤ͑̚L̄͑͋Ĝͨͥ̿͒̽̈́Oͥ͛ͭ!̏"; while true { break; } - | ----------^^^^^^^^^^^ - | | - | help: use `loop` + | ^^^^^^^^^^ help: use `loop` | = note: #[warn(while_true)] on by default diff --git a/src/test/ui/issue-1962.stderr b/src/test/ui/issue-1962.stderr index 4e34898bebe..5f920316b5c 100644 --- a/src/test/ui/issue-1962.stderr +++ b/src/test/ui/issue-1962.stderr @@ -1,15 +1,8 @@ error: denote infinite loops with `loop { ... }` --> $DIR/issue-1962.rs:14:3 | -14 | while true { //~ ERROR denote infinite loops with `loop - | ^--------- - | | - | ___help: use `loop` - | | -15 | | i += 1; -16 | | if i == 5 { break; } -17 | | } - | |___^ +14 | while true { //~ ERROR denote infinite loops with `loop + | ^^^^^^^^^^ help: use `loop` | = note: requested on the command line with `-D while-true` diff --git a/src/test/ui/lint/suggestions.stderr b/src/test/ui/lint/suggestions.stderr index 44cfb1a82a2..701a9522218 100644 --- a/src/test/ui/lint/suggestions.stderr +++ b/src/test/ui/lint/suggestions.stderr @@ -75,18 +75,8 @@ warning: function is marked #[no_mangle], but not exported warning: denote infinite loops with `loop { ... }` --> $DIR/suggestions.rs:34:5 | -34 | while true { // should suggest `loop` - | ^--------- - | | - | _____help: use `loop` - | | -35 | | //~^ WARN denote infinite loops -36 | | let mut a = (1); // should suggest no `mut`, no parens -37 | | //~^ WARN does not need to be mutable -... | -44 | | println!("{}", a); -45 | | } - | |_____^ +34 | while true { // should suggest `loop` + | ^^^^^^^^^^ help: use `loop` | = note: #[warn(while_true)] on by default