From c81bf49ad622b7f4c637f409ad7b81ccfb018809 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Mon, 28 Oct 2024 11:06:02 +0000 Subject: [PATCH] Update `unnecessary_conversion_for_trait` --- .../src/lib.rs | 2 + .../ui/general.fixed | 3 +- .../ui/general.rs | 3 +- .../ui/general.stderr | 44 +++++++++++-------- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs b/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs index c2c77b979..991ed59e2 100644 --- a/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs +++ b/examples/supplementary/unnecessary_conversion_for_trait/src/lib.rs @@ -102,6 +102,7 @@ const WATCHED_INHERENTS: &[&[&str]] = &[ &["core", "slice", "", "iter"], &["core", "slice", "", "iter_mut"], &["core", "str", "", "as_bytes"], + &["core", "str", "", "as_str"], &["std", "ffi", "os_str", "OsStr", "as_encoded_bytes"], &["std", "ffi", "os_str", "OsStr", "into_os_string"], &["std", "ffi", "os_str", "OsStr", "new"], @@ -131,6 +132,7 @@ const IGNORED_INHERENTS: &[&[&str]] = &[ &["alloc", "string", "String", "from_utf16_lossy"], &["alloc", "string", "String", "from_utf16be_lossy"], &["alloc", "string", "String", "from_utf16le_lossy"], + &["alloc", "string", "String", "from_utf8_lossy_owned"], &["alloc", "string", "String", "leak"], &["alloc", "vec", "Vec", "into_flattened"], &["alloc", "vec", "Vec", "leak"], diff --git a/examples/supplementary/unnecessary_conversion_for_trait/ui/general.fixed b/examples/supplementary/unnecessary_conversion_for_trait/ui/general.fixed index 659e507e4..71005a738 100644 --- a/examples/supplementary/unnecessary_conversion_for_trait/ui/general.fixed +++ b/examples/supplementary/unnecessary_conversion_for_trait/ui/general.fixed @@ -1,7 +1,7 @@ // run-rustfix #![allow(unused_imports, unused_parens)] -// #![feature(os_str_bytes)] +#![feature(str_as_str)] use std::{ borrow::{Borrow, BorrowMut}, @@ -65,6 +65,7 @@ fn main() { let _ = Command::new("ls").args(["-a", "-l"]); let _ = Command::new("ls").args(["-a", "-l"]); + let _ = std::fs::write("x", ""); let _ = std::fs::write("x", ""); let _ = os_str_or_bytes(osstr); diff --git a/examples/supplementary/unnecessary_conversion_for_trait/ui/general.rs b/examples/supplementary/unnecessary_conversion_for_trait/ui/general.rs index b7aa1f7cf..ac5e23ac9 100644 --- a/examples/supplementary/unnecessary_conversion_for_trait/ui/general.rs +++ b/examples/supplementary/unnecessary_conversion_for_trait/ui/general.rs @@ -1,7 +1,7 @@ // run-rustfix #![allow(unused_imports, unused_parens)] -// #![feature(os_str_bytes)] +#![feature(str_as_str)] use std::{ borrow::{Borrow, BorrowMut}, @@ -66,6 +66,7 @@ fn main() { let _ = Command::new("ls").args(["-a", "-l"].iter_mut()); let _ = std::fs::write("x", "".as_bytes()); + let _ = std::fs::write("x", "".as_str()); let _ = os_str_or_bytes(osstr.as_encoded_bytes()); let _ = is_empty_os(osstring.clone().into_boxed_os_str().into_os_string()); diff --git a/examples/supplementary/unnecessary_conversion_for_trait/ui/general.stderr b/examples/supplementary/unnecessary_conversion_for_trait/ui/general.stderr index 6685b3ff7..53da18f27 100644 --- a/examples/supplementary/unnecessary_conversion_for_trait/ui/general.stderr +++ b/examples/supplementary/unnecessary_conversion_for_trait/ui/general.stderr @@ -151,112 +151,118 @@ LL | let _ = std::fs::write("x", "".as_bytes()); | ^^^^^^^^^^^ help: remove this warning: the receiver implements the required traits - --> $DIR/general.rs:70:34 + --> $DIR/general.rs:69:35 + | +LL | let _ = std::fs::write("x", "".as_str()); + | ^^^^^^^^^ help: remove this + +warning: the receiver implements the required traits + --> $DIR/general.rs:71:34 | LL | let _ = os_str_or_bytes(osstr.as_encoded_bytes()); | ^^^^^^^^^^^^^^^^^^^ help: remove this warning: the receiver implements the required traits - --> $DIR/general.rs:71:41 + --> $DIR/general.rs:72:41 | LL | let _ = is_empty_os(osstring.clone().into_boxed_os_str().into_os_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this warning: the inner argument implements the required traits - --> $DIR/general.rs:72:28 + --> $DIR/general.rs:73:28 | LL | let _ = std::fs::write(OsStr::new("x"), ""); | ^^^^^^^^^^^^^^^ help: use: `"x"` warning: the receiver implements the required traits - --> $DIR/general.rs:73:33 + --> $DIR/general.rs:74:33 | LL | let _ = std::fs::write(osstr.to_os_string(), ""); | ^^^^^^^^^^^^^^^ help: remove this warning: the receiver implements the required traits - --> $DIR/general.rs:75:28 + --> $DIR/general.rs:76:28 | LL | let _ = std::fs::write(osstring.as_os_str(), ""); | ^^^^^^^^^^^^^^^^^^^^ help: use: `&osstring` warning: the receiver implements the required traits - --> $DIR/general.rs:76:41 + --> $DIR/general.rs:77:41 | LL | let _ = is_empty_os(osstring.clone().into_boxed_os_str()); | ^^^^^^^^^^^^^^^^^^^^ help: remove this warning: the receiver implements the required traits - --> $DIR/general.rs:77:48 + --> $DIR/general.rs:78:48 | LL | let _ = os_string_or_bytes(osstring.clone().into_encoded_bytes()); | ^^^^^^^^^^^^^^^^^^^^^ help: remove this warning: the receiver implements the required traits - --> $DIR/general.rs:79:46 + --> $DIR/general.rs:80:46 | LL | let _ = std::fs::write(PathBuf::from("x").as_mut_os_str(), ""); | ^^^^^^^^^^^^^^^^ help: remove this warning: the receiver implements the required traits - --> $DIR/general.rs:80:32 + --> $DIR/general.rs:81:32 | LL | let _ = std::fs::write(path.as_os_str(), ""); | ^^^^^^^^^^^^ help: remove this warning: the receiver implements the required traits - --> $DIR/general.rs:81:46 + --> $DIR/general.rs:82:46 | LL | let _ = std::fs::write(PathBuf::from("x").into_boxed_path().into_path_buf(), ""); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this warning: the receiver implements the required traits - --> $DIR/general.rs:82:41 + --> $DIR/general.rs:83:41 | LL | let _ = Command::new("ls").args(path.iter()); | ^^^^^^^ help: remove this warning: the inner argument implements the required traits - --> $DIR/general.rs:83:28 + --> $DIR/general.rs:84:28 | LL | let _ = std::fs::write(Path::new("x"), ""); | ^^^^^^^^^^^^^^ help: use: `"x"` warning: the receiver implements the required traits - --> $DIR/general.rs:84:32 + --> $DIR/general.rs:85:32 | LL | let _ = std::fs::write(path.to_path_buf(), ""); | ^^^^^^^^^^^^^^ help: remove this warning: the receiver implements the required traits - --> $DIR/general.rs:86:28 + --> $DIR/general.rs:87:28 | LL | let _ = std::fs::write(path_buf.as_mut_os_string(), ""); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `&mut path_buf` warning: the receiver implements the required traits - --> $DIR/general.rs:87:28 + --> $DIR/general.rs:88:28 | LL | let _ = std::fs::write(path_buf.as_path(), ""); | ^^^^^^^^^^^^^^^^^^ help: use: `&path_buf` warning: the receiver implements the required traits - --> $DIR/general.rs:88:44 + --> $DIR/general.rs:89:44 | LL | let _ = std::fs::write(path_buf.clone().into_os_string(), ""); | ^^^^^^^^^^^^^^^^^ help: remove this warning: the receiver implements the required traits - --> $DIR/general.rs:90:28 + --> $DIR/general.rs:91:28 | LL | let _ = std::fs::write(tempdir.path(), ""); | ^^^^^^^^^^^^^^ help: use: `&tempdir` warning: the receiver implements the required traits - --> $DIR/general.rs:91:28 + --> $DIR/general.rs:92:28 | LL | let _ = std::fs::write(tempfile.path(), ""); | ^^^^^^^^^^^^^^^ help: use: `&tempfile` -warning: 43 warnings emitted +warning: 44 warnings emitted