Skip to content

Commit 6162ec8

Browse files
committed
Rename lint to index_refutable_slice and connected config
1 parent 950cd0d commit 6162ec8

File tree

13 files changed

+40
-40
lines changed

13 files changed

+40
-40
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2559,7 +2559,6 @@ Released 2018-09-13
25592559
[`assign_op_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern
25602560
[`assign_ops`]: https://rust-lang.github.io/rust-clippy/master/index.html#assign_ops
25612561
[`async_yields_async`]: https://rust-lang.github.io/rust-clippy/master/index.html#async_yields_async
2562-
[`avoidable_slice_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#avoidable_slice_indexing
25632562
[`await_holding_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_lock
25642563
[`await_holding_refcell_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_refcell_ref
25652564
[`bad_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
@@ -2698,6 +2697,7 @@ Released 2018-09-13
26982697
[`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops
26992698
[`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping
27002699
[`inconsistent_struct_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_struct_constructor
2700+
[`index_refutable_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#index_refutable_slice
27012701
[`indexing_slicing`]: https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicing
27022702
[`ineffective_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#ineffective_bit_mask
27032703
[`inefficient_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#inefficient_to_string

clippy_lints/src/avoidable_slice_indexing.rs renamed to clippy_lints/src/index_refutable_slice.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,34 +45,34 @@ declare_clippy_lint! {
4545
/// println!("{}", first);
4646
/// }
4747
/// ```
48-
pub AVOIDABLE_SLICE_INDEXING,
48+
pub INDEX_REFUTABLE_SLICE,
4949
nursery,
5050
"avoid indexing on slices which could be deconstructed"
5151
}
5252

5353
#[derive(Copy, Clone)]
54-
pub struct AvoidableSliceIndexing {
54+
pub struct IndexRefutableSlice {
5555
indexing_limit: u64,
5656
msrv: Option<RustcVersion>,
5757
}
5858

59-
impl AvoidableSliceIndexing {
60-
pub fn new(avoidable_slice_indexing_limit: u64, msrv: Option<RustcVersion>) -> Self {
59+
impl IndexRefutableSlice {
60+
pub fn new(max_suggested_slice_pattern_length: u64, msrv: Option<RustcVersion>) -> Self {
6161
Self {
62-
indexing_limit: avoidable_slice_indexing_limit,
62+
indexing_limit: max_suggested_slice_pattern_length,
6363
msrv,
6464
}
6565
}
6666
}
6767

68-
impl_lint_pass!(AvoidableSliceIndexing => [AVOIDABLE_SLICE_INDEXING]);
68+
impl_lint_pass!(IndexRefutableSlice => [INDEX_REFUTABLE_SLICE]);
6969

70-
impl LateLintPass<'_> for AvoidableSliceIndexing {
70+
impl LateLintPass<'_> for IndexRefutableSlice {
7171
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
7272
if_chain! {
7373
if !in_macro(expr.span) || is_expn_of(expr.span, "if_chain").is_some();
7474
if let Some(IfLet {let_pat, if_then, ..}) = IfLet::hir(cx, expr);
75-
if !is_lint_allowed(cx, AVOIDABLE_SLICE_INDEXING, expr.hir_id);
75+
if !is_lint_allowed(cx, INDEX_REFUTABLE_SLICE, expr.hir_id);
7676
if meets_msrv(self.msrv.as_ref(), &msrvs::SLICE_PATTERNS);
7777
if let Some(found_slices) = find_slice_values(cx, let_pat);
7878
if let Some(filtered_slices) = filter_lintable_slices(cx, found_slices, self.indexing_limit, if_then);
@@ -154,7 +154,7 @@ fn lint_slice(cx: &LateContext<'_>, slice: &SliceLintInformation) {
154154

155155
span_lint_and_then(
156156
cx,
157-
AVOIDABLE_SLICE_INDEXING,
157+
INDEX_REFUTABLE_SLICE,
158158
slice.ident.span,
159159
"this binding can be a slice pattern to avoid indexing",
160160
|diag| {

clippy_lints/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ mod assertions_on_constants;
165165
mod assign_ops;
166166
mod async_yields_async;
167167
mod attrs;
168-
mod avoidable_slice_indexing;
169168
mod await_holding_invalid;
170169
mod bit_mask;
171170
mod blacklisted_name;
@@ -233,6 +232,7 @@ mod implicit_hasher;
233232
mod implicit_return;
234233
mod implicit_saturating_sub;
235234
mod inconsistent_struct_constructor;
235+
mod index_refutable_slice;
236236
mod indexing_slicing;
237237
mod infinite_iter;
238238
mod inherent_impl;
@@ -548,7 +548,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
548548
attrs::INLINE_ALWAYS,
549549
attrs::MISMATCHED_TARGET_OS,
550550
attrs::USELESS_ATTRIBUTE,
551-
avoidable_slice_indexing::AVOIDABLE_SLICE_INDEXING,
552551
await_holding_invalid::AWAIT_HOLDING_LOCK,
553552
await_holding_invalid::AWAIT_HOLDING_REFCELL_REF,
554553
bit_mask::BAD_BIT_MASK,
@@ -665,6 +664,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
665664
implicit_return::IMPLICIT_RETURN,
666665
implicit_saturating_sub::IMPLICIT_SATURATING_SUB,
667666
inconsistent_struct_constructor::INCONSISTENT_STRUCT_CONSTRUCTOR,
667+
index_refutable_slice::INDEX_REFUTABLE_SLICE,
668668
indexing_slicing::INDEXING_SLICING,
669669
indexing_slicing::OUT_OF_BOUNDS_INDEXING,
670670
infinite_iter::INFINITE_ITER,
@@ -1808,7 +1808,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
18081808

18091809
store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
18101810
LintId::of(attrs::EMPTY_LINE_AFTER_OUTER_ATTR),
1811-
LintId::of(avoidable_slice_indexing::AVOIDABLE_SLICE_INDEXING),
18121811
LintId::of(cognitive_complexity::COGNITIVE_COMPLEXITY),
18131812
LintId::of(copies::BRANCHES_SHARING_CODE),
18141813
LintId::of(disallowed_method::DISALLOWED_METHOD),
@@ -1817,6 +1816,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
18171816
LintId::of(floating_point_arithmetic::IMPRECISE_FLOPS),
18181817
LintId::of(floating_point_arithmetic::SUBOPTIMAL_FLOPS),
18191818
LintId::of(future_not_send::FUTURE_NOT_SEND),
1819+
LintId::of(index_refutable_slice::INDEX_REFUTABLE_SLICE),
18201820
LintId::of(let_if_seq::USELESS_LET_IF_SEQ),
18211821
LintId::of(missing_const_for_fn::MISSING_CONST_FOR_FN),
18221822
LintId::of(mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL),
@@ -1926,8 +1926,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
19261926
store.register_early_pass(move || Box::new(unnested_or_patterns::UnnestedOrPatterns::new(msrv)));
19271927

19281928
store.register_late_pass(|| Box::new(size_of_in_element_count::SizeOfInElementCount));
1929-
let avoidable_slice_indexing_limit = conf.avoidable_slice_indexing_limit;
1930-
store.register_late_pass(move || Box::new(avoidable_slice_indexing::AvoidableSliceIndexing::new(avoidable_slice_indexing_limit, msrv)));
1929+
let max_suggested_slice_pattern_length = conf.max_suggested_slice_pattern_length;
1930+
store.register_late_pass(move || Box::new(index_refutable_slice::IndexRefutableSlice::new(max_suggested_slice_pattern_length, msrv)));
19311931
store.register_late_pass(|| Box::new(map_clone::MapClone));
19321932
store.register_late_pass(|| Box::new(map_err_ignore::MapErrIgnore));
19331933
store.register_late_pass(|| Box::new(shadow::Shadow));

clippy_lints/src/utils/conf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ define_Conf! {
140140
///
141141
/// Suppress lints whenever the suggested change would cause breakage for other crates.
142142
(avoid_breaking_exported_api: bool = true),
143-
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, AVOIDABLE_SLICE_INDEXING.
143+
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, INDEX_REFUTABLE_SLICE.
144144
///
145145
/// The minimum rust version that the project supports
146146
(msrv: Option<String> = None),
@@ -284,12 +284,12 @@ define_Conf! {
284284
///
285285
/// The list of unicode scripts allowed to be used in the scope.
286286
(allowed_scripts: Vec<String> = vec!["Latin".to_string()]),
287-
/// Lint: AVOIDABLE_SLICE_INDEXING.
287+
/// Lint: INDEX_REFUTABLE_SLICE.
288288
///
289289
/// The limit after which slice indexing will not be linted as avoidable.
290290
///
291291
/// As an example, the default limit of `3` would allow `slice[3]` but lint `slice[2]`.
292-
(avoidable_slice_indexing_limit: u64 = 3),
292+
(max_suggested_slice_pattern_length: u64 = 3),
293293
}
294294

295295
/// Search for the configuration file.

tests/ui-toml/avoidable_slice_indexing_limit/clippy.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/ui-toml/avoidable_slice_indexing_limit/avoidable_slice_indexing_limit.rs renamed to tests/ui-toml/max_suggested_slice_pattern_length/avoidable_slice_indexing_limit.rs

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

33
fn below_limit() {
44
let slice: Option<&[u32]> = Some(&[1, 2, 3]);

tests/ui-toml/avoidable_slice_indexing_limit/avoidable_slice_indexing_limit.stderr renamed to tests/ui-toml/max_suggested_slice_pattern_length/avoidable_slice_indexing_limit.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | if let Some(slice) = slice {
77
note: the lint level is defined here
88
--> $DIR/avoidable_slice_indexing_limit.rs:1:9
99
|
10-
LL | #![deny(clippy::avoidable_slice_indexing)]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | #![deny(clippy::index_refutable_slice)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
help: try using a slice pattern here
1313
|
1414
LL | if let Some([_, _, _, _, _, _, _, slice_7, ..]) = slice {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
max-suggested-slice-pattern-length = 8
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `avoid-breaking-exported-api`, `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `disallowed-types`, `unreadable-literal-lint-fractions`, `upper-case-acronyms-aggressive`, `cargo-ignore-publish`, `standard-macro-braces`, `enforced-import-renames`, `allowed-scripts`, `avoidable-slice-indexing-limit`, `third-party` at line 5 column 1
1+
error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `avoid-breaking-exported-api`, `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `disallowed-types`, `unreadable-literal-lint-fractions`, `upper-case-acronyms-aggressive`, `cargo-ignore-publish`, `standard-macro-braces`, `enforced-import-renames`, `allowed-scripts`, `max-suggested-slice-pattern-length`, `third-party` at line 5 column 1
22

33
error: aborting due to previous error
44

tests/ui/avoidable_slice_indexing/if_let_slice_destruction.rs renamed to tests/ui/index_refutable_slice/if_let_slice_binding.rs

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

33
enum SomeEnum<T> {
44
One(T),

tests/ui/avoidable_slice_indexing/if_let_slice_destruction.stderr renamed to tests/ui/index_refutable_slice/if_let_slice_binding.stderr

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error: this binding can be a slice pattern to avoid indexing
2-
--> $DIR/if_let_slice_destruction.rs:13:17
2+
--> $DIR/if_let_slice_binding.rs:13:17
33
|
44
LL | if let Some(slice) = slice {
55
| ^^^^^
66
|
77
note: the lint level is defined here
8-
--> $DIR/if_let_slice_destruction.rs:1:9
8+
--> $DIR/if_let_slice_binding.rs:1:9
99
|
10-
LL | #![deny(clippy::avoidable_slice_indexing)]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | #![deny(clippy::index_refutable_slice)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
help: try using a slice pattern here
1313
|
1414
LL | if let Some([slice_0, ..]) = slice {
@@ -19,7 +19,7 @@ LL | println!("{}", slice_0);
1919
| ~~~~~~~
2020

2121
error: this binding can be a slice pattern to avoid indexing
22-
--> $DIR/if_let_slice_destruction.rs:19:17
22+
--> $DIR/if_let_slice_binding.rs:19:17
2323
|
2424
LL | if let Some(slice) = slice {
2525
| ^^^^^
@@ -34,7 +34,7 @@ LL | println!("{}", slice_0);
3434
| ~~~~~~~
3535

3636
error: this binding can be a slice pattern to avoid indexing
37-
--> $DIR/if_let_slice_destruction.rs:25:17
37+
--> $DIR/if_let_slice_binding.rs:25:17
3838
|
3939
LL | if let Some(slice) = slice {
4040
| ^^^^^
@@ -50,7 +50,7 @@ LL ~ println!("{}", slice_0);
5050
|
5151

5252
error: this binding can be a slice pattern to avoid indexing
53-
--> $DIR/if_let_slice_destruction.rs:32:26
53+
--> $DIR/if_let_slice_binding.rs:32:26
5454
|
5555
LL | if let SomeEnum::One(slice) | SomeEnum::Three(slice) = slice_wrapped {
5656
| ^^^^^
@@ -65,7 +65,7 @@ LL | println!("{}", slice_0);
6565
| ~~~~~~~
6666

6767
error: this binding can be a slice pattern to avoid indexing
68-
--> $DIR/if_let_slice_destruction.rs:39:29
68+
--> $DIR/if_let_slice_binding.rs:39:29
6969
|
7070
LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) {
7171
| ^
@@ -80,7 +80,7 @@ LL | println!("{} -> {}", a_2, b[1]);
8080
| ~~~
8181

8282
error: this binding can be a slice pattern to avoid indexing
83-
--> $DIR/if_let_slice_destruction.rs:39:38
83+
--> $DIR/if_let_slice_binding.rs:39:38
8484
|
8585
LL | if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) {
8686
| ^
@@ -95,7 +95,7 @@ LL | println!("{} -> {}", a[2], b_1);
9595
| ~~~
9696

9797
error: this binding can be a slice pattern to avoid indexing
98-
--> $DIR/if_let_slice_destruction.rs:46:21
98+
--> $DIR/if_let_slice_binding.rs:46:21
9999
|
100100
LL | if let Some(ref slice) = slice {
101101
| ^^^^^
@@ -110,7 +110,7 @@ LL | println!("{:?}", slice_1);
110110
| ~~~~~~~
111111

112112
error: this binding can be a slice pattern to avoid indexing
113-
--> $DIR/if_let_slice_destruction.rs:54:17
113+
--> $DIR/if_let_slice_binding.rs:54:17
114114
|
115115
LL | if let Some(slice) = &slice {
116116
| ^^^^^
@@ -125,7 +125,7 @@ LL | println!("{:?}", slice_0);
125125
| ~~~~~~~
126126

127127
error: this binding can be a slice pattern to avoid indexing
128-
--> $DIR/if_let_slice_destruction.rs:123:17
128+
--> $DIR/if_let_slice_binding.rs:123:17
129129
|
130130
LL | if let Some(slice) = wrap.inner {
131131
| ^^^^^
@@ -140,7 +140,7 @@ LL | println!("This is awesome! {}", slice_0);
140140
| ~~~~~~~
141141

142142
error: this binding can be a slice pattern to avoid indexing
143-
--> $DIR/if_let_slice_destruction.rs:130:17
143+
--> $DIR/if_let_slice_binding.rs:130:17
144144
|
145145
LL | if let Some(slice) = wrap.inner {
146146
| ^^^^^

tests/ui/avoidable_slice_indexing/slice_indexing_in_macro.rs renamed to tests/ui/index_refutable_slice/slice_indexing_in_macro.rs

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

33
extern crate if_chain;
44
use if_chain::if_chain;

tests/ui/avoidable_slice_indexing/slice_indexing_in_macro.stderr renamed to tests/ui/index_refutable_slice/slice_indexing_in_macro.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | if let Some(slice) = slice;
77
note: the lint level is defined here
88
--> $DIR/slice_indexing_in_macro.rs:1:9
99
|
10-
LL | #![deny(clippy::avoidable_slice_indexing)]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | #![deny(clippy::index_refutable_slice)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
help: try using a slice pattern here
1313
|
1414
LL | if let Some([slice_0, ..]) = slice;

0 commit comments

Comments
 (0)