Skip to content

Conversation

samueltardieu
Copy link
Member

@samueltardieu samueltardieu commented Sep 21, 2025

Starting with Rust version 1.82.0, the compiler generates similar code with and without the with_ref cfg:

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.

changelog: [inefficient_to_string]: do not trigger for Rust ≥ 1.82.0

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 21, 2025

r? @dswij

rustbot has assigned @dswij.
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

Copy link

github-actions bot commented Sep 21, 2025

Lintcheck changes for 951d35e

Lint Added Removed Changed
clippy::inefficient_to_string 0 5 0

This comment will be updated if you push new changes

@Jarcho
Copy link
Contributor

Jarcho commented Sep 21, 2025

This was fixed in 1.82. I wouldn't deprecate it, but MSRV gating it should be fine.

@samueltardieu samueltardieu force-pushed the features/deprecate-inefficient-to-string branch from b48e9ea to 0567bd5 Compare September 23, 2025 22:46
@samueltardieu samueltardieu changed the title Deprecate inefficient_to_string Do not trigger inefficient_to_string after Rust 1.82 Sep 23, 2025
@samueltardieu
Copy link
Member Author

Code, description, and title updated to not trigger the lint starting from Rust 1.82.0.

r? Jarcho since you suggested this

@rustbot rustbot assigned Jarcho and unassigned dswij Sep 23, 2025
@Jarcho
Copy link
Contributor

Jarcho commented Sep 25, 2025

cc @rust-lang/clippy

I'll wait and see if anyone else has anything to say before merging. This is the opposite of how we use MSRV everywhere else, but it makes sense with how the lint is useless after a specific version.

@samueltardieu samueltardieu requested a review from Jarcho October 1, 2025 20:49
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.
@samueltardieu samueltardieu force-pushed the features/deprecate-inefficient-to-string branch from 0567bd5 to 951d35e Compare October 1, 2025 21:13
Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jarcho Jarcho added this pull request to the merge queue Oct 1, 2025
Merged via the queue into rust-lang:master with commit 6cc8f8d Oct 1, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 1, 2025
@samueltardieu samueltardieu deleted the features/deprecate-inefficient-to-string branch October 1, 2025 22:20
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.

4 participants