You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do not trigger inefficient_to_string after Rust 1.82
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.
| ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstr).to_string()`
19
19
|
20
20
= help: `&&str` implements `ToString` through a slower blanket impl, but `str` has a fast specialization of `ToString`
21
21
22
22
error: calling `to_string` on `&&std::string::String`
23
-
--> tests/ui/inefficient_to_string.rs:21:21
23
+
--> tests/ui/inefficient_to_string.rs:22:21
24
24
|
25
25
LL | let _: String = rrstring.to_string();
26
26
| ^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstring).to_string()`
27
27
|
28
28
= help: `&std::string::String` implements `ToString` through a slower blanket impl, but `std::string::String` has a fast specialization of `ToString`
29
29
30
30
error: calling `to_string` on `&&&std::string::String`
31
-
--> tests/ui/inefficient_to_string.rs:23:21
31
+
--> tests/ui/inefficient_to_string.rs:24:21
32
32
|
33
33
LL | let _: String = rrrstring.to_string();
34
34
| ^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstring).to_string()`
35
35
|
36
36
= help: `&&std::string::String` implements `ToString` through a slower blanket impl, but `std::string::String` has a fast specialization of `ToString`
37
37
38
38
error: calling `to_string` on `&&std::borrow::Cow<'_, str>`
39
-
--> tests/ui/inefficient_to_string.rs:32:21
39
+
--> tests/ui/inefficient_to_string.rs:33:21
40
40
|
41
41
LL | let _: String = rrcow.to_string();
42
42
| ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrcow).to_string()`
43
43
|
44
44
= help: `&std::borrow::Cow<'_, str>` implements `ToString` through a slower blanket impl, but `std::borrow::Cow<'_, str>` has a fast specialization of `ToString`
45
45
46
46
error: calling `to_string` on `&&&std::borrow::Cow<'_, str>`
47
-
--> tests/ui/inefficient_to_string.rs:34:21
47
+
--> tests/ui/inefficient_to_string.rs:35:21
48
48
|
49
49
LL | let _: String = rrrcow.to_string();
50
50
| ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrcow).to_string()`
0 commit comments