Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy cleanup #393

Merged
merged 1 commit into from Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions mockall/tests/automock_instrument.rs
Expand Up @@ -2,6 +2,7 @@
//! A trait that uses tracing::instrument should be automockable. The mock
//! method won't be instrumented, though.
#![deny(warnings)]
#![allow(dead_code)]

use mockall::*;
use tracing::instrument;
Expand Down
2 changes: 1 addition & 1 deletion mockall/tests/automock_module_nonpub.rs
@@ -1,6 +1,7 @@
// vim: tw=80
//! bare functions can use non-public types, as long as the object's visibility is compatible.
#![deny(warnings)]
#![allow(dead_code)]

mod outer {
struct SuperT();
Expand All @@ -11,7 +12,6 @@ mod outer {
pub(crate) struct PubCrateT();
struct PrivT();

#[allow(dead_code)]
#[automock]
mod m {
use super::*;
Expand Down
1 change: 0 additions & 1 deletion mockall/tests/mock_associated_const.rs
Expand Up @@ -17,7 +17,6 @@ trait Foo {
mock! {
Foo {
const Y: i32 = 69;
fn foo(&self);
}
impl Foo for Foo {
const X: i32 = 42;
Expand Down
1 change: 1 addition & 0 deletions mockall/tests/mock_cfg.rs
@@ -1,6 +1,7 @@
// vim: tw=80
//! mock's methods and trait impls can be conditionally compiled
#![deny(warnings)]
#![allow(dead_code)]

use mockall::*;

Expand Down
1 change: 0 additions & 1 deletion mockall/tests/mock_constructor_with_args.rs
Expand Up @@ -8,7 +8,6 @@ use mockall::*;

mock! {
pub Foo {
fn foo(&self) -> u32;
fn new(x: u32) -> Self;
}
}
Expand Down
8 changes: 2 additions & 6 deletions mockall/tests/mock_debug.rs
Expand Up @@ -8,19 +8,15 @@ use std::fmt::{self, Debug, Formatter};
// using derive(Debug) tells mockall to generate the Debug impl automatically
mock!{
#[derive(Debug)]
pub Bar {
fn foo(&self) -> u32;
}
pub Bar { }
impl Clone for Bar {
fn clone(&self) -> Self;
}
}

// With no derive(Debug), mockall won't genetate the debug impl automatically
mock!{
pub Baz {
fn foo(&self) -> u32;
}
pub Baz { }
impl Clone for Baz {
fn clone(&self) -> Self;
}
Expand Down
1 change: 1 addition & 0 deletions mockall/tests/mock_docs.rs
@@ -1,6 +1,7 @@
// vim: tw=80
#![deny(missing_docs)]
#![deny(warnings)]
#![allow(dead_code)]

use mockall::*;

Expand Down
Expand Up @@ -59,7 +59,7 @@ fn return_static_ref() {
thing.expect_baz()
.return_const(x);

assert_eq!(42u32, *(*thing.baz()).0);
assert_eq!(42u32, *thing.baz().0);
}

// It isn't possible to safely set an expectation for a non-'static return value
Expand Down Expand Up @@ -99,7 +99,7 @@ mod trait_methods {
thing.expect_trait_baz()
.return_const(x);

assert_eq!(42u32, *(*thing.trait_baz()).0);
assert_eq!(42u32, *thing.trait_baz().0);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions mockall/tests/mock_generic_method_returning_nonstatic.rs
Expand Up @@ -60,7 +60,7 @@ fn return_static_ref() {
thing.expect_baz()
.return_const(x);

assert_eq!(42u32, *(*thing.baz()).0);
assert_eq!(42u32, *thing.baz().0);
}

// It isn't possible to safely set an expectation for a non-'static return value
Expand Down Expand Up @@ -100,7 +100,7 @@ mod trait_methods {
thing.expect_trait_baz()
.return_const(x);

assert_eq!(42u32, *(*thing.trait_baz()).0);
assert_eq!(42u32, *thing.trait_baz().0);
}

#[test]
Expand Down
Expand Up @@ -10,6 +10,7 @@ mock! {
fn foo<Q: 'static>(t: T, q: Q) -> u64;
// We must use a different method for every should_panic test, so the
// shared mutex doesn't get poisoned.
#[allow(dead_code)]
fn foo2<Q: 'static>(t: T, q: Q) -> u64;
fn foo3<Q: 'static>(t: T, q: Q) -> u64;
}
Expand Down
1 change: 1 addition & 0 deletions mockall/tests/mock_life0.rs
Expand Up @@ -2,6 +2,7 @@
//! mock a method whose self parameter has an explicit lifetime
//! https://github.com/asomers/mockall/issues/95
#![deny(warnings)]
#![allow(dead_code)]

use mockall::*;

Expand Down
1 change: 1 addition & 0 deletions mockall/tests/mock_nonpub.rs
Expand Up @@ -2,6 +2,7 @@
//! methods can use non-public types, as long as the object's visibility is
//! compatible.
#![deny(warnings)]
#![allow(dead_code)]

use mockall::*;

Expand Down
15 changes: 15 additions & 0 deletions mockall/tests/mock_refmut_arguments.rs
Expand Up @@ -2,11 +2,14 @@
//! A struct with methods that take arguments by mutable reference.
#![deny(warnings)]

use std::mem;

use mockall::*;

mock!{
Foo {
fn foo(&self, x: &mut u32);
// This is almost never safe, but it should still work.
fn bar(&self, y: &'static mut u32);
}
}
Expand Down Expand Up @@ -35,3 +38,15 @@ fn with() {
mock.foo(&mut x);
assert_eq!(5, x);
}

#[test]
fn static_mut() {
let mut x: u32 = 5;
let mut mock = MockFoo::new();
mock.expect_bar()
.withf(|x| *x == 5)
.returning(|x| { *x = 42;} );
// Safe because mock leaves scope before x
unsafe { mock.bar(mem::transmute(&mut x)); }
assert_eq!(x, 42);
}
1 change: 1 addition & 0 deletions mockall/tests/mock_struct_with_static_method.rs
@@ -1,5 +1,6 @@
// vim: tw=80
#![deny(warnings)]
#![allow(dead_code)]

use mockall::*;
use std::sync::Mutex;
Expand Down
2 changes: 1 addition & 1 deletion mockall_derive/src/lib.rs
Expand Up @@ -447,7 +447,7 @@ fn deselfify_args(
{
for arg in args.iter_mut() {
if let FnArg::Typed(pt) = arg {
deselfify(&mut *pt.ty, actual, generics)
deselfify(pt.ty.as_mut(), actual, generics)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion mockall_derive/src/mock_function.rs
Expand Up @@ -222,7 +222,7 @@ impl<'a> Builder<'a> {
false,
),
ReturnType::Type(_, ref ty) => {
let mut output_ty = supersuperfy(&**ty, self.levels);
let mut output_ty = supersuperfy(ty, self.levels);
destrify(&mut output_ty);
let boxed = dedynify(&mut output_ty);
(output_ty, boxed)
Expand Down
2 changes: 1 addition & 1 deletion mockall_derive/src/mockable_item.rs
Expand Up @@ -104,7 +104,7 @@ impl From<(Attrs, ItemForeignMod)> for MockableModule {

for arg in sig.inputs.iter_mut() {
if let FnArg::Typed(pt) = arg {
*pt.ty = supersuperfy(&*pt.ty, 1);
*pt.ty = supersuperfy(pt.ty.as_ref(), 1);
}
}
if let ReturnType::Type(_, ty) = &mut sig.output {
Expand Down