Skip to content

Commit 94b7035

Browse files
authored
Do not specialize for if_chain any longer (#15362)
Now that `if let` chains have been introduced, the `if_chain` external crate is no longer necessary. Dropping special support for it also alleviates the need to keep the crate as a dependency in tests. This is a cleanup PR. changelog: none
2 parents fab7eab + 4f1044a commit 94b7035

File tree

8 files changed

+14
-37
lines changed

8 files changed

+14
-37
lines changed

clippy_lints/src/index_refutable_slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::higher::IfLet;
55
use clippy_utils::msrvs::{self, Msrv};
66
use clippy_utils::ty::is_copy;
7-
use clippy_utils::{is_expn_of, is_lint_allowed, path_to_local, sym};
7+
use clippy_utils::{is_lint_allowed, path_to_local};
88
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
99
use rustc_errors::Applicability;
1010
use rustc_hir as hir;
@@ -71,7 +71,7 @@ impl_lint_pass!(IndexRefutableSlice => [INDEX_REFUTABLE_SLICE]);
7171
impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice {
7272
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
7373
if let Some(IfLet { let_pat, if_then, .. }) = IfLet::hir(cx, expr)
74-
&& (!expr.span.from_expansion() || is_expn_of(expr.span, sym::if_chain).is_some())
74+
&& !expr.span.from_expansion()
7575
&& !is_lint_allowed(cx, INDEX_REFUTABLE_SLICE, expr.hir_id)
7676
&& let found_slices = find_slice_values(cx, let_pat)
7777
&& !found_slices.is_empty()

clippy_test_deps/Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clippy_test_deps/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ edition = "2021"
99
libc = "0.2"
1010
regex = "1.5.5"
1111
serde = { version = "1.0.145", features = ["derive"] }
12-
if_chain = "1.0"
1312
quote = "1.0.25"
1413
syn = { version = "2.0", features = ["full"] }
1514
futures = "0.3"

clippy_utils/src/sym.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ generate! {
171171
has_significant_drop,
172172
hidden_glob_reexports,
173173
hygiene,
174-
if_chain,
175174
insert,
176175
inspect,
177176
int_roundings,

tests/compile-test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ fn internal_extern_flags() -> Vec<String> {
7373
&& INTERNAL_TEST_DEPENDENCIES.contains(&name)
7474
{
7575
// A dependency may be listed twice if it is available in sysroot,
76-
// and the sysroot dependencies are listed first. As of the writing,
77-
// this only seems to apply to if_chain.
76+
// and the sysroot dependencies are listed first.
7877
crates.insert(name, path);
7978
}
8079
}
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#![deny(clippy::index_refutable_slice)]
22

3-
extern crate if_chain;
4-
use if_chain::if_chain;
5-
63
macro_rules! if_let_slice_macro {
74
() => {
85
// This would normally be linted
@@ -18,12 +15,9 @@ fn main() {
1815
if_let_slice_macro!();
1916

2017
// Do lint this
21-
if_chain! {
22-
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
23-
if let Some([slice_0, ..]) = slice;
18+
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
19+
if let Some([slice_0, ..]) = slice {
2420
//~^ ERROR: this binding can be a slice pattern to avoid indexing
25-
then {
26-
println!("{}", slice_0);
27-
}
21+
println!("{}", slice_0);
2822
}
2923
}
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#![deny(clippy::index_refutable_slice)]
22

3-
extern crate if_chain;
4-
use if_chain::if_chain;
5-
63
macro_rules! if_let_slice_macro {
74
() => {
85
// This would normally be linted
@@ -18,12 +15,9 @@ fn main() {
1815
if_let_slice_macro!();
1916

2017
// Do lint this
21-
if_chain! {
22-
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
23-
if let Some(slice) = slice;
18+
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
19+
if let Some(slice) = slice {
2420
//~^ ERROR: this binding can be a slice pattern to avoid indexing
25-
then {
26-
println!("{}", slice[0]);
27-
}
21+
println!("{}", slice[0]);
2822
}
2923
}

tests/ui/index_refutable_slice/slice_indexing_in_macro.stderr

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: this binding can be a slice pattern to avoid indexing
2-
--> tests/ui/index_refutable_slice/slice_indexing_in_macro.rs:23:21
2+
--> tests/ui/index_refutable_slice/slice_indexing_in_macro.rs:19:17
33
|
4-
LL | if let Some(slice) = slice;
5-
| ^^^^^
4+
LL | if let Some(slice) = slice {
5+
| ^^^^^
66
|
77
note: the lint level is defined here
88
--> tests/ui/index_refutable_slice/slice_indexing_in_macro.rs:1:9
@@ -11,10 +11,9 @@ LL | #![deny(clippy::index_refutable_slice)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
help: replace the binding and indexed access with a slice pattern
1313
|
14-
LL ~ if let Some([slice_0, ..]) = slice;
14+
LL ~ if let Some([slice_0, ..]) = slice {
1515
LL |
16-
LL | then {
17-
LL ~ println!("{}", slice_0);
16+
LL ~ println!("{}", slice_0);
1817
|
1918

2019
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)