mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-21 20:23:21 +00:00
while_immutable_condition: limit suggestion span to condition
This commit is contained in:
parent
85bcaad412
commit
737247e50e
@ -2161,7 +2161,7 @@ fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, b
|
||||
span_lint(
|
||||
cx,
|
||||
WHILE_IMMUTABLE_CONDITION,
|
||||
expr.span,
|
||||
cond.span,
|
||||
"Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.",
|
||||
);
|
||||
}
|
||||
|
@ -1,83 +1,58 @@
|
||||
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
|
||||
--> $DIR/infinite_loop.rs:10:5
|
||||
--> $DIR/infinite_loop.rs:10:11
|
||||
|
|
||||
10 | / while y < 10 {
|
||||
11 | | println!("KO - y is immutable");
|
||||
12 | | }
|
||||
| |_____^
|
||||
10 | while y < 10 {
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: `-D while-immutable-condition` implied by `-D warnings`
|
||||
|
||||
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
|
||||
--> $DIR/infinite_loop.rs:15:5
|
||||
--> $DIR/infinite_loop.rs:15:11
|
||||
|
|
||||
15 | / while y < 10 && x < 3 {
|
||||
16 | | let mut k = 1;
|
||||
17 | | k += 2;
|
||||
18 | | println!("KO - x and y immutable");
|
||||
19 | | }
|
||||
| |_____^
|
||||
15 | while y < 10 && x < 3 {
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
|
||||
--> $DIR/infinite_loop.rs:22:5
|
||||
--> $DIR/infinite_loop.rs:22:11
|
||||
|
|
||||
22 | / while !cond {
|
||||
23 | | println!("KO - cond immutable");
|
||||
24 | | }
|
||||
| |_____^
|
||||
22 | while !cond {
|
||||
| ^^^^^
|
||||
|
||||
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
|
||||
--> $DIR/infinite_loop.rs:52:5
|
||||
--> $DIR/infinite_loop.rs:52:11
|
||||
|
|
||||
52 | / while i < 3 {
|
||||
53 | | j = 3;
|
||||
54 | | println!("KO - i not mentionned");
|
||||
55 | | }
|
||||
| |_____^
|
||||
52 | while i < 3 {
|
||||
| ^^^^^
|
||||
|
||||
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
|
||||
--> $DIR/infinite_loop.rs:57:5
|
||||
--> $DIR/infinite_loop.rs:57:11
|
||||
|
|
||||
57 | / while i < 3 && j > 0 {
|
||||
58 | | println!("KO - i and j not mentionned");
|
||||
59 | | }
|
||||
| |_____^
|
||||
57 | while i < 3 && j > 0 {
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
|
||||
--> $DIR/infinite_loop.rs:61:5
|
||||
--> $DIR/infinite_loop.rs:61:11
|
||||
|
|
||||
61 | / while i < 3 {
|
||||
62 | | let mut i = 5;
|
||||
63 | | fn_mutref(&mut i);
|
||||
64 | | println!("KO - shadowed");
|
||||
65 | | }
|
||||
| |_____^
|
||||
61 | while i < 3 {
|
||||
| ^^^^^
|
||||
|
||||
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
|
||||
--> $DIR/infinite_loop.rs:76:5
|
||||
--> $DIR/infinite_loop.rs:76:11
|
||||
|
|
||||
76 | / while i < 3 {
|
||||
77 | | fn_constref(&i);
|
||||
78 | | println!("KO - const reference");
|
||||
79 | | }
|
||||
| |_____^
|
||||
76 | while i < 3 {
|
||||
| ^^^^^
|
||||
|
||||
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
|
||||
--> $DIR/infinite_loop.rs:81:5
|
||||
--> $DIR/infinite_loop.rs:81:11
|
||||
|
|
||||
81 | / while i < 3 {
|
||||
82 | | fn_val(i);
|
||||
83 | | println!("KO - passed by value");
|
||||
84 | | }
|
||||
| |_____^
|
||||
81 | while i < 3 {
|
||||
| ^^^^^
|
||||
|
||||
error: Variable in the condition are not mutated in the loop body. This either leads to an infinite or to a never running loop.
|
||||
--> $DIR/infinite_loop.rs:144:9
|
||||
--> $DIR/infinite_loop.rs:144:15
|
||||
|
|
||||
144 | / while self.count < n {
|
||||
145 | | println!("KO - {} is not mutated", self.count);
|
||||
146 | | }
|
||||
| |_________^
|
||||
144 | while self.count < n {
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user