mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 13:05:18 +03:00
951d35eeb6
Starting with Rust version 1.82.0, the compiler generates similar code with
and without the `with_ref` cfg:
```rust
fn f(x: impl IntoIterator<Item = String>) {
for y in x { println!("{y}"); }
}
fn main() {
#[cfg(with_ref)]
let a = ["foo", "bar"].iter().map(|&s| s.to_string());
#[cfg(not(with_ref))]
let a = ["foo", "bar"].iter().map(|s| s.to_string());
f(a);
}
```
The generated code is strictly identical with `-O`, and identical modulo
some minor reordering without.
45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
#![deny(clippy::inefficient_to_string)]
|
|
|
|
use std::borrow::Cow;
|
|
|
|
#[clippy::msrv = "1.81"]
|
|
fn main() {
|
|
let rstr: &str = "hello";
|
|
let rrstr: &&str = &rstr;
|
|
let rrrstr: &&&str = &rrstr;
|
|
let _: String = rstr.to_string();
|
|
let _: String = (*rrstr).to_string();
|
|
//~^ inefficient_to_string
|
|
let _: String = (**rrrstr).to_string();
|
|
//~^ inefficient_to_string
|
|
|
|
let string: String = String::from("hello");
|
|
let rstring: &String = &string;
|
|
let rrstring: &&String = &rstring;
|
|
let rrrstring: &&&String = &rrstring;
|
|
let _: String = string.to_string();
|
|
let _: String = rstring.to_string();
|
|
let _: String = (*rrstring).to_string();
|
|
//~^ inefficient_to_string
|
|
let _: String = (**rrrstring).to_string();
|
|
//~^ inefficient_to_string
|
|
|
|
let cow: Cow<'_, str> = Cow::Borrowed("hello");
|
|
let rcow: &Cow<'_, str> = &cow;
|
|
let rrcow: &&Cow<'_, str> = &rcow;
|
|
let rrrcow: &&&Cow<'_, str> = &rrcow;
|
|
let _: String = cow.to_string();
|
|
let _: String = rcow.to_string();
|
|
let _: String = (*rrcow).to_string();
|
|
//~^ inefficient_to_string
|
|
let _: String = (**rrrcow).to_string();
|
|
//~^ inefficient_to_string
|
|
}
|
|
|
|
#[clippy::msrv = "1.82"]
|
|
fn sufficient_msrv() {
|
|
let rstr: &str = "hello";
|
|
let rrstr: &&str = &rstr;
|
|
let _: String = rrstr.to_string();
|
|
}
|