Skip to content

False positive on clippy::borrowed_box forced by Mockall #5770

Open
@JamesSharkey

Description

@JamesSharkey

I tried this code:

#[mockall::automock]
trait Bar {
    fn foo(&self, value: Box<String>);
}

fn main() {
    let mut mock_bar = MockBar::default();
    mock_bar.expect_foo().with(mockall::predicate::function(|value: &Box<String>| **value == ""));
}

I expected clippy to give no warnings

Instead, this happened:

warning: you seem to be trying to use `&Box<T>`. Consider using just `&T`
 --> src\main.rs:8:69
  |
8 |     mock_bar.expect_foo().with(mockall::predicate::function(|value: &Box<String>| **value == ""));
  |                                                                     ^^^^^^^^^^^^ help: try: `&String`
  |
  = note: `#[warn(clippy::borrowed_box)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrowed_box

The Mockall library predicate uses &T where T is the type of a function's parameter. In this case T is Box so the type in the predicate's closure is forced to be &Box and can't be change to &String.

Meta

  • cargo clippy -V: clippy 0.0.212 (bb37a0f 2020-06-16)
  • rustc -Vv:
rustc 1.44.1 (c7087fe00 2020-06-17)
binary: rustc
commit-hash: c7087fe00d2ba919df1d813c040a5d47e43b0fe7
commit-date: 2020-06-17
host: x86_64-pc-windows-msvc
release: 1.44.1
LLVM version: 9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions