Skip to content

Commit 67c32eb

Browse files
committed
Update trivially_copy_pass_by_ref with Trait examples
1 parent 70ca052 commit 67c32eb

File tree

2 files changed

+45
-26
lines changed

2 files changed

+45
-26
lines changed

tests/ui/trivially_copy_pass_by_ref.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ struct Foo(u32);
1818
#[derive(Copy, Clone)]
1919
struct Bar([u8; 24]);
2020

21+
#[derive(Copy, Clone)]
22+
pub struct Color {
23+
pub r: u8, pub g: u8, pub b: u8, pub a: u8,
24+
}
25+
2126
struct FooRef<'a> {
2227
foo: &'a Foo,
2328
}
@@ -80,6 +85,20 @@ impl Bar {
8085
}
8186
}
8287

88+
trait MyTrait {
89+
fn trait_method(&self, _foo: &Foo);
90+
}
91+
92+
pub trait MyTrait2 {
93+
fn trait_method2(&self, _color: &Color);
94+
}
95+
96+
impl MyTrait for Foo {
97+
fn trait_method(&self, _foo: &Foo) {
98+
unimplemented!()
99+
}
100+
}
101+
83102
fn main() {
84103
let (mut foo, bar) = (Foo(0), Bar([0; 24]));
85104
let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0);

tests/ui/trivially_copy_pass_by_ref.stderr

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,81 @@
11
error: this argument is passed by reference, but would be more efficient if passed by value
2-
--> $DIR/trivially_copy_pass_by_ref.rs:52:11
2+
--> $DIR/trivially_copy_pass_by_ref.rs:57:11
33
|
4-
52 | fn bad(x: &u32, y: &Foo, z: &Baz) {
4+
57 | fn bad(x: &u32, y: &Foo, z: &Baz) {
55
| ^^^^ help: consider passing by value instead: `u32`
66
|
77
= note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings`
88

99
error: this argument is passed by reference, but would be more efficient if passed by value
10-
--> $DIR/trivially_copy_pass_by_ref.rs:52:20
10+
--> $DIR/trivially_copy_pass_by_ref.rs:57:20
1111
|
12-
52 | fn bad(x: &u32, y: &Foo, z: &Baz) {
12+
57 | fn bad(x: &u32, y: &Foo, z: &Baz) {
1313
| ^^^^ help: consider passing by value instead: `Foo`
1414

1515
error: this argument is passed by reference, but would be more efficient if passed by value
16-
--> $DIR/trivially_copy_pass_by_ref.rs:52:29
16+
--> $DIR/trivially_copy_pass_by_ref.rs:57:29
1717
|
18-
52 | fn bad(x: &u32, y: &Foo, z: &Baz) {
18+
57 | fn bad(x: &u32, y: &Foo, z: &Baz) {
1919
| ^^^^ help: consider passing by value instead: `Baz`
2020

2121
error: this argument is passed by reference, but would be more efficient if passed by value
22-
--> $DIR/trivially_copy_pass_by_ref.rs:62:12
22+
--> $DIR/trivially_copy_pass_by_ref.rs:67:12
2323
|
24-
62 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
24+
67 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
2525
| ^^^^^ help: consider passing by value instead: `self`
2626

2727
error: this argument is passed by reference, but would be more efficient if passed by value
28-
--> $DIR/trivially_copy_pass_by_ref.rs:62:22
28+
--> $DIR/trivially_copy_pass_by_ref.rs:67:22
2929
|
30-
62 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
30+
67 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
3131
| ^^^^ help: consider passing by value instead: `u32`
3232

3333
error: this argument is passed by reference, but would be more efficient if passed by value
34-
--> $DIR/trivially_copy_pass_by_ref.rs:62:31
34+
--> $DIR/trivially_copy_pass_by_ref.rs:67:31
3535
|
36-
62 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
36+
67 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
3737
| ^^^^ help: consider passing by value instead: `Foo`
3838

3939
error: this argument is passed by reference, but would be more efficient if passed by value
40-
--> $DIR/trivially_copy_pass_by_ref.rs:62:40
40+
--> $DIR/trivially_copy_pass_by_ref.rs:67:40
4141
|
42-
62 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
42+
67 | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {
4343
| ^^^^ help: consider passing by value instead: `Baz`
4444

4545
error: this argument is passed by reference, but would be more efficient if passed by value
46-
--> $DIR/trivially_copy_pass_by_ref.rs:65:16
46+
--> $DIR/trivially_copy_pass_by_ref.rs:70:16
4747
|
48-
65 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
48+
70 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
4949
| ^^^^ help: consider passing by value instead: `u32`
5050

5151
error: this argument is passed by reference, but would be more efficient if passed by value
52-
--> $DIR/trivially_copy_pass_by_ref.rs:65:25
52+
--> $DIR/trivially_copy_pass_by_ref.rs:70:25
5353
|
54-
65 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
54+
70 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
5555
| ^^^^ help: consider passing by value instead: `Foo`
5656

5757
error: this argument is passed by reference, but would be more efficient if passed by value
58-
--> $DIR/trivially_copy_pass_by_ref.rs:65:34
58+
--> $DIR/trivially_copy_pass_by_ref.rs:70:34
5959
|
60-
65 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
60+
70 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
6161
| ^^^^ help: consider passing by value instead: `Baz`
6262

6363
error: this argument is passed by reference, but would be more efficient if passed by value
64-
--> $DIR/trivially_copy_pass_by_ref.rs:79:16
64+
--> $DIR/trivially_copy_pass_by_ref.rs:84:16
6565
|
66-
79 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
66+
84 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
6767
| ^^^^ help: consider passing by value instead: `u32`
6868

6969
error: this argument is passed by reference, but would be more efficient if passed by value
70-
--> $DIR/trivially_copy_pass_by_ref.rs:79:25
70+
--> $DIR/trivially_copy_pass_by_ref.rs:84:25
7171
|
72-
79 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
72+
84 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
7373
| ^^^^ help: consider passing by value instead: `Foo`
7474

7575
error: this argument is passed by reference, but would be more efficient if passed by value
76-
--> $DIR/trivially_copy_pass_by_ref.rs:79:34
76+
--> $DIR/trivially_copy_pass_by_ref.rs:84:34
7777
|
78-
79 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
78+
84 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
7979
| ^^^^ help: consider passing by value instead: `Baz`
8080

8181
error: aborting due to 13 previous errors

0 commit comments

Comments
 (0)