mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
Auto merge of #46857 - estebank:use-loop-sp, r=nikomatsakis
Point at `while true` span instead of entire block
This commit is contained in:
commit
565907fefb
@ -102,11 +102,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue {
|
|||||||
if let ast::LitKind::Bool(true) = lit.node {
|
if let ast::LitKind::Bool(true) = lit.node {
|
||||||
if lit.span.ctxt() == SyntaxContext::empty() {
|
if lit.span.ctxt() == SyntaxContext::empty() {
|
||||||
let msg = "denote infinite loops with `loop { ... }`";
|
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);
|
let condition_span = cx.tcx.sess.codemap().def_span(e.span);
|
||||||
err.span_suggestion_short(condition_span,
|
let mut err = cx.struct_span_lint(WHILE_TRUE, condition_span, msg);
|
||||||
"use `loop`",
|
err.span_suggestion_short(condition_span, "use `loop`", "loop".to_owned());
|
||||||
"loop".to_owned());
|
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,7 @@ warning: denote infinite loops with `loop { ... }`
|
|||||||
--> $DIR/unicode_3.rs:14:45
|
--> $DIR/unicode_3.rs:14:45
|
||||||
|
|
|
|
||||||
14 | let s = "ZͨA͑ͦ͒͋ͤ͑̚L̄͑͋Ĝͨͥ̿͒̽̈́Oͥ͛ͭ!̏"; while true { break; }
|
14 | let s = "ZͨA͑ͦ͒͋ͤ͑̚L̄͑͋Ĝͨͥ̿͒̽̈́Oͥ͛ͭ!̏"; while true { break; }
|
||||||
| ----------^^^^^^^^^^^
|
| ^^^^^^^^^^ help: use `loop`
|
||||||
| |
|
|
||||||
| help: use `loop`
|
|
||||||
|
|
|
|
||||||
= note: #[warn(while_true)] on by default
|
= note: #[warn(while_true)] on by default
|
||||||
|
|
||||||
|
@ -2,14 +2,7 @@ error: denote infinite loops with `loop { ... }`
|
|||||||
--> $DIR/issue-1962.rs:14:3
|
--> $DIR/issue-1962.rs:14:3
|
||||||
|
|
|
|
||||||
14 | while true { //~ ERROR denote infinite loops with `loop
|
14 | while true { //~ ERROR denote infinite loops with `loop
|
||||||
| ^---------
|
| ^^^^^^^^^^ help: use `loop`
|
||||||
| |
|
|
||||||
| ___help: use `loop`
|
|
||||||
| |
|
|
||||||
15 | | i += 1;
|
|
||||||
16 | | if i == 5 { break; }
|
|
||||||
17 | | }
|
|
||||||
| |___^
|
|
||||||
|
|
|
|
||||||
= note: requested on the command line with `-D while-true`
|
= note: requested on the command line with `-D while-true`
|
||||||
|
|
||||||
|
@ -76,17 +76,7 @@ warning: denote infinite loops with `loop { ... }`
|
|||||||
--> $DIR/suggestions.rs:34:5
|
--> $DIR/suggestions.rs:34:5
|
||||||
|
|
|
|
||||||
34 | while true { // should suggest `loop`
|
34 | while true { // should suggest `loop`
|
||||||
| ^---------
|
| ^^^^^^^^^^ help: use `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 | | }
|
|
||||||
| |_____^
|
|
||||||
|
|
|
|
||||||
= note: #[warn(while_true)] on by default
|
= note: #[warn(while_true)] on by default
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user