Skip to content

Commit d57845f

Browse files
committed
Auto merge of #4071 - matthiaskrgr:sizeof, r=flip1995
trivially_copy_pass_by_ref: print size of type and limit in the lint message changelog: trivially_copy_pass_by_ref: print size of type and limit in the lint message
2 parents e119ab4 + 5d58163 commit d57845f

File tree

5 files changed

+42
-36
lines changed

5 files changed

+42
-36
lines changed

clippy_lints/src/trivially_copy_pass_by_ref.rs

+2-2
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 ({} byte) is passed by reference, but would be more efficient if passed by value (limit: {} byte)", size, self.limit),
122122
"consider passing by value instead",
123123
value_type,
124124
Applicability::Unspecified,

tests/ui-toml/toml_trivially_copy/test.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
2+
// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
3+
14
#![allow(clippy::many_single_char_names)]
25

36
#[derive(Copy, Clone)]

tests/ui-toml/toml_trivially_copy/test.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error: this argument is passed by reference, but would be more efficient if passed by value
2-
--> $DIR/test.rs:11:11
1+
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
2+
--> $DIR/test.rs:14:11
33
|
44
LL | fn bad(x: &u16, y: &Foo) {}
55
| ^^^^ help: consider passing by value instead: `u16`
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/test.rs:11:20
9+
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
10+
--> $DIR/test.rs:14:20
1111
|
1212
LL | fn bad(x: &u16, y: &Foo) {}
1313
| ^^^^ help: consider passing by value instead: `Foo`

tests/ui/trivially_copy_pass_by_ref.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
2+
// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
3+
14
#![allow(
25
clippy::many_single_char_names,
36
clippy::blacklisted_name,

tests/ui/trivially_copy_pass_by_ref.stderr

+30-30
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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
2+
--> $DIR/trivially_copy_pass_by_ref.rs:50: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
10+
--> $DIR/trivially_copy_pass_by_ref.rs:50: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
16+
--> $DIR/trivially_copy_pass_by_ref.rs:50: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
22+
--> $DIR/trivially_copy_pass_by_ref.rs:57: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
28+
--> $DIR/trivially_copy_pass_by_ref.rs:57: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
34+
--> $DIR/trivially_copy_pass_by_ref.rs:57: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
40+
--> $DIR/trivially_copy_pass_by_ref.rs:57: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
46+
--> $DIR/trivially_copy_pass_by_ref.rs:59: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
52+
--> $DIR/trivially_copy_pass_by_ref.rs:59: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
58+
--> $DIR/trivially_copy_pass_by_ref.rs:59: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
64+
--> $DIR/trivially_copy_pass_by_ref.rs:71: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
70+
--> $DIR/trivially_copy_pass_by_ref.rs:71: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
76+
--> $DIR/trivially_copy_pass_by_ref.rs:71: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
82+
--> $DIR/trivially_copy_pass_by_ref.rs:75: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 byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
88+
--> $DIR/trivially_copy_pass_by_ref.rs:79:37
8989
|
9090
LL | fn trait_method2(&self, _color: &Color);
9191
| ^^^^^^ help: consider passing by value instead: `Color`

0 commit comments

Comments
 (0)