Skip to content

Commit f26073b

Browse files
committed
Improve needless_borrow lint.
* Lint when a borrow is auto dereferenced more than once * Lint when the expression is used as the expression of a block for a match arm Moves `needless_borrow` and `ref_binding_to_reference` to `dereference` lint pass in preperation for `explicit_auto_deref` lint.
1 parent f51fb34 commit f26073b

10 files changed

+417
-304
lines changed

clippy_lints/src/dereference.rs

Lines changed: 324 additions & 5 deletions
Large diffs are not rendered by default.

clippy_lints/src/lib.register_all.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
3333
LintId::of(copies::IFS_SAME_COND),
3434
LintId::of(copies::IF_SAME_THEN_ELSE),
3535
LintId::of(default::FIELD_REASSIGN_WITH_DEFAULT),
36+
LintId::of(dereference::NEEDLESS_BORROW),
3637
LintId::of(derivable_impls::DERIVABLE_IMPLS),
3738
LintId::of(derive::DERIVE_HASH_XOR_EQ),
3839
LintId::of(derive::DERIVE_ORD_XOR_PARTIAL_ORD),
@@ -203,7 +204,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
203204
LintId::of(needless_arbitrary_self_type::NEEDLESS_ARBITRARY_SELF_TYPE),
204205
LintId::of(needless_bool::BOOL_COMPARISON),
205206
LintId::of(needless_bool::NEEDLESS_BOOL),
206-
LintId::of(needless_borrow::NEEDLESS_BORROW),
207207
LintId::of(needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE),
208208
LintId::of(needless_option_as_deref::NEEDLESS_OPTION_AS_DEREF),
209209
LintId::of(needless_question_mark::NEEDLESS_QUESTION_MARK),

clippy_lints/src/lib.register_lints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ store.register_lints(&[
9292
default::FIELD_REASSIGN_WITH_DEFAULT,
9393
default_numeric_fallback::DEFAULT_NUMERIC_FALLBACK,
9494
dereference::EXPLICIT_DEREF_METHODS,
95+
dereference::NEEDLESS_BORROW,
96+
dereference::REF_BINDING_TO_REFERENCE,
9597
derivable_impls::DERIVABLE_IMPLS,
9698
derive::DERIVE_HASH_XOR_EQ,
9799
derive::DERIVE_ORD_XOR_PARTIAL_ORD,
@@ -356,8 +358,6 @@ store.register_lints(&[
356358
needless_bitwise_bool::NEEDLESS_BITWISE_BOOL,
357359
needless_bool::BOOL_COMPARISON,
358360
needless_bool::NEEDLESS_BOOL,
359-
needless_borrow::NEEDLESS_BORROW,
360-
needless_borrow::REF_BINDING_TO_REFERENCE,
361361
needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE,
362362
needless_continue::NEEDLESS_CONTINUE,
363363
needless_for_each::NEEDLESS_FOR_EACH,

clippy_lints/src/lib.register_pedantic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![
2121
LintId::of(copy_iterator::COPY_ITERATOR),
2222
LintId::of(default::DEFAULT_TRAIT_ACCESS),
2323
LintId::of(dereference::EXPLICIT_DEREF_METHODS),
24+
LintId::of(dereference::REF_BINDING_TO_REFERENCE),
2425
LintId::of(derive::EXPL_IMPL_CLONE_ON_COPY),
2526
LintId::of(derive::UNSAFE_DERIVE_DESERIALIZE),
2627
LintId::of(doc::DOC_MARKDOWN),
@@ -68,7 +69,6 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![
6869
LintId::of(misc::USED_UNDERSCORE_BINDING),
6970
LintId::of(mut_mut::MUT_MUT),
7071
LintId::of(needless_bitwise_bool::NEEDLESS_BITWISE_BOOL),
71-
LintId::of(needless_borrow::REF_BINDING_TO_REFERENCE),
7272
LintId::of(needless_continue::NEEDLESS_CONTINUE),
7373
LintId::of(needless_for_each::NEEDLESS_FOR_EACH),
7474
LintId::of(needless_pass_by_value::NEEDLESS_PASS_BY_VALUE),

clippy_lints/src/lib.register_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ store.register_group(true, "clippy::style", Some("clippy_style"), vec![
1515
LintId::of(collapsible_match::COLLAPSIBLE_MATCH),
1616
LintId::of(comparison_chain::COMPARISON_CHAIN),
1717
LintId::of(default::FIELD_REASSIGN_WITH_DEFAULT),
18+
LintId::of(dereference::NEEDLESS_BORROW),
1819
LintId::of(doc::MISSING_SAFETY_DOC),
1920
LintId::of(doc::NEEDLESS_DOCTEST_MAIN),
2021
LintId::of(enum_variants::ENUM_VARIANT_NAMES),
@@ -81,7 +82,6 @@ store.register_group(true, "clippy::style", Some("clippy_style"), vec![
8182
LintId::of(misc_early::REDUNDANT_PATTERN),
8283
LintId::of(mut_mutex_lock::MUT_MUTEX_LOCK),
8384
LintId::of(mut_reference::UNNECESSARY_MUT_PASSED),
84-
LintId::of(needless_borrow::NEEDLESS_BORROW),
8585
LintId::of(neg_multiply::NEG_MULTIPLY),
8686
LintId::of(new_without_default::NEW_WITHOUT_DEFAULT),
8787
LintId::of(non_copy_const::BORROW_INTERIOR_MUTABLE_CONST),

clippy_lints/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ mod mutex_atomic;
297297
mod needless_arbitrary_self_type;
298298
mod needless_bitwise_bool;
299299
mod needless_bool;
300-
mod needless_borrow;
301300
mod needless_borrowed_ref;
302301
mod needless_continue;
303302
mod needless_for_each;
@@ -602,7 +601,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
602601
store.register_late_pass(|| Box::new(zero_div_zero::ZeroDiv));
603602
store.register_late_pass(|| Box::new(mutex_atomic::Mutex));
604603
store.register_late_pass(|| Box::new(needless_update::NeedlessUpdate));
605-
store.register_late_pass(|| Box::new(needless_borrow::NeedlessBorrow::default()));
606604
store.register_late_pass(|| Box::new(needless_borrowed_ref::NeedlessBorrowedRef));
607605
store.register_late_pass(|| Box::new(no_effect::NoEffect));
608606
store.register_late_pass(|| Box::new(temporary_assignment::TemporaryAssignment));

clippy_lints/src/needless_borrow.rs

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

0 commit comments

Comments
 (0)