Skip to content

Do not specialize for if_chain any longer #15362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clippy_lints/src/index_refutable_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::higher::IfLet;
use clippy_utils::msrvs::{self, Msrv};
use clippy_utils::ty::is_copy;
use clippy_utils::{is_expn_of, is_lint_allowed, path_to_local, sym};
use clippy_utils::{is_lint_allowed, path_to_local};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_errors::Applicability;
use rustc_hir as hir;
Expand Down Expand Up @@ -71,7 +71,7 @@ impl_lint_pass!(IndexRefutableSlice => [INDEX_REFUTABLE_SLICE]);
impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
if let Some(IfLet { let_pat, if_then, .. }) = IfLet::hir(cx, expr)
&& (!expr.span.from_expansion() || is_expn_of(expr.span, sym::if_chain).is_some())
&& !expr.span.from_expansion()
&& !is_lint_allowed(cx, INDEX_REFUTABLE_SLICE, expr.hir_id)
&& let found_slices = find_slice_values(cx, let_pat)
&& !found_slices.is_empty()
Expand Down
7 changes: 0 additions & 7 deletions clippy_test_deps/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion clippy_test_deps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = "2021"
libc = "0.2"
regex = "1.5.5"
serde = { version = "1.0.145", features = ["derive"] }
if_chain = "1.0"
quote = "1.0.25"
syn = { version = "2.0", features = ["full"] }
futures = "0.3"
Expand Down
1 change: 0 additions & 1 deletion clippy_utils/src/sym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ generate! {
has_significant_drop,
hidden_glob_reexports,
hygiene,
if_chain,
insert,
inspect,
int_roundings,
Expand Down
3 changes: 1 addition & 2 deletions tests/compile-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ fn internal_extern_flags() -> Vec<String> {
&& INTERNAL_TEST_DEPENDENCIES.contains(&name)
{
// A dependency may be listed twice if it is available in sysroot,
// and the sysroot dependencies are listed first. As of the writing,
// this only seems to apply to if_chain.
// and the sysroot dependencies are listed first.
crates.insert(name, path);
}
}
Expand Down
12 changes: 3 additions & 9 deletions tests/ui/index_refutable_slice/slice_indexing_in_macro.fixed
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#![deny(clippy::index_refutable_slice)]

extern crate if_chain;
use if_chain::if_chain;

macro_rules! if_let_slice_macro {
() => {
// This would normally be linted
Expand All @@ -18,12 +15,9 @@ fn main() {
if_let_slice_macro!();

// Do lint this
if_chain! {
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
if let Some([slice_0, ..]) = slice;
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
if let Some([slice_0, ..]) = slice {
//~^ ERROR: this binding can be a slice pattern to avoid indexing
then {
println!("{}", slice_0);
}
println!("{}", slice_0);
}
}
12 changes: 3 additions & 9 deletions tests/ui/index_refutable_slice/slice_indexing_in_macro.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#![deny(clippy::index_refutable_slice)]

extern crate if_chain;
use if_chain::if_chain;

macro_rules! if_let_slice_macro {
() => {
// This would normally be linted
Expand All @@ -18,12 +15,9 @@ fn main() {
if_let_slice_macro!();

// Do lint this
if_chain! {
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
if let Some(slice) = slice;
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
if let Some(slice) = slice {
//~^ ERROR: this binding can be a slice pattern to avoid indexing
then {
println!("{}", slice[0]);
}
println!("{}", slice[0]);
}
}
11 changes: 5 additions & 6 deletions tests/ui/index_refutable_slice/slice_indexing_in_macro.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: this binding can be a slice pattern to avoid indexing
--> tests/ui/index_refutable_slice/slice_indexing_in_macro.rs:23:21
--> tests/ui/index_refutable_slice/slice_indexing_in_macro.rs:19:17
|
LL | if let Some(slice) = slice;
| ^^^^^
LL | if let Some(slice) = slice {
| ^^^^^
|
note: the lint level is defined here
--> tests/ui/index_refutable_slice/slice_indexing_in_macro.rs:1:9
Expand All @@ -11,10 +11,9 @@ LL | #![deny(clippy::index_refutable_slice)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: replace the binding and indexed access with a slice pattern
|
LL ~ if let Some([slice_0, ..]) = slice;
LL ~ if let Some([slice_0, ..]) = slice {
LL |
LL | then {
LL ~ println!("{}", slice_0);
LL ~ println!("{}", slice_0);
|

error: aborting due to 1 previous error
Expand Down