Skip to content

Commit

Permalink
trivially_copy_pass_by_ref: print size of type and limit in the lint …
Browse files Browse the repository at this point in the history
…message
  • Loading branch information
matthiaskrgr committed May 8, 2019
1 parent 341c96a commit 4ff26ad
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/trivially_copy_pass_by_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
// portability problems between 32 and 64-bit targets
let bit_width = cmp::min(bit_width, 32);
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
});
Self { limit }
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
cx,
TRIVIALLY_COPY_PASS_BY_REF,
input.span,
"this argument is passed by reference, but would be more efficient if passed by value",
&format!("this argument ({} B) is passed by reference, but would be more efficient if passed by value (limit: {} B)", size, self.limit),
"consider passing by value instead",
value_type,
Applicability::Unspecified,
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/trivially_copy_pass_by_ref.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// normalize-stderr-test "\(\d+ B\)" -> "(N B)"
// normalize-stderr-test "\(limit: \d+ B\)" -> "(limit: N B)"


#![allow(
clippy::many_single_char_names,
clippy::blacklisted_name,
Expand Down
60 changes: 30 additions & 30 deletions tests/ui/trivially_copy_pass_by_ref.stderr
Original file line number Diff line number Diff line change
@@ -1,91 +1,91 @@
error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:47:11
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
--> $DIR/trivially_copy_pass_by_ref.rs:51:11
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `u32`
|
= 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
--> $DIR/trivially_copy_pass_by_ref.rs:47:20
error: this argument (N B) is passed by reference, but would be more efficient if passed by value (limit: N B)
--> $DIR/trivially_copy_pass_by_ref.rs:51:20
|
LL | fn bad(x: &u32, y: &Foo, z: &Baz) {}
| ^^^^ help: consider passing by value instead: `Foo`

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

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

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

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

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

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

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

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

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

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

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

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

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

0 comments on commit 4ff26ad

Please sign in to comment.