Skip to content

Bad suggestion for clone in field init shorthand #108470

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

Closed
ehuss opened this issue Feb 25, 2023 · 0 comments · Fixed by #109355
Closed

Bad suggestion for clone in field init shorthand #108470

ehuss opened this issue Feb 25, 2023 · 0 comments · Fixed by #109355
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Feb 25, 2023

Code

struct Foo {
    t: Thing
}

#[derive(Clone)]
struct Thing;

fn main() {
    let t = &Thing;
    let f = Foo {
        t
    };
}

Current output

error[E0308]: mismatched types
  --> src/main.rs:11:9
   |
11 |         t
   |         ^ expected `Thing`, found `&Thing`
   |
help: consider using clone here
   |
11 |         t.clone()
   |          ++++++++

Desired output

error[E0308]: mismatched types
  --> src/main.rs:11:9
   |
11 |         t
   |         ^ expected `Thing`, found `&Thing`
   |
help: consider using clone here
   |
11 |         t: t.clone()
   |         ++  ++++++++

Rationale and extra context

The suggestion is not compatible with struct field init shorthand syntax. The suggestion should include the field name when rewriting.

Other cases

No response

Anything else?

rustc 1.69.0-nightly (c5c7d2b37 2023-02-24)
binary: rustc
commit-hash: c5c7d2b37780dac1092e75f12ab97dd56c30861d
commit-date: 2023-02-24
host: aarch64-apple-darwin
release: 1.69.0-nightly
LLVM version: 15.0.7
@ehuss ehuss added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Feb 25, 2023
@chenyukang chenyukang self-assigned this Mar 1, 2023
@bors bors closed this as completed in f3d3f35 Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants