Skip to content

Commit 01b1360

Browse files
committed
Rename 'use_last' to 'get_last_with_len'
1 parent 1a8771e commit 01b1360

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ All notable changes to this project will be documented in this file.
909909
[`for_loop_over_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loop_over_result
910910
[`forget_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_copy
911911
[`forget_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_ref
912+
[`get_last_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_last_with_len
912913
[`get_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_unwrap
913914
[`identity_conversion`]: https://rust-lang.github.io/rust-clippy/master/index.html#identity_conversion
914915
[`identity_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#identity_op
@@ -1106,7 +1107,6 @@ All notable changes to this project will be documented in this file.
11061107
[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label
11071108
[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
11081109
[`use_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_debug
1109-
[`use_last`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_last
11101110
[`use_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_self
11111111
[`used_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding
11121112
[`useless_asref`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_asref

clippy_lints/src/use_last.rs renamed to clippy_lints/src/get_last_with_len.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ declare_clippy_lint! {
3737
/// let x = vec![2, 3, 5];
3838
/// let last_element = x.last();
3939
/// ```
40-
pub USE_LAST,
40+
pub GET_LAST_WITH_LEN,
4141
complexity,
4242
"Using `x.get(x.len() - 1)` when `x.last()` is correct and simpler"
4343
}
4444

45-
declare_lint_pass!(UseLast => [USE_LAST]);
45+
declare_lint_pass!(UseLast => [GET_LAST_WITH_LEN]);
4646

4747
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseLast {
4848
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
@@ -76,17 +76,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseLast {
7676
if let LitKind::Int(rhs_value, ..) = rhs_lit.node;
7777
if rhs_value == 1;
7878

79-
let mut applicability = Applicability::MachineApplicable;
80-
let vec_name = snippet_with_applicability(
81-
cx, struct_calling_on.span, "vec", &mut applicability);
8279

8380
then {
81+
let mut applicability = Applicability::MachineApplicable;
82+
let vec_name = snippet_with_applicability(cx, struct_calling_on.span, "vec",
83+
&mut applicability);
84+
8485
span_lint_and_sugg(
8586
cx,
86-
USE_LAST,
87+
GET_LAST_WITH_LEN,
8788
expr.span,
88-
&format!("Use `{}.last()` instead of `{}.get({}.len() - 1)`",
89-
vec_name, vec_name, vec_name),
89+
&format!("Use `{}.last()` instead of `{}.get({}.len() - 1)`", vec_name,
90+
vec_name, vec_name),
9091
"try",
9192
format!("{}.last()", vec_name),
9293
applicability,

clippy_lints/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ pub mod fallible_impl_from;
185185
pub mod format;
186186
pub mod formatting;
187187
pub mod functions;
188+
pub mod get_last_with_len;
188189
pub mod identity_conversion;
189190
pub mod identity_op;
190191
pub mod if_not_else;
@@ -266,7 +267,6 @@ pub mod unsafe_removed_from_name;
266267
pub mod unused_io_amount;
267268
pub mod unused_label;
268269
pub mod unwrap;
269-
pub mod use_last;
270270
pub mod use_self;
271271
pub mod vec;
272272
pub mod wildcard_dependencies;
@@ -574,7 +574,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
574574
reg.register_late_lint_pass(box types::RefToMut);
575575
reg.register_late_lint_pass(box assertions_on_constants::AssertionsOnConstants);
576576
reg.register_late_lint_pass(box missing_const_for_fn::MissingConstForFn);
577-
reg.register_late_lint_pass(box use_last::UseLast);
578577
reg.register_late_lint_pass(box transmuting_null::TransmutingNull);
579578
reg.register_late_lint_pass(box path_buf_push_overwrite::PathBufPushOverwrite);
580579

@@ -708,6 +707,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
708707
formatting::SUSPICIOUS_ELSE_FORMATTING,
709708
functions::NOT_UNSAFE_PTR_ARG_DEREF,
710709
functions::TOO_MANY_ARGUMENTS,
710+
get_last_with_len::GET_LAST_WITH_LEN,
711711
identity_conversion::IDENTITY_CONVERSION,
712712
identity_op::IDENTITY_OP,
713713
indexing_slicing::OUT_OF_BOUNDS_INDEXING,
@@ -872,7 +872,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
872872
unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME,
873873
unused_io_amount::UNUSED_IO_AMOUNT,
874874
unused_label::UNUSED_LABEL,
875-
use_last::USE_LAST,
876875
vec::USELESS_VEC,
877876
write::PRINTLN_EMPTY_STRING,
878877
write::PRINT_LITERAL,
@@ -980,6 +979,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
980979
explicit_write::EXPLICIT_WRITE,
981980
format::USELESS_FORMAT,
982981
functions::TOO_MANY_ARGUMENTS,
982+
get_last_with_len::GET_LAST_WITH_LEN,
983983
identity_conversion::IDENTITY_CONVERSION,
984984
identity_op::IDENTITY_OP,
985985
int_plus_one::INT_PLUS_ONE,
@@ -1035,7 +1035,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
10351035
types::UNNECESSARY_CAST,
10361036
types::VEC_BOX,
10371037
unused_label::UNUSED_LABEL,
1038-
use_last::USE_LAST,
10391038
zero_div_zero::ZERO_DIVIDED_BY_ZERO,
10401039
]);
10411040

tests/ui/use_last.rs renamed to tests/ui/get_last_with_len.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::use_last)]
1+
#![warn(clippy::get_last_with_len)]
22

33
fn dont_use_last() {
44
let x = vec![2, 3, 5];

tests/ui/get_last_with_len.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: unknown clippy lint: clippy::get_last_with_len
2+
--> $DIR/get_last_with_len.rs:1:9
3+
|
4+
LL | #![warn(clippy::get_last_with_len)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::unknown-clippy-lints` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+
File renamed without changes.

tests/ui/use_last.stderr

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)