Skip to content

Commit 85441ab

Browse files
committed
Convert redundant_clone to an analysis pass
1 parent 9e2c054 commit 85441ab

13 files changed

+2761
-1137
lines changed

clippy_lints/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ edition = "2024"
1212
arrayvec = { version = "0.7", default-features = false }
1313
cargo_metadata = "0.18"
1414
clippy_config = { path = "../clippy_config" }
15+
clippy_data_structures = { path = "../clippy_data_structures" }
16+
clippy_mir = { path = "../clippy_mir" }
1517
clippy_utils = { path = "../clippy_utils" }
1618
declare_clippy_lint = { path = "../declare_clippy_lint" }
1719
itertools = "0.12"

clippy_lints/src/assigning_clones.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn clone_source_borrows_from_dest(cx: &LateContext<'_>, lhs: &Expr<'_>, call_spa
155155
let Some(mir) = enclosing_mir(cx.tcx, lhs.hir_id) else {
156156
return false;
157157
};
158-
let PossibleBorrowerMap { map: borrow_map, .. } = PossibleBorrowerMap::new(cx, mir);
158+
let PossibleBorrowerMap { map: borrow_map, .. } = PossibleBorrowerMap::new(cx.tcx, cx.typing_env(), mir);
159159

160160
// The operation `dest = src.to_owned()` in MIR is split up across 3 blocks *if* the type has `Drop`
161161
// code. For types that don't, the second basic block is simply skipped.

clippy_lints/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#![feature(array_chunks)]
12
#![feature(array_windows)]
23
#![feature(box_patterns)]
4+
#![feature(cmp_minmax)]
35
#![feature(macro_metavar_expr_concat)]
46
#![feature(f128)]
57
#![feature(f16)]
@@ -30,6 +32,7 @@
3032

3133
// FIXME: switch to something more ergonomic here, once available.
3234
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
35+
extern crate indexmap;
3336
extern crate pulldown_cmark;
3437
extern crate rustc_abi;
3538
extern crate rustc_arena;
@@ -48,6 +51,7 @@ extern crate rustc_infer;
4851
extern crate rustc_lexer;
4952
extern crate rustc_lint;
5053
extern crate rustc_middle;
54+
extern crate rustc_mir_dataflow;
5155
extern crate rustc_parse;
5256
extern crate rustc_parse_format;
5357
extern crate rustc_resolve;

clippy_lints/src/needless_borrows_for_generic_args.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,10 @@ fn referent_used_exactly_once<'tcx>(
364364
.last()
365365
.is_none_or(|&(local_def_id, _)| local_def_id != body_owner_local_def_id)
366366
{
367-
possible_borrowers.push((body_owner_local_def_id, PossibleBorrowerMap::new(cx, mir)));
367+
possible_borrowers.push((
368+
body_owner_local_def_id,
369+
PossibleBorrowerMap::new(cx.tcx, cx.typing_env(), mir),
370+
));
368371
}
369372
let possible_borrower = &mut possible_borrowers.last_mut().unwrap().1;
370373
// If `only_borrowers` were used here, the `copyable_iterator::warn` test would fail. The reason is

0 commit comments

Comments
 (0)