Skip to content

Conversation

@samueltardieu
Copy link
Member

&str already implements AsRef<[u8]>

changelog: none

`&str` already implements `AsRef<[u8]>`
@rustbot
Copy link
Collaborator

rustbot commented Jul 1, 2025

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 1, 2025
@dswij dswij added this pull request to the merge queue Jul 3, 2025
Merged via the queue into rust-lang:master with commit b631cef Jul 3, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 3, 2025
@samueltardieu samueltardieu deleted the push-oopuxpwzumzs branch July 4, 2025 10:31
@smoelius
Copy link
Contributor

smoelius commented Jul 6, 2025

Dylint has an unnecessary_conversion_for_trait lint that suggests this and other similar, possible improvements (see below). I would be willing to donate it to Clippy. Would Clippy want it?

I understand that the lint would need to undergo the standard review process, that this would likely require changes, and that the review would not take place until the feature freeze has ended.

Warnings generated at commit 0450db3
$ find . -name Cargo.toml | xargs -n 1 cargo dylint --git https://github.com/trailofbits/dylint --pattern examples/supplementary/unnecessary_conversion_for_trait -- --manifes
t-path 2>&1 | grep -v 'no edition set' | grep -A 5 '^warning:'
warning: the receiver implements the required traits
   --> lintcheck/src/main.rs:177:55
    |
177 |             .env("CARGO_TARGET_DIR", shared_target_dir.as_os_str())
    |                                                       ^^^^^^^^^^^^ help: remove this
    |
