blob: 5b76cf78f069da72299ba8cc04be8c3e3448584b [file] [log] [blame]
#![warn(clippy::str_to_string)]
fn main() {
let hello = "hello world".to_owned();
//~^ str_to_string
let msg = &hello[..];
msg.to_owned();
//~^ str_to_string
}
fn issue16271(key: &[u8]) {
macro_rules! t {
($e:expr) => {
match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
}
};
}
let _value = t!(str::from_utf8(key)).to_owned();
//~^ str_to_string
}
struct GenericWrapper<T>(T);
impl<T> GenericWrapper<T> {
fn mapper<U, F: FnOnce(T) -> U>(self, f: F) -> U {
f(self.0)
}
}
fn issue16511(x: Option<&str>) {
let _ = x.map(ToOwned::to_owned);
//~^ str_to_string
let _ = x.map(ToOwned::to_owned);
//~^ str_to_string
let _ = ["a", "b"].iter().map(ToOwned::to_owned);
//~^ str_to_string
fn mapper<F: Fn(&str) -> String>(f: F) -> String {
f("hello")
}
let _ = mapper(ToOwned::to_owned);
//~^ str_to_string
let w = GenericWrapper("hello");
let _ = w.mapper(ToOwned::to_owned);
//~^ str_to_string
}