Skip to content

Commit 4ff26ad

Browse files
committed
trivially_copy_pass_by_ref: print size of type and limit in the lint message
1 parent 341c96a commit 4ff26ad

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

clippy_lints/src/trivially_copy_pass_by_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
6565
// portability problems between 32 and 64-bit targets
6666
let bit_width = cmp::min(bit_width, 32);
6767
let byte_width = bit_width / 8;
68-
// Use a limit of 2 times the register bit width
68+
// Use a limit of 2 times the register byte width
6969
byte_width * 2
7070
});
7171
Self { limit }
@@ -118,7 +118,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
118118
cx,
119119
TRIVIALLY_COPY_PASS_BY_REF,
120120
input.span,
121-
"this argument is passed by reference, but would be more efficient if passed by value",
121+
&format!("this argument ({} B) is passed by reference, but would be more efficient if passed by value (limit: {} B)", size, self.limit),
122122
"consider passing by value instead",
123123
value_type,
124124
Applicability::Unspecified,

tests/ui/trivially_copy_pass_by_ref.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// normalize-stderr-test "\(\d+ B\)" -> "(N B)"
2+
// normalize-stderr-test "\(limit: \d+ B\)" -> "(limit: N B)"
3+
4+
15
#![allow(
26
clippy::many_single_char_names,
37
clippy::blacklisted_name,

tests/ui/trivially_copy_pass_by_ref.stderr

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
1-
error: this argument is passed by reference, but would be more efficient if passed by value
2-
--> $DIR/trivially_copy_pass_by_ref.rs:47:11
1+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
2+
--> $DIR/trivially_copy_pass_by_ref.rs:51:11
33
|
44
LL | 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

9-
error: this argument is passed by reference, but would be more efficient if passed by value
10-
--> $DIR/trivially_copy_pass_by_ref.rs:47:20
9+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
10+
--> $DIR/trivially_copy_pass_by_ref.rs:51:20
1111
|
1212
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
1313
| ^^^^ help: consider passing by value instead: `Foo`
1414

15-
error: this argument is passed by reference, but would be more efficient if passed by value
16-
--> $DIR/trivially_copy_pass_by_ref.rs:47:29
15+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
16+
--> $DIR/trivially_copy_pass_by_ref.rs:51:29
1717
|
1818
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
1919
| ^^^^ help: consider passing by value instead: `Baz`
2020

21-
error: this argument is passed by reference, but would be more efficient if passed by value
22-
--> $DIR/trivially_copy_pass_by_ref.rs:54:12
21+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
22+
--> $DIR/trivially_copy_pass_by_ref.rs:58:12
2323
|
2424
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
2525
| ^^^^^ help: consider passing by value instead: `self`
2626

27-
error: this argument is passed by reference, but would be more efficient if passed by value
28-
--> $DIR/trivially_copy_pass_by_ref.rs:54:22
27+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
28+
--> $DIR/trivially_copy_pass_by_ref.rs:58:22
2929
|
3030
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
3131
| ^^^^ help: consider passing by value instead: `u32`
3232

33-
error: this argument is passed by reference, but would be more efficient if passed by value
34-
--> $DIR/trivially_copy_pass_by_ref.rs:54:31
33+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
34+
--> $DIR/trivially_copy_pass_by_ref.rs:58:31
3535
|
3636
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
3737
| ^^^^ help: consider passing by value instead: `Foo`
3838

39-
error: this argument is passed by reference, but would be more efficient if passed by value
40-
--> $DIR/trivially_copy_pass_by_ref.rs:54:40
39+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
40+
--> $DIR/trivially_copy_pass_by_ref.rs:58:40
4141
|
4242
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {}
4343
| ^^^^ help: consider passing by value instead: `Baz`
4444

45-
error: this argument is passed by reference, but would be more efficient if passed by value
46-
--> $DIR/trivially_copy_pass_by_ref.rs:56:16
45+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
46+
--> $DIR/trivially_copy_pass_by_ref.rs:60:16
4747
|
4848
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
4949
| ^^^^ help: consider passing by value instead: `u32`
5050

51-
error: this argument is passed by reference, but would be more efficient if passed by value
52-
--> $DIR/trivially_copy_pass_by_ref.rs:56:25
51+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
52+
--> $DIR/trivially_copy_pass_by_ref.rs:60:25
5353
|
5454
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
5555
| ^^^^ help: consider passing by value instead: `Foo`
5656

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

63-
error: this argument is passed by reference, but would be more efficient if passed by value
64-
--> $DIR/trivially_copy_pass_by_ref.rs:68:16
63+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
64+
--> $DIR/trivially_copy_pass_by_ref.rs:72:16
6565
|
6666
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
6767
| ^^^^ help: consider passing by value instead: `u32`
6868

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

75-
error: this argument is passed by reference, but would be more efficient if passed by value
76-
--> $DIR/trivially_copy_pass_by_ref.rs:68:34
75+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
76+
--> $DIR/trivially_copy_pass_by_ref.rs:72:34
7777
|
7878
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {}
7979
| ^^^^ help: consider passing by value instead: `Baz`
8080

81-
error: this argument is passed by reference, but would be more efficient if passed by value
82-
--> $DIR/trivially_copy_pass_by_ref.rs:72:34
81+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
82+
--> $DIR/trivially_copy_pass_by_ref.rs:76:34
8383
|
8484
LL | fn trait_method(&self, _foo: &Foo);
8585
| ^^^^ help: consider passing by value instead: `Foo`
8686

87-
error: this argument is passed by reference, but would be more efficient if passed by value
88-
--> $DIR/trivially_copy_pass_by_ref.rs:76:37
87+
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
88+
--> $DIR/trivially_copy_pass_by_ref.rs:80:37
8989
|
9090
LL | fn trait_method2(&self, _color: &Color);
9191
| ^^^^^^ help: consider passing by value instead: `Color`

0 commit comments

Comments
 (0)