trivially_copy_pass_by_ref: print size of type and limit in the lint message

This commit is contained in:
Matthias Krüger 2019-05-06 21:41:05 +02:00
parent 345ac82934
commit 5d58163f7d
5 changed files with 42 additions and 36 deletions

View File

@ -65,7 +65,7 @@ pub fn new(limit: Option<u64>, target: &SessionConfig) -> Self {
// portability problems between 32 and 64-bit targets // portability problems between 32 and 64-bit targets
let bit_width = cmp::min(bit_width, 32); let bit_width = cmp::min(bit_width, 32);
let byte_width = bit_width / 8; let byte_width = bit_width / 8;
// Use a limit of 2 times the register bit width // Use a limit of 2 times the register byte width
byte_width * 2 byte_width * 2
}); });
Self { limit } Self { limit }
@ -118,7 +118,7 @@ fn check_poly_fn(&mut self, cx: &LateContext<'_, 'tcx>, decl: &FnDecl, sig: &FnS
cx, cx,
TRIVIALLY_COPY_PASS_BY_REF, TRIVIALLY_COPY_PASS_BY_REF,
input.span, input.span,
"this argument is passed by reference, but would be more efficient if passed by value", &format!("this argument ({} byte) is passed by reference, but would be more efficient if passed by value (limit: {} byte)", size, self.limit),
"consider passing by value instead", "consider passing by value instead",
value_type, value_type,
Applicability::Unspecified, Applicability::Unspecified,

View File

@ -1,3 +1,6 @@
// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
#![allow(clippy::many_single_char_names)] #![allow(clippy::many_single_char_names)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]

View File

@ -1,13 +1,13 @@
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/test.rs:11:11 --> $DIR/test.rs:14:11
| |
LL | fn bad(x: &u16, y: &Foo) {} LL | fn bad(x: &u16, y: &Foo) {}
| ^^^^ help: consider passing by value instead: `u16` | ^^^^ help: consider passing by value instead: `u16`
| |
= 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/test.rs:11:20 --> $DIR/test.rs:14:20
| |
LL | fn bad(x: &u16, y: &Foo) {} LL | fn bad(x: &u16, y: &Foo) {}
| ^^^^ help: consider passing by value instead: `Foo` | ^^^^ help: consider passing by value instead: `Foo`

View File

@ -1,3 +1,6 @@
// normalize-stderr-test "\(\d+ byte\)" -> "(N byte)"
// normalize-stderr-test "\(limit: \d+ byte\)" -> "(limit: N byte)"
#![allow( #![allow(
clippy::many_single_char_names, clippy::many_single_char_names,
clippy::blacklisted_name, clippy::blacklisted_name,

View File

@ -1,91 +1,91 @@
error: this argument is passed by reference, but would be more efficient if passed by value error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:47:11 --> $DIR/trivially_copy_pass_by_ref.rs:50:11
| |
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:47:20 --> $DIR/trivially_copy_pass_by_ref.rs:50:20
| |
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:47:29 --> $DIR/trivially_copy_pass_by_ref.rs:50:29
| |
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:54:12 --> $DIR/trivially_copy_pass_by_ref.rs:57:12
| |
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:54:22 --> $DIR/trivially_copy_pass_by_ref.rs:57:22
| |
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:54:31 --> $DIR/trivially_copy_pass_by_ref.rs:57:31
| |
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:54:40 --> $DIR/trivially_copy_pass_by_ref.rs:57:40
| |
LL | fn bad(&self, x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:56:16 --> $DIR/trivially_copy_pass_by_ref.rs:59:16
| |
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:56:25 --> $DIR/trivially_copy_pass_by_ref.rs:59:25
| |
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:56:34 --> $DIR/trivially_copy_pass_by_ref.rs:59:34
| |
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:68:16 --> $DIR/trivially_copy_pass_by_ref.rs:71:16
| |
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:68:25 --> $DIR/trivially_copy_pass_by_ref.rs:71:25
| |
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:68:34 --> $DIR/trivially_copy_pass_by_ref.rs:71:34
| |
LL | fn bad2(x: &u32, y: &Foo, z: &Baz) {} LL | 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:72:34 --> $DIR/trivially_copy_pass_by_ref.rs:75:34
| |
LL | fn trait_method(&self, _foo: &Foo); LL | fn trait_method(&self, _foo: &Foo);
| ^^^^ 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 (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
--> $DIR/trivially_copy_pass_by_ref.rs:76:37 --> $DIR/trivially_copy_pass_by_ref.rs:79:37
| |
LL | fn trait_method2(&self, _color: &Color); LL | fn trait_method2(&self, _color: &Color);
| ^^^^^^ help: consider passing by value instead: `Color` | ^^^^^^ help: consider passing by value instead: `Color`