Skip to content

Commit c419d0a

Browse files
committed
Auto merge of rust-lang#9136 - smoelius:enhance-needless-borrow, r=Jarcho
Enhance `needless_borrow` to consider trait implementations The proposed enhancement causes `needless_borrow` to suggest removing `&` from `&e` when `&e` is an argument position requiring trait implementations, and `e` implements the required traits. Example: ``` error: the borrowed expression implements the required traits --> $DIR/needless_borrow.rs:131:51 | LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); | ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]` ``` r? `@Jarcho` changelog: Enhance `needless_borrow` to consider trait implementations
2 parents 849c1c0 + 032f112 commit c419d0a

19 files changed

+585
-78
lines changed

clippy_dev/src/bless.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn update_reference_file(test_output_entry: &DirEntry, ignore_timestamp: bool) {
3737
return;
3838
}
3939

40-
let test_output_file = fs::read(&test_output_path).expect("Unable to read test output file");
40+
let test_output_file = fs::read(test_output_path).expect("Unable to read test output file");
4141
let reference_file = fs::read(&reference_file_path).unwrap_or_default();
4242

4343
if test_output_file != reference_file {

clippy_dev/src/fmt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn run(check: bool, verbose: bool) {
4646
// dependency
4747
if fs::read_to_string(project_root.join("Cargo.toml"))
4848
.expect("Failed to read clippy Cargo.toml")
49-
.contains(&"[target.'cfg(NOT_A_PLATFORM)'.dependencies]")
49+
.contains("[target.'cfg(NOT_A_PLATFORM)'.dependencies]")
5050
{
5151
return Err(CliError::IntellijSetupActive);
5252
}
@@ -193,10 +193,10 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
193193
let args = &["--version"];
194194

195195
if context.verbose {
196-
println!("{}", format_command(&program, &dir, args));
196+
println!("{}", format_command(program, &dir, args));
197197
}
198198

199-
let output = Command::new(&program).current_dir(&dir).args(args.iter()).output()?;
199+
let output = Command::new(program).current_dir(&dir).args(args.iter()).output()?;
200200

201201
if output.status.success() {
202202
Ok(())
@@ -207,7 +207,7 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
207207
Err(CliError::RustfmtNotInstalled)
208208
} else {
209209
Err(CliError::CommandFailed(
210-
format_command(&program, &dir, args),
210+
format_command(program, &dir, args),
211211
std::str::from_utf8(&output.stderr).unwrap_or("").to_string(),
212212
))
213213
}

clippy_dev/src/update_lints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec<Lint>) -> io
418418
.expect("failed to find `impl_lint_pass` terminator");
419419

420420
impl_lint_pass_end += impl_lint_pass_start;
421-
if let Some(lint_name_pos) = content[impl_lint_pass_start..impl_lint_pass_end].find(&lint_name_upper) {
421+
if let Some(lint_name_pos) = content[impl_lint_pass_start..impl_lint_pass_end].find(lint_name_upper) {
422422
let mut lint_name_end = impl_lint_pass_start + (lint_name_pos + lint_name_upper.len());
423423
for c in content[lint_name_end..impl_lint_pass_end].chars() {
424424
// Remove trailing whitespace
@@ -451,7 +451,7 @@ fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec<Lint>) -> io
451451
}
452452

453453
let mut content =
454-
fs::read_to_string(&path).unwrap_or_else(|_| panic!("failed to read `{}`", path.to_string_lossy()));
454+
fs::read_to_string(path).unwrap_or_else(|_| panic!("failed to read `{}`", path.to_string_lossy()));
455455

456456
eprintln!(
457457
"warn: you will have to manually remove any code related to `{}` from `{}`",

0 commit comments

Comments
 (0)