Skip to content

Commit

Permalink
Auto merge of rust-lang#9136 - smoelius:enhance-needless-borrow, r=Ja…
Browse files Browse the repository at this point in the history
…rcho

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
  • Loading branch information
bors committed Aug 18, 2022
2 parents 849c1c0 + 032f112 commit c419d0a
Show file tree
Hide file tree
Showing 19 changed files with 585 additions and 78 deletions.
2 changes: 1 addition & 1 deletion clippy_dev/src/bless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn update_reference_file(test_output_entry: &DirEntry, ignore_timestamp: bool) {
return;
}

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

if test_output_file != reference_file {
Expand Down
8 changes: 4 additions & 4 deletions clippy_dev/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn run(check: bool, verbose: bool) {
// dependency
if fs::read_to_string(project_root.join("Cargo.toml"))
.expect("Failed to read clippy Cargo.toml")
.contains(&"[target.'cfg(NOT_A_PLATFORM)'.dependencies]")
.contains("[target.'cfg(NOT_A_PLATFORM)'.dependencies]")
{
return Err(CliError::IntellijSetupActive);
}
Expand Down Expand Up @@ -193,10 +193,10 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
let args = &["--version"];

if context.verbose {
println!("{}", format_command(&program, &dir, args));
println!("{}", format_command(program, &dir, args));
}

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

if output.status.success() {
Ok(())
Expand All @@ -207,7 +207,7 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
Err(CliError::RustfmtNotInstalled)
} else {
Err(CliError::CommandFailed(
format_command(&program, &dir, args),
format_command(program, &dir, args),
std::str::from_utf8(&output.stderr).unwrap_or("").to_string(),
))
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ fn remove_lint_declaration(name: &str, path: &Path, lints: &mut Vec<Lint>) -> io
.expect("failed to find `impl_lint_pass` terminator");

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

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

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

0 comments on commit c419d0a

Please sign in to comment.