mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
needless_pass_by_value: Add suggestion for implementing Copy (fixes #2222)
This commit is contained in:
parent
cf1fbaa36a
commit
2a30c8a194
2 changed files with 31 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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>(T, U);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue