rust-clippy/tests/ui/trivially_copy_pass_by_ref.stderr
Ryan Cumming 58459abd0c Allow pass by reference if we return a reference
Currently this code will trigger `trivally_copy_pass_by_ref`:

```
struct OuterStruct {
    field: [u8; 8],
}

fn return_inner(outer: &OuterStruct) -> &[u8] {
    &outer.field
}
```

If we change the `outer` to be pass-by-value it will not live long
enough for us to return the reference. The above example is trivial but
I've hit this in real code that either returns a reference to either the
argument or in to `self`.

This suppresses the `trivally_copy_pass_by_ref` lint if we return a
reference and it has the same lifetime as the argument. This will likely
miss complex cases with multiple lifetimes bounded by each other but it
should cover the majority of cases with little effort.
2018-07-23 18:44:40 +10:00

82 lines
3.6 KiB
Text

error: this argument is passed by reference, but would be more efficient if passed by value
--> $DIR/trivially_copy_pass_by_ref.rs:23:11
|
23 | fn bad(x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `u32`
|
= note: `-D 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:23:20
|
23 | 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:23:29
|
23 | 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:33:12
|
33 | 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:33:22
|
33 | 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:33:31
|
33 | 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:33:40
|
33 | 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:36:16
|
36 | 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:36:25
|
36 | 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:36:34
|
36 | 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:50:16
|
50 | 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:50:25
|
50 | 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:50:34
|
50 | fn bad2(x: &u32, y: &Foo, z: &Baz) {
| ^^^^ help: consider passing by value instead: `Baz`
error: aborting due to 13 previous errors