--
warning: `lintcheck` (bin "lintcheck") generated 1 warning (run `cargo fix --bin "lintcheck"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
Building workspace metadata entry `unnecessary_conversion_for_trait`
    Finished `release` profile [optimized] target(s) in 0.08s
Checking with toolchain `nightly-2025-05-14-x86_64-unknown-linux-gnu`
warning: the receiver implements the required traits
   --> clippy_dev/src/fmt.rs:255:25
    |
255 |         fs::write(path, new_text.as_bytes())?;
    |                         ^^^^^^^^^^^^^^^^^^^ help: use: `&new_text`
    |
--
warning: the receiver implements the required traits
   --> clippy_dev/src/fmt.rs:352:19
    |
352 |         .args(args.iter())
    |                   ^^^^^^^ help: remove this

warning: the receiver implements the required traits
   --> clippy_dev/src/fmt.rs:387:67
    |
387 |     let output = Command::new(program).current_dir(&dir).args(args.iter()).output()?;
    |                                                                   ^^^^^^^ help: remove this

warning: the receiver implements the required traits
  --> clippy_dev/src/new_lint.rs:98:32
   |
98 |         write_file(&lint_path, lint_contents.as_bytes())?;
   |                                ^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `&lint_contents`

warning: the receiver implements the required traits
   --> clippy_dev/src/new_lint.rs:436:16
    |
436 |     write_file(lint_file_path.as_path(), lint_file_contents)?;
    |                ^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `&lint_file_path`

warning: `clippy_dev` (lib) generated 5 warnings (run `cargo fix --lib -p clippy_dev` to apply 5 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s
Building workspace metadata entry `unnecessary_conversion_for_trait`
    Finished `release` profile [optimized] target(s) in 0.08s
Checking with toolchain `nightly-2025-05-14-x86_64-unknown-linux-gnu`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s
--
warning: the receiver implements the required traits
   --> src/sugg.rs:672:43
    |
672 |             self.span_suggestion(span, msg.to_string(), format!("{attr}\n{indent}"), applicability);
    |                                           ^^^^^^^^^^^^ help: remove this
    |
--
warning: the receiver implements the required traits
   --> src/sugg.rs:693:43
    |
693 |             self.span_suggestion(span, msg.to_string(), format!("{new_item}\n{indent}"), applicability);
    |                                           ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
   --> src/sugg.rs:710:46
    |
710 |         self.span_suggestion(remove_span, msg.to_string(), "", applicability);
    |                                              ^^^^^^^^^^^^ help: remove this

warning: `clippy_utils` (lib) generated 3 warnings (run `cargo fix --lib -p clippy_utils` to apply 3 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
Building workspace metadata entry `unnecessary_conversion_for_trait`
    Finished `release` profile [optimized] target(s) in 0.08s
Checking with toolchain `nightly-2025-05-14-x86_64-unknown-linux-gnu`
warning: the receiver implements the required traits
  --> src/almost_complete_range.rs:63:34
   |
63 | ...                   "..=".to_owned(),
   |                            ^^^^^^^^^^^ help: remove this
   |
--
warning: the receiver implements the required traits
   --> src/matches/single_match.rs:130:51
    |
130 |             diag.span_suggestion(expr.span, help, sugg.to_string(), app);
    |                                                   ^^^^^^^^^^^^^^^^ help: use: `&sugg`

warning: the receiver implements the required traits
   --> src/matches/single_match.rs:186:48
    |
186 |         diag.span_suggestion(expr.span, "try", sugg.to_string(), app);
    |                                                ^^^^^^^^^^^^^^^^ help: use: `&sugg`

warning: the receiver implements the required traits
   --> src/matches/single_match.rs:400:21
    |
400 |                 pats.iter(),
    |                     ^^^^^^^ help: remove this

warning: the receiver implements the required traits
   --> src/methods/open_options.rs:192:38
    |
192 |                     ".truncate(true)".to_string(),
    |                                      ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
  --> src/methods/vec_resize_to_zero.rs:42:30
   |
42 |                     "clear()".to_string(),
   |                              ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
   --> src/misc.rs:295:44
    |
295 |             "used underscore-prefixed item".to_string(),
    |                                            ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
   --> src/misc.rs:297:71
    |
297 |                 diag.span_note(definition_span, "item is defined here".to_string());
    |                                                                       ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
   --> src/misc.rs:340:47
    |
340 |             "used underscore-prefixed binding".to_string(),
    |                                               ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
   --> src/misc.rs:342:74
    |
342 |                 diag.span_note(definition_span, "binding is defined here".to_string());
    |                                                                          ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
  --> src/misc_early/zero_prefixed_literal.rs:19:33
   |
19 |                 trimmed_lit_snip.to_string(),
   |                                 ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
   --> src/needless_pass_by_ref_mut.rs:282:55
    |
282 | ...                   "consider changing to".to_string(),
    |                                             ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
  --> src/redundant_pub_crate.rs:69:30
   |
69 |                         "pub".to_string(),
   |                              ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
   --> src/std_instead_of_core.rs:147:41
    |
147 | ...                   replace_with.to_string(),
    |                                   ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
  --> src/transmute/transmute_int_to_bool.rs:33:25
   |
33 |                         sugg::make_binop(ast::BinOpKind::Ne, &arg, &zero).to_string(),
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `&sugg::make_binop(ast::BinOpKind::Ne, &arg, &zero)`

warning: the receiver implements the required traits
  --> src/transmute/transmutes_expressible_as_ptr_casts.rs:29:29
   |
29 |                 .as_ty(to_ty.to_string())
   |                             ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
  --> src/transmute/transmutes_expressible_as_ptr_casts.rs:33:25
   |
33 |             .as_ty(to_ty.to_string())
   |                         ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
  --> src/transmute/useless_transmute.rs:59:76
   |
59 |                         diag.span_suggestion(e.span, "try", arg.as_ty(to_ty.to_string()), Applicability::Unspecified);
   |                                                                            ^^^^^^^^^^^^ help: remove this

warning: the receiver implements the required traits
  --> src/unnecessary_box_returns.rs:95:33
   |
95 |                         boxed_ty.to_string(),
   |                                 ^^^^^^^^^^^^ help: remove this

warning: `clippy_lints` (lib) generated 19 warnings (run `cargo fix --lib -p clippy_lints` to apply 19 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s
Building workspace metadata entry `unnecessary_conversion_for_trait`
    Finished `release` profile [optimized] target(s) in 0.08s
Checking with toolchain `nightly-2025-05-14-x86_64-unknown-linux-gnu`
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
--
warning: the inner argument implements the required traits
   --> src/driver.rs:229:29
    |
229 |                 args.extend(vec!["--sysroot".into(), sys_root]);
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
--
warning: `clippy` (bin "clippy-driver") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s

@dswij
Copy link
Member

dswij commented Jul 6, 2025

That'd be highly welcomed! @smoelius

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants