diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index f404d3434390..92dc330779f5 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -202,6 +202,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue { // Dereference suggestion let sugg = |db: &mut DiagnosticBuilder| { + if let ty::TypeVariants::TyAdt(ref def, ..) = ty.sty { + if let Some(span) = cx.tcx.hir.span_if_local(def.did) { + // FIXME (#2374) Restrict this to types which can impl Copy + db.span_help(span, "consider marking this type as Copy if possible"); + } + } + let deref_span = spans_need_deref.get(&canonical_id); if_chain! { if match_type(cx, ty, &paths::VEC); diff --git a/tests/ui/needless_pass_by_value.stderr b/tests/ui/needless_pass_by_value.stderr index 33bda7d98724..441a9095b6a0 100644 --- a/tests/ui/needless_pass_by_value.stderr +++ b/tests/ui/needless_pass_by_value.stderr @@ -17,6 +17,12 @@ error: this argument is passed by value, but not consumed in the function body | 26 | fn bar(x: String, y: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` + | +help: consider marking this type as Copy if possible + --> $DIR/needless_pass_by_value.rs:24:1 + | +24 | struct Wrapper(String); + | ^^^^^^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body --> $DIR/needless_pass_by_value.rs:32:71 @@ -40,12 +46,24 @@ error: this argument is passed by value, but not consumed in the function body | 57 | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ help: consider taking a reference instead: `&Wrapper` + | +help: consider marking this type as Copy if possible + --> $DIR/needless_pass_by_value.rs:24:1 + | +24 | struct Wrapper(String); + | ^^^^^^^^^^^^^^^^^^^^^^^ error: this argument is passed by value, but not consumed in the function body --> $DIR/needless_pass_by_value.rs:57:36 | 57 | fn test_destructure(x: Wrapper, y: Wrapper, z: Wrapper) { | ^^^^^^^ + | +help: consider marking this type as Copy if possible + --> $DIR/needless_pass_by_value.rs:24:1 + | +24 | struct Wrapper(String); + | ^^^^^^^^^^^^^^^^^^^^^^^ help: consider taking a reference instead | 57 | fn test_destructure(x: Wrapper, y: &Wrapper, z: Wrapper) { @@ -123,6 +141,12 @@ error: this argument is passed by value, but not consumed in the function body | 101 | _s: Self, | ^^^^ help: consider taking a reference instead: `&Self` + | +help: consider marking this type as Copy if possible + --> $DIR/needless_pass_by_value.rs:82:1 + | +82 | struct S(T, U); + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 16 previous errors