mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
out_of_bounds_indexing improved reporting of out of bounds value
This commit is contained in:
parent
5c39282826
commit
66d3672b26
@ -120,7 +120,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
||||
utils::span_lint(
|
||||
cx,
|
||||
OUT_OF_BOUNDS_INDEXING,
|
||||
expr.span,
|
||||
range.start.map_or(expr.span, |start| start.span),
|
||||
"range is out of bounds",
|
||||
);
|
||||
return;
|
||||
@ -132,7 +132,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
||||
utils::span_lint(
|
||||
cx,
|
||||
OUT_OF_BOUNDS_INDEXING,
|
||||
expr.span,
|
||||
range.end.map_or(expr.span, |end| end.span),
|
||||
"range is out of bounds",
|
||||
);
|
||||
return;
|
||||
|
@ -48,18 +48,18 @@ error: slicing may panic.
|
||||
= help: Consider using `.get(n..)` or .get_mut(n..)` instead
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:30:6
|
||||
--> $DIR/indexing_slicing.rs:30:11
|
||||
|
|
||||
30 | &x[..=4];
|
||||
| ^^^^^^^
|
||||
| ^
|
||||
|
|
||||
= note: `-D clippy::out-of-bounds-indexing` implied by `-D warnings`
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:31:6
|
||||
--> $DIR/indexing_slicing.rs:31:11
|
||||
|
|
||||
31 | &x[1..5];
|
||||
| ^^^^^^^
|
||||
| ^
|
||||
|
||||
error: slicing may panic.
|
||||
--> $DIR/indexing_slicing.rs:32:6
|
||||
@ -70,34 +70,34 @@ error: slicing may panic.
|
||||
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:32:6
|
||||
--> $DIR/indexing_slicing.rs:32:8
|
||||
|
|
||||
32 | &x[5..][..10]; // Two lint reports, one for [5..] and another for [..10].
|
||||
| ^^^^^^
|
||||
| ^
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:33:6
|
||||
--> $DIR/indexing_slicing.rs:33:8
|
||||
|
|
||||
33 | &x[5..];
|
||||
| ^^^^^^
|
||||
| ^
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:34:6
|
||||
--> $DIR/indexing_slicing.rs:34:10
|
||||
|
|
||||
34 | &x[..5];
|
||||
| ^^^^^^
|
||||
| ^
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:35:6
|
||||
--> $DIR/indexing_slicing.rs:35:8
|
||||
|
|
||||
35 | &x[5..].iter().map(|x| 2 * x).collect::<Vec<i32>>();
|
||||
| ^^^^^^
|
||||
| ^
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:36:6
|
||||
--> $DIR/indexing_slicing.rs:36:12
|
||||
|
|
||||
36 | &x[0..=4];
|
||||
| ^^^^^^^^
|
||||
| ^
|
||||
|
||||
error: slicing may panic.
|
||||
--> $DIR/indexing_slicing.rs:37:6
|
||||
@ -148,46 +148,46 @@ error: slicing may panic.
|
||||
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:60:6
|
||||
--> $DIR/indexing_slicing.rs:60:12
|
||||
|
|
||||
60 | &empty[1..5];
|
||||
| ^^^^^^^^^^^
|
||||
| ^
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:61:6
|
||||
--> $DIR/indexing_slicing.rs:61:16
|
||||
|
|
||||
61 | &empty[0..=4];
|
||||
| ^^^^^^^^^^^^
|
||||
| ^
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:62:6
|
||||
--> $DIR/indexing_slicing.rs:62:15
|
||||
|
|
||||
62 | &empty[..=4];
|
||||
| ^^^^^^^^^^^
|
||||
| ^
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:63:6
|
||||
--> $DIR/indexing_slicing.rs:63:12
|
||||
|
|
||||
63 | &empty[1..];
|
||||
| ^^^^^^^^^^
|
||||
| ^
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:64:6
|
||||
--> $DIR/indexing_slicing.rs:64:14
|
||||
|
|
||||
64 | &empty[..4];
|
||||
| ^^^^^^^^^^
|
||||
| ^
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:65:6
|
||||
--> $DIR/indexing_slicing.rs:65:16
|
||||
|
|
||||
65 | &empty[0..=0];
|
||||
| ^^^^^^^^^^^^
|
||||
| ^
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:66:6
|
||||
--> $DIR/indexing_slicing.rs:66:15
|
||||
|
|
||||
66 | &empty[..=0];
|
||||
| ^^^^^^^^^^^
|
||||
| ^
|
||||
|
||||
error: indexing may panic.
|
||||
--> $DIR/indexing_slicing.rs:74:5
|
||||
@ -230,10 +230,10 @@ error: slicing may panic.
|
||||
= help: Consider using `.get(..n)`or `.get_mut(..n)` instead
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:78:6
|
||||
--> $DIR/indexing_slicing.rs:78:8
|
||||
|
|
||||
78 | &x[10..][..100]; // Two lint reports, one for [10..] and another for [..100].
|
||||
| ^^^^^^^
|
||||
| ^^
|
||||
|
||||
error: slicing may panic.
|
||||
--> $DIR/indexing_slicing.rs:79:6
|
||||
@ -268,16 +268,16 @@ error: indexing may panic.
|
||||
= help: Consider using `.get(n)` or `.get_mut(n)` instead
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:97:6
|
||||
--> $DIR/indexing_slicing.rs:97:13
|
||||
|
|
||||
97 | &x[num..10]; // should trigger out of bounds error
|
||||
| ^^^^^^^^^^
|
||||
| ^^
|
||||
|
||||
error: range is out of bounds
|
||||
--> $DIR/indexing_slicing.rs:98:6
|
||||
--> $DIR/indexing_slicing.rs:98:8
|
||||
|
|
||||
98 | &x[10..num]; // should trigger out of bounds error
|
||||
| ^^^^^^^^^^
|
||||
| ^^
|
||||
|
||||
error: aborting due to 39 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user