Update trivially_copy_pass_by_ref with Trait examples

This commit is contained in:
Wayne Warren 2018-11-20 19:57:53 -06:00
parent 70ca052397
commit 67c32eb2c4
2 changed files with 45 additions and 26 deletions

View file

@ -18,6 +18,11 @@ struct Foo(u32);
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct Bar([u8; 24]); struct Bar([u8; 24]);
#[derive(Copy, Clone)]
pub struct Color {
pub r: u8, pub g: u8, pub b: u8, pub a: u8,
}
struct FooRef<'a> { struct FooRef<'a> {
foo: &'a Foo, foo: &'a Foo,
} }
@ -80,6 +85,20 @@ impl Bar {
} }
} }
trait MyTrait {
fn trait_method(&self, _foo: &Foo);
}
pub trait MyTrait2 {
fn trait_method2(&self, _color: &Color);
}
impl MyTrait for Foo {
fn trait_method(&self, _foo: &Foo) {
unimplemented!()
}
}
fn main() { fn main() {
let (mut foo, bar) = (Foo(0), Bar([0; 24])); let (mut foo, bar) = (Foo(0), Bar([0; 24]));
let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0); let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0);

View file

@ -1,81 +1,81 @@
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:52:11 --> $DIR/trivially_copy_pass_by_ref.rs:57:11
| |
52 | fn bad(x: &u32, y: &Foo, z: &Baz) { 57 | fn bad(x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `u32` | ^^^^ help: consider passing by value instead: `u32`
| |
= note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings` = note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:52:20 --> $DIR/trivially_copy_pass_by_ref.rs:57:20
| |
52 | fn bad(x: &u32, y: &Foo, z: &Baz) { 57 | fn bad(x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `Foo` | ^^^^ help: consider passing by value instead: `Foo`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:52:29 --> $DIR/trivially_copy_pass_by_ref.rs:57:29
| |
52 | fn bad(x: &u32, y: &Foo, z: &Baz) { 57 | fn bad(x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `Baz` | ^^^^ help: consider passing by value instead: `Baz`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:62:12 --> $DIR/trivially_copy_pass_by_ref.rs:67:12
| |
62 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) { 67 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
| ^^^^^ help: consider passing by value instead: `self` | ^^^^^ help: consider passing by value instead: `self`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:62:22 --> $DIR/trivially_copy_pass_by_ref.rs:67:22
| |
62 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) { 67 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `u32` | ^^^^ help: consider passing by value instead: `u32`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:62:31 --> $DIR/trivially_copy_pass_by_ref.rs:67:31
| |
62 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) { 67 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `Foo` | ^^^^ help: consider passing by value instead: `Foo`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:62:40 --> $DIR/trivially_copy_pass_by_ref.rs:67:40
| |
62 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) { 67 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `Baz` | ^^^^ help: consider passing by value instead: `Baz`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:65:16 --> $DIR/trivially_copy_pass_by_ref.rs:70:16
| |
65 | fn bad2(x: &u32, y: &Foo, z: &Baz) { 70 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `u32` | ^^^^ help: consider passing by value instead: `u32`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:65:25 --> $DIR/trivially_copy_pass_by_ref.rs:70:25
| |
65 | fn bad2(x: &u32, y: &Foo, z: &Baz) { 70 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `Foo` | ^^^^ help: consider passing by value instead: `Foo`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:65:34 --> $DIR/trivially_copy_pass_by_ref.rs:70:34
| |
65 | fn bad2(x: &u32, y: &Foo, z: &Baz) { 70 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `Baz` | ^^^^ help: consider passing by value instead: `Baz`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:79:16 --> $DIR/trivially_copy_pass_by_ref.rs:84:16
| |
79 | fn bad2(x: &u32, y: &Foo, z: &Baz) { 84 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `u32` | ^^^^ help: consider passing by value instead: `u32`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:79:25 --> $DIR/trivially_copy_pass_by_ref.rs:84:25
| |
79 | fn bad2(x: &u32, y: &Foo, z: &Baz) { 84 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `Foo` | ^^^^ help: consider passing by value instead: `Foo`
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:79:34 --> $DIR/trivially_copy_pass_by_ref.rs:84:34
| |
79 | fn bad2(x: &u32, y: &Foo, z: &Baz) { 84 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `Baz` | ^^^^ help: consider passing by value instead: `Baz`
error: aborting due to 13 previous errors error: aborting due to 13 previous errors