Skip to content

Commit 818e5af

Browse files
committed
Update ui tests and add rustfix
1 parent 7b192e0 commit 818e5af

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

tests/ui/get_last_with_len.fixed

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// run-rustfix
2+
3+
#![warn(clippy::get_last_with_len)]
4+
5+
fn dont_use_last() {
6+
let x = vec![2, 3, 5];
7+
let _ = x.last(); // ~ERROR Use x.last()
8+
}
9+
10+
fn indexing_two_from_end() {
11+
let x = vec![2, 3, 5];
12+
let _ = x.get(x.len() - 2);
13+
}
14+
15+
fn index_into_last() {
16+
let x = vec![2, 3, 5];
17+
let _ = x[x.len() - 1];
18+
}
19+
20+
fn use_last_with_different_vec_length() {
21+
let x = vec![2, 3, 5];
22+
let y = vec!['a', 'b', 'c'];
23+
let _ = x.get(y.len() - 1);
24+
}
25+
26+
fn main() {
27+
dont_use_last();
28+
indexing_two_from_end();
29+
index_into_last();
30+
use_last_with_different_vec_length();
31+
}

tests/ui/get_last_with_len.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-rustfix
2+
13
#![warn(clippy::get_last_with_len)]
24

35
fn dont_use_last() {

tests/ui/get_last_with_len.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: unknown clippy lint: clippy::get_last_with_len
2-
--> $DIR/get_last_with_len.rs:1:9
1+
error: Use `x.last()` instead of `x.get(x.len() - 1)`
2+
--> $DIR/get_last_with_len.rs:7:13
33
|
4-
LL | #![warn(clippy::get_last_with_len)]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | let _ = x.get(x.len() - 1); // ~ERROR Use x.last()
5+
| ^^^^^^^^^^^^^^^^^^ help: try: `x.last()`
66
|
7-
= note: `-D clippy::unknown-clippy-lints` implied by `-D warnings`
7+
= note: `-D clippy::get-last-with-len` implied by `-D warnings`
88

99
error: aborting due to previous error
1010

0 commit comments

Comments
 (0)