Skip to content

Commit c3a561b

Browse files
committed
Rename set_contains_or_insert to contains_or_insert
Make the name of the lint more generic in order to support other collections like `BTreeSet`, `HashMap`, etc
1 parent 94a000b commit c3a561b

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5277,6 +5277,7 @@ Released 2018-09-13
52775277
[`comparison_to_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_to_empty
52785278
[`const_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_is_empty
52795279
[`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime
5280+
[`contains_or_insert`]: https://rust-lang.github.io/rust-clippy/master/index.html#contains_or_insert
52805281
[`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator
52815282
[`crate_in_macro_def`]: https://rust-lang.github.io/rust-clippy/master/index.html#crate_in_macro_def
52825283
[`create_dir`]: https://rust-lang.github.io/rust-clippy/master/index.html#create_dir
@@ -5800,7 +5801,6 @@ Released 2018-09-13
58005801
[`semicolon_outside_block`]: https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_outside_block
58015802
[`separated_literal_suffix`]: https://rust-lang.github.io/rust-clippy/master/index.html#separated_literal_suffix
58025803
[`serde_api_misuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#serde_api_misuse
5803-
[`set_contains_or_insert`]: https://rust-lang.github.io/rust-clippy/master/index.html#set_contains_or_insert
58045804
[`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse
58055805
[`shadow_same`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_same
58065806
[`shadow_unrelated`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated

clippy_lints/src/set_contains_or_insert.rs renamed to clippy_lints/src/contains_or_insert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ declare_clippy_lint! {
4343
/// }
4444
/// ```
4545
#[clippy::version = "1.80.0"]
46-
pub SET_CONTAINS_OR_INSERT,
46+
pub CONTAINS_OR_INSERT,
4747
nursery,
4848
"call to `HashSet::contains` followed by `HashSet::insert`"
4949
}
5050

51-
declare_lint_pass!(HashsetInsertAfterContains => [SET_CONTAINS_OR_INSERT]);
51+
declare_lint_pass!(HashsetInsertAfterContains => [CONTAINS_OR_INSERT]);
5252

5353
impl<'tcx> LateLintPass<'tcx> for HashsetInsertAfterContains {
5454
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
@@ -63,7 +63,7 @@ impl<'tcx> LateLintPass<'tcx> for HashsetInsertAfterContains {
6363
{
6464
span_lint(
6565
cx,
66-
SET_CONTAINS_OR_INSERT,
66+
CONTAINS_OR_INSERT,
6767
vec![contains_expr.span, insert_expr.span],
6868
"usage of `HashSet::insert` after `HashSet::contains`",
6969
);

clippy_lints/src/declared_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
111111
crate::collapsible_if::COLLAPSIBLE_IF_INFO,
112112
crate::collection_is_never_read::COLLECTION_IS_NEVER_READ_INFO,
113113
crate::comparison_chain::COMPARISON_CHAIN_INFO,
114+
crate::contains_or_insert::CONTAINS_OR_INSERT_INFO,
114115
crate::copies::BRANCHES_SHARING_CODE_INFO,
115116
crate::copies::IFS_SAME_COND_INFO,
116117
crate::copies::IF_SAME_THEN_ELSE_INFO,
@@ -647,7 +648,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
647648
crate::semicolon_block::SEMICOLON_OUTSIDE_BLOCK_INFO,
648649
crate::semicolon_if_nothing_returned::SEMICOLON_IF_NOTHING_RETURNED_INFO,
649650
crate::serde_api::SERDE_API_MISUSE_INFO,
650-
crate::set_contains_or_insert::SET_CONTAINS_OR_INSERT_INFO,
651651
crate::shadow::SHADOW_REUSE_INFO,
652652
crate::shadow::SHADOW_SAME_INFO,
653653
crate::shadow::SHADOW_UNRELATED_INFO,

clippy_lints/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ mod cognitive_complexity;
9898
mod collapsible_if;
9999
mod collection_is_never_read;
100100
mod comparison_chain;
101+
mod contains_or_insert;
101102
mod copies;
102103
mod copy_iterator;
103104
mod crate_in_macro_def;
@@ -320,7 +321,6 @@ mod self_named_constructors;
320321
mod semicolon_block;
321322
mod semicolon_if_nothing_returned;
322323
mod serde_api;
323-
mod set_contains_or_insert;
324324
mod shadow;
325325
mod significant_drop_tightening;
326326
mod single_call_fn;
@@ -1175,7 +1175,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
11751175
});
11761176
store.register_late_pass(move |_| Box::new(string_patterns::StringPatterns::new(msrv())));
11771177
store.register_early_pass(|| Box::new(field_scoped_visibility_modifiers::FieldScopedVisibilityModifiers));
1178-
store.register_late_pass(|_| Box::new(set_contains_or_insert::HashsetInsertAfterContains));
1178+
store.register_late_pass(|_| Box::new(contains_or_insert::HashsetInsertAfterContains));
11791179
store.register_early_pass(|| Box::new(byte_char_slices::ByteCharSlice));
11801180
store.register_early_pass(|| Box::new(cfg_not_test::CfgNotTest));
11811181
// add lints here, do not remove this comment, it's used in `new_lint`

tests/ui/set_contains_or_insert.rs renamed to tests/ui/contains_or_insert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unused)]
22
#![allow(clippy::nonminimal_bool)]
33
#![allow(clippy::needless_borrow)]
4-
#![warn(clippy::set_contains_or_insert)]
4+
#![warn(clippy::contains_or_insert)]
55

66
use std::collections::HashSet;
77

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,60 @@
11
error: usage of `HashSet::insert` after `HashSet::contains`
2-
--> tests/ui/set_contains_or_insert.rs:18:13
2+
--> tests/ui/contains_or_insert.rs:18:13
33
|
44
LL | if !set.contains(&value) {
55
| ^^^^^^^^^^^^^^^^
66
LL | set.insert(value);
77
| ^^^^^^^^^^^^^
88
|
99
= note: `-D clippy::set-contains-or-insert` implied by `-D warnings`
10-
= help: to override `-D warnings` add `#[allow(clippy::set_contains_or_insert)]`
10+
= help: to override `-D warnings` add `#[allow(clippy::contains_or_insert)]`
1111

1212
error: usage of `HashSet::insert` after `HashSet::contains`
13-
--> tests/ui/set_contains_or_insert.rs:23:12
13+
--> tests/ui/contains_or_insert.rs:23:12
1414
|
1515
LL | if set.contains(&value) {
1616
| ^^^^^^^^^^^^^^^^
1717
LL | set.insert(value);
1818
| ^^^^^^^^^^^^^
1919

2020
error: usage of `HashSet::insert` after `HashSet::contains`
21-
--> tests/ui/set_contains_or_insert.rs:28:13
21+
--> tests/ui/contains_or_insert.rs:28:13
2222
|
2323
LL | if !set.contains(&value) {
2424
| ^^^^^^^^^^^^^^^^
2525
LL | set.insert(value);
2626
| ^^^^^^^^^^^^^
2727

2828
error: usage of `HashSet::insert` after `HashSet::contains`
29-
--> tests/ui/set_contains_or_insert.rs:32:14
29+
--> tests/ui/contains_or_insert.rs:32:14
3030
|
3131
LL | if !!set.contains(&value) {
3232
| ^^^^^^^^^^^^^^^^
3333
LL | set.insert(value);
3434
| ^^^^^^^^^^^^^
3535

3636
error: usage of `HashSet::insert` after `HashSet::contains`
37-
--> tests/ui/set_contains_or_insert.rs:37:15
37+
--> tests/ui/contains_or_insert.rs:37:15
3838
|
3939
LL | if (&set).contains(&value) {
4040
| ^^^^^^^^^^^^^^^^
4141
LL | set.insert(value);
4242
| ^^^^^^^^^^^^^
4343

4444
error: usage of `HashSet::insert` after `HashSet::contains`
45-
--> tests/ui/set_contains_or_insert.rs:42:13
45+
--> tests/ui/contains_or_insert.rs:42:13
4646
|
4747
LL | if !set.contains(borrow_value) {
4848
| ^^^^^^^^^^^^^^^^^^^^^^
4949
LL | set.insert(*borrow_value);
5050
| ^^^^^^^^^^^^^^^^^^^^^
5151

5252
error: usage of `HashSet::insert` after `HashSet::contains`
53-
--> tests/ui/set_contains_or_insert.rs:47:20
53+
--> tests/ui/contains_or_insert.rs:47:20
5454
|
5555
LL | if !borrow_set.contains(&value) {
5656
| ^^^^^^^^^^^^^^^^
5757
LL | borrow_set.insert(value);
5858
| ^^^^^^^^^^^^^
5959

6060
error: aborting due to 7 previous errors
61-

0 commit comments

Comments
 (0)