Skip to content

Suggest .clone() when we have &T, T was expected and T: Clone #106443

Closed
@estebank

Description

@estebank

Given

#[derive(Clone)]
struct S;
fn foo(_: S) {}
fn main() {
    let s = &S;
    foo(s);
}

we should suggest cloning.

Also, given

#[derive(Clone)]
struct S;
trait X {}
impl X for S {}
fn foo<T: X>(_: T) {}
fn bar<T: X>(s: &T) {
    foo(s);
}
fn main() {}

we should suggest

fn bar<T: X + Clone>(s: &T) {
    foo(s.clone());
}

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-papercutDiagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions