Skip to content

Commit 565907f

Browse files
committed
Auto merge of #46857 - estebank:use-loop-sp, r=nikomatsakis
Point at `while true` span instead of entire block
2 parents f0cf23e + e9f4fc8 commit 565907f

File tree

4 files changed

+7
-28
lines changed

4 files changed

+7
-28
lines changed

src/librustc_lint/builtin.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue {
102102
if let ast::LitKind::Bool(true) = lit.node {
103103
if lit.span.ctxt() == SyntaxContext::empty() {
104104
let msg = "denote infinite loops with `loop { ... }`";
105-
let mut err = cx.struct_span_lint(WHILE_TRUE, e.span, msg);
106105
let condition_span = cx.tcx.sess.codemap().def_span(e.span);
107-
err.span_suggestion_short(condition_span,
108-
"use `loop`",
109-
"loop".to_owned());
106+
let mut err = cx.struct_span_lint(WHILE_TRUE, condition_span, msg);
107+
err.span_suggestion_short(condition_span, "use `loop`", "loop".to_owned());
110108
err.emit();
111109
}
112110
}

src/test/ui/codemap_tests/unicode_3.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ warning: denote infinite loops with `loop { ... }`
22
--> $DIR/unicode_3.rs:14:45
33
|
44
14 | let s = "ZͨA͑ͦ͒͋ͤ͑̚L̄͑͋Ĝͨͥ̿͒̽̈́Oͥ͛ͭ!̏"; while true { break; }
5-
| ----------^^^^^^^^^^^
6-
| |
7-
| help: use `loop`
5+
| ^^^^^^^^^^ help: use `loop`
86
|
97
= note: #[warn(while_true)] on by default
108

src/test/ui/issue-1962.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
error: denote infinite loops with `loop { ... }`
22
--> $DIR/issue-1962.rs:14:3
33
|
4-
14 | while true { //~ ERROR denote infinite loops with `loop
5-
| ^---------
6-
| |
7-
| ___help: use `loop`
8-
| |
9-
15 | | i += 1;
10-
16 | | if i == 5 { break; }
11-
17 | | }
12-
| |___^
4+
14 | while true { //~ ERROR denote infinite loops with `loop
5+
| ^^^^^^^^^^ help: use `loop`
136
|
147
= note: requested on the command line with `-D while-true`
158

src/test/ui/lint/suggestions.stderr

+2-12
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,8 @@ warning: function is marked #[no_mangle], but not exported
7575
warning: denote infinite loops with `loop { ... }`
7676
--> $DIR/suggestions.rs:34:5
7777
|
78-
34 | while true { // should suggest `loop`
79-
| ^---------
80-
| |
81-
| _____help: use `loop`
82-
| |
83-
35 | | //~^ WARN denote infinite loops
84-
36 | | let mut a = (1); // should suggest no `mut`, no parens
85-
37 | | //~^ WARN does not need to be mutable
86-
... |
87-
44 | | println!("{}", a);
88-
45 | | }
89-
| |_____^
78+
34 | while true { // should suggest `loop`
79+
| ^^^^^^^^^^ help: use `loop`
9080
|
9181
= note: #[warn(while_true)] on by default
9282

0 commit comments

Comments
 (0)