Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unnecessary_to_owned suggestion cause error when interacting with println! macro #12821

Closed
GitPinkRabbit opened this issue May 19, 2024 · 1 comment · Fixed by #12843
Closed
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@GitPinkRabbit
Copy link

GitPinkRabbit commented May 19, 2024

Summary

Clippy thinks the left curly bracket { in println!("{c}") is an &.

Lint Name

unnecessary_to_owned

Reproducer

I tried this code:

fn main() {
    let v: Vec<_> = "hello".chars().collect();
    for c in v.iter().cloned() {
        println!("{c}");
    }
}

I saw this happen:

warning: unnecessary use of `cloned`
 --> src\main.rs:3:14
  |
3 |     for c in v.iter().cloned() {
  |              ^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_to_owned
  = note: `#[warn(clippy::unnecessary_to_owned)]` on by default
help: use
  |
3 |     for c in v.iter() {
  |              ~~~~~~~~
help: remove this `&`
  |
4 -         println!("{c}");
4 +         println!("c}");
  |

I expected to see this happen:

Do not suggest to remove the &.

Version

rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-pc-windows-msvc
release: 1.75.0
LLVM version: 17.0.6

Additional Labels

@rustbot label I-suggestion-causes-error

@GitPinkRabbit GitPinkRabbit added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 19, 2024
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label May 19, 2024
@mdm
Copy link
Contributor

mdm commented May 20, 2024

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants