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

macros: suppress clippy::default_numeric_fallback lint in generated code #3831

Merged
merged 10 commits into from Jun 2, 2021
1 change: 1 addition & 0 deletions .clippy.toml
@@ -0,0 +1 @@
msrv = "1.45"
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -265,7 +265,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update ${{ env.minrust }} && rustup default ${{ env.minrust }}
run: rustup update 1.52.1 && rustup default 1.52.1
- name: Install clippy
run: rustup component add clippy

Expand Down
2 changes: 2 additions & 0 deletions tokio-stream/tests/async_send_sync.rs
@@ -1,3 +1,5 @@
#![allow(clippy::diverging_sub_expression)]

use std::rc::Rc;

#[allow(dead_code)]
Expand Down
6 changes: 3 additions & 3 deletions tokio-util/tests/poll_semaphore.rs
Expand Up @@ -6,9 +6,9 @@ use tokio_util::sync::PollSemaphore;

type SemRet = Option<OwnedSemaphorePermit>;

fn semaphore_poll<'a>(
sem: &'a mut PollSemaphore,
) -> tokio_test::task::Spawn<impl Future<Output = SemRet> + 'a> {
fn semaphore_poll(
sem: &mut PollSemaphore,
) -> tokio_test::task::Spawn<impl Future<Output = SemRet> + '_> {
let fut = futures::future::poll_fn(move |cx| sem.poll_acquire(cx));
tokio_test::task::spawn(fut)
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/macros/select.rs
Expand Up @@ -398,7 +398,7 @@ macro_rules! select {
// set the appropriate bit in `disabled`.
$(
if !$c {
let mask = 1 << $crate::count!( $($skip)* );
let mask: util::Mask = 1 << $crate::count!( $($skip)* );
disabled |= mask;
}
)*
Expand Down
3 changes: 3 additions & 0 deletions tokio/src/runtime/task/state.rs
Expand Up @@ -29,12 +29,15 @@ const LIFECYCLE_MASK: usize = 0b11;
const NOTIFIED: usize = 0b100;

/// The join handle is still around
#[allow(clippy::unusual_byte_groupings)] // https://github.com/rust-lang/rust-clippy/issues/6556
const JOIN_INTEREST: usize = 0b1_000;

/// A join handle waker has been set
#[allow(clippy::unusual_byte_groupings)] // https://github.com/rust-lang/rust-clippy/issues/6556
const JOIN_WAKER: usize = 0b10_000;

/// The task has been forcibly cancelled.
#[allow(clippy::unusual_byte_groupings)] // https://github.com/rust-lang/rust-clippy/issues/6556
const CANCELLED: usize = 0b100_000;

/// All bits
Expand Down
1 change: 1 addition & 0 deletions tokio/src/util/linked_list.rs
Expand Up @@ -50,6 +50,7 @@ pub(crate) unsafe trait Link {
type Target;

/// Convert the handle to a raw pointer without consuming the handle
#[allow(clippy::wrong_self_convention)]
fn as_raw(handle: &Self::Handle) -> NonNull<Self::Target>;

/// Convert the raw pointer to a handle
Expand Down
6 changes: 1 addition & 5 deletions tokio/src/util/wake.rs
Expand Up @@ -54,11 +54,7 @@ unsafe fn inc_ref_count<T: Wake>(data: *const ()) {
let arc = ManuallyDrop::new(Arc::<T>::from_raw(data as *const T));

// Now increase refcount, but don't drop new refcount either
let arc_clone: ManuallyDrop<_> = arc.clone();

// Drop explicitly to avoid clippy warnings
drop(arc);
drop(arc_clone);
let _arc_clone: ManuallyDrop<_> = arc.clone();
}

unsafe fn clone_arc_raw<T: Wake>(data: *const ()) -> RawWaker {
Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/async_send_sync.rs
@@ -1,6 +1,6 @@
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]
#![allow(clippy::type_complexity)]
#![allow(clippy::type_complexity, clippy::diverging_sub_expression)]

use std::cell::Cell;
use std::future::Future;
Expand Down
10 changes: 10 additions & 0 deletions tokio/tests/macros_select.rs
Expand Up @@ -537,3 +537,13 @@ async fn biased_eventually_ready() {

assert_eq!(count, 3);
}

// https://github.com/tokio-rs/tokio/issues/3830
// https://github.com/rust-lang/rust-clippy/issues/7304
#[warn(clippy::default_numeric_fallback)]
pub async fn default_numeric_fallback() {
tokio::select! {
_ = async {} => (),
else => (),
}
}
12 changes: 2 additions & 10 deletions tokio/tests/macros_test.rs
Expand Up @@ -2,20 +2,12 @@ use tokio::test;

#[test]
async fn test_macro_can_be_used_via_use() {
tokio::spawn(async {
assert_eq!(1 + 1, 2);
})
.await
.unwrap();
tokio::spawn(async {}).await.unwrap();
}

#[tokio::test]
async fn test_macro_is_resilient_to_shadowing() {
tokio::spawn(async {
assert_eq!(1 + 1, 2);
})
.await
.unwrap();
tokio::spawn(async {}).await.unwrap();
}

// https://github.com/tokio-rs/tokio/issues/3403
Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/task_blocking.rs
Expand Up @@ -132,7 +132,7 @@ fn useful_panic_message_when_dropping_rt_in_rt() {
let err: &'static str = err.downcast_ref::<&'static str>().unwrap();

assert!(
err.find("Cannot drop a runtime").is_some(),
err.contains("Cannot drop a runtime"),
"Wrong panic message: {:?}",
err
);
Expand Down