Skip to content

Commit

Permalink
Make clippy::pedantic happy
Browse files Browse the repository at this point in the history
  • Loading branch information
oxalica committed Feb 16, 2023
1 parent 50e2474 commit e4674cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@clippy
- run: cargo clippy --tests -- -Dclippy::all
- run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic

miri:
name: Miri
Expand Down
18 changes: 9 additions & 9 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ fn expand(
};

attrs.push(parse_quote_spanned!(async_span=> #[allow(clippy::needless_lifetimes)]));
attrs.push(parse_quote_spanned!(async_span=> #[must_use]));

let lifetime = match args.lifetime {
None => Lifetime::new("'static", Span::call_site()),
Expand Down Expand Up @@ -273,6 +274,7 @@ mod tests {
use quote::quote;

#[track_caller]
#[allow(clippy::needless_pass_by_value)]
fn check(args: TokenStream, input: TokenStream, expect: Expect) {
let got = async_ffi_inner(args, input).to_string();
expect.assert_eq(&got);
Expand All @@ -285,7 +287,7 @@ mod tests {
quote! {
async fn foo() {}
},
expect!["# [allow (clippy :: needless_lifetimes)] fn foo () -> :: async_ffi :: BorrowingFfiFuture < 'static , () > { :: async_ffi :: BorrowingFfiFuture :: new (async move { }) }"],
expect!["# [allow (clippy :: needless_lifetimes)] # [must_use] fn foo () -> :: async_ffi :: BorrowingFfiFuture < 'static , () > { :: async_ffi :: BorrowingFfiFuture :: new (async move { }) }"],
);
}

Expand All @@ -296,14 +298,14 @@ mod tests {
quote! {
async fn foo(x: i32) { x + 1 }
},
expect!["# [allow (clippy :: needless_lifetimes)] fn foo (x : i32) -> :: async_ffi :: BorrowingFfiFuture < 'static , () > { :: async_ffi :: BorrowingFfiFuture :: new (async move { let _ = & x ; x + 1 }) }"],
expect!["# [allow (clippy :: needless_lifetimes)] # [must_use] fn foo (x : i32) -> :: async_ffi :: BorrowingFfiFuture < 'static , () > { :: async_ffi :: BorrowingFfiFuture :: new (async move { let _ = & x ; x + 1 }) }"],
);
check(
quote!(),
quote! {
async fn foo(&self, y: i32) -> i32 { self.x + y }
},
expect!["# [allow (clippy :: needless_lifetimes)] fn foo (& self , y : i32) -> :: async_ffi :: BorrowingFfiFuture < 'static , i32 > { :: async_ffi :: BorrowingFfiFuture :: new (async move { let _ = & self ; let _ = & y ; self . x + y }) }"],
expect!["# [allow (clippy :: needless_lifetimes)] # [must_use] fn foo (& self , y : i32) -> :: async_ffi :: BorrowingFfiFuture < 'static , i32 > { :: async_ffi :: BorrowingFfiFuture :: new (async move { let _ = & self ; let _ = & y ; self . x + y }) }"],
);
}

Expand All @@ -314,9 +316,7 @@ mod tests {
quote! {
fn foo() {}
},
expect![[
r##"# [allow (clippy :: needless_lifetimes)] fn foo () -> :: async_ffi :: BorrowingFfiFuture < 'static , () > { :: async_ffi :: BorrowingFfiFuture :: new (async move { }) } compile_error ! { "#[async_ffi] expects an `async fn`" }"##
]],
expect![[r##"# [allow (clippy :: needless_lifetimes)] # [must_use] fn foo () -> :: async_ffi :: BorrowingFfiFuture < 'static , () > { :: async_ffi :: BorrowingFfiFuture :: new (async move { }) } compile_error ! { "#[async_ffi] expects an `async fn`" }"##]],
);
}

Expand All @@ -327,7 +327,7 @@ mod tests {
quote! {
async fn foo() {}
},
expect!["# [allow (clippy :: needless_lifetimes)] fn foo () -> :: async_ffi :: LocalBorrowingFfiFuture < 'static , () > { :: async_ffi :: LocalBorrowingFfiFuture :: new (async move { }) }"],
expect!["# [allow (clippy :: needless_lifetimes)] # [must_use] fn foo () -> :: async_ffi :: LocalBorrowingFfiFuture < 'static , () > { :: async_ffi :: LocalBorrowingFfiFuture :: new (async move { }) }"],
);
}

Expand All @@ -338,7 +338,7 @@ mod tests {
quote! {
async fn extern_fn(arg1: u32) -> u32;
},
expect!["# [allow (clippy :: needless_lifetimes)] fn extern_fn (arg1 : u32) -> :: async_ffi :: BorrowingFfiFuture < 'static , u32 > ;"],
expect!["# [allow (clippy :: needless_lifetimes)] # [must_use] fn extern_fn (arg1 : u32) -> :: async_ffi :: BorrowingFfiFuture < 'static , u32 > ;"],
);
}

Expand All @@ -349,7 +349,7 @@ mod tests {
quote! {
async fn f(x: &i32) {}
},
expect!["# [allow (clippy :: needless_lifetimes)] fn f < 'fut > (x : & i32) -> :: async_ffi :: BorrowingFfiFuture < 'fut , () > { :: async_ffi :: BorrowingFfiFuture :: new (async move { let _ = & x ; }) }"],
expect!["# [allow (clippy :: needless_lifetimes)] # [must_use] fn f < 'fut > (x : & i32) -> :: async_ffi :: BorrowingFfiFuture < 'fut , () > { :: async_ffi :: BorrowingFfiFuture :: new (async move { let _ = & x ; }) }"],
);
}
}
11 changes: 6 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ pub struct FfiContext<'a> {
}

impl<'a> FfiContext<'a> {
/// SAFETY: VTable functions of `waker` are unsafe, the caller must ensure they have a
/// SAFETY: Vtable functions of `waker` are unsafe, the caller must ensure they have a
/// sane behavior as a Waker. `with_context` relies on this to be safe.
unsafe fn new(waker: &'a FfiWaker) -> Self {
Self {
waker: waker as *const FfiWaker as *const FfiWakerBase,
waker: (waker as *const FfiWaker).cast::<FfiWakerBase>(),
_marker: PhantomData,
}
}
Expand Down Expand Up @@ -231,13 +231,13 @@ impl<'a> ContextExt for Context<'a> {
DropBomb::with("Waker::wake", || {
let b = Box::from_raw(data as *mut FfiWaker);
ManuallyDrop::into_inner(b.waker.owned).wake();
})
});
}
unsafe extern "C" fn wake_by_ref(data: *const FfiWakerBase) {
DropBomb::with("Waker::wake_by_ref", || {
let data = data as *mut FfiWaker;
(*data).waker.owned.wake_by_ref();
})
});
}
// Same as `wake`.
unsafe extern "C" fn drop(data: *const FfiWakerBase) {
Expand Down Expand Up @@ -275,7 +275,7 @@ impl<'a> ContextExt for Context<'a> {
DropBomb::with("Waker::wake_by_ref", || {
let data = data as *mut FfiWaker;
(*(*data).waker.reference).wake_by_ref();
})
});
}
unsafe extern "C" fn unreachable(_: *const FfiWakerBase) {
std::process::abort();
Expand Down Expand Up @@ -400,6 +400,7 @@ impl<T> FfiPoll<T> {

/// Try to convert a [`FfiPoll`] back to the [`std::task::Poll`].
///
/// # Errors
/// Returns `Err(PollPanicked)` if the result indicates the poll function panicked.
///
/// [`std::task::Poll`]: std::task::Poll
Expand Down

0 comments on commit e4674cb

Please sign in to comment.