clippy:
name: clippy
runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ rustflags:
+ - ""
+ - "--cfg tokio_unstable --cfg tokio_taskdump --cfg tokio_uring -Dwarnings"
steps:
- uses: actions/checkout@v4
- name: Install Rust ${{ env.rust_clippy }}
components: clippy
- uses: Swatinem/rust-cache@v2
# Run clippy
- - name: "clippy --all"
+ - name: "clippy --all ${{ matrix.rustflags }}"
run: cargo clippy --all --tests --all-features --no-deps
-
+ env:
+ RUSTFLAGS: ${{ matrix.rustflags }}
docs:
name: docs
runs-on: ${{ matrix.run.os }}
/// # Ok(())
/// # }
/// ```
+ #[allow(clippy::result_large_err)]
pub fn try_into_std(mut self) -> Result<StdFile, Self> {
match Arc::try_unwrap(self.std) {
Ok(file) => Ok(file),
let name = sym.name();
Self {
name: name.as_ref().map(|name| name.as_bytes().into()),
- name_demangled: name.map(|name| format!("{}", name).into()),
+ name_demangled: name.map(|name| format!("{name}").into()),
addr: sym.addr().map(Address),
filename: sym.filename().map(From::from),
lineno: sym.lineno(),
const DEFAULT_RING_SIZE: u32 = 256;
#[repr(usize)]
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq, Copy, Clone)]
enum State {
Uninitialized = 0,
Initialized = 1,
}
impl State {
- fn as_usize(self) -> usize {
- self as usize
+ fn as_usize(&self) -> usize {
+ *self as usize
}
fn from_usize(value: usize) -> Self {
ops.remove(idx);
}
Some(other) => {
- panic!("unexpected lifecycle for slot {}: {:?}", idx, other);
+ panic!("unexpected lifecycle for slot {idx}: {other:?}");
}
None => {
- panic!("no op at index {}", idx);
+ panic!("no op at index {idx}");
}
}
}
// We can safely remove the entry from the slab, as it has already been completed.
ops.remove(index);
}
- prev => panic!("Unexpected state: {:?}", prev),
+ prev => panic!("Unexpected state: {prev:?}"),
};
}
}
}
pub(crate) fn legacy_mut(&mut self, f: impl Fn(&mut LegacyBuilder)) {
- let legacy = self.legacy.get_or_insert_with(|| LegacyBuilder::default());
+ let legacy = self.legacy.get_or_insert_with(LegacyBuilder::default);
f(legacy);
}
/// - If `bucket_offset` is greater than the specified number of buckets, `(n - p + 1) * 2^p`
fn from_n_p(n: u32, p: u32, bucket_offset: usize) -> Self {
assert!(n >= p, "{n} (n) must be at least as large as {p} (p)");
- let num_buckets = ((n - p + 1) * 1 << p) as usize - bucket_offset;
+ let num_buckets = ((n - p + 1) << p) as usize - bucket_offset;
Self {
num_buckets,
p,
}
fn truncate_to_max_value(&self, max_value: u64) -> LogHistogram {
- let mut hist = self.clone();
+ let mut hist = *self;
while hist.max_value() >= max_value {
hist.num_buckets -= 1;
}
pub(crate) fn value_to_bucket(&self, value: u64) -> usize {
let index = bucket_index(value, self.p);
- let offset_bucket = if index < self.bucket_offset as u64 {
- 0
- } else {
- index - self.bucket_offset as u64
- };
+ let offset_bucket = index.saturating_sub(self.bucket_offset as u64);
let max = self.num_buckets - 1;
offset_bucket.min(max as u64) as usize
}
assert!(max_error > 0.0, "max_error must be greater than 0");
assert!(max_error < 1.0, "max_error must be less than 1");
let mut p = 2;
- while 2_f64.powf(-1.0 * p as f64) > max_error && p <= MAX_PRECISION {
+ while 2_f64.powf(-(p as f64)) > max_error && p <= MAX_PRECISION {
p += 1;
}
self.precision = Some(p);
assert_eq!(
config.value_to_bucket(i as u64),
i,
- "{} should be in bucket {}",
- i,
- i
+ "{i} should be in bucket {i}"
);
}
let trace_status = &self.shared.trace_status;
// If a dump is in progress, block.
- trace_status.start_trace_request(&self).await;
+ trace_status.start_trace_request(self).await;
let result = loop {
if let Some(result) = trace_status.take_result() {
};
// Allow other queued dumps to proceed.
- trace_status.end_trace_request(&self).await;
+ trace_status.end_trace_request(self).await;
result
}
impl<S> Notified<S> {
#[cfg(all(tokio_unstable, feature = "rt-multi-thread"))]
#[inline]
- pub(crate) fn task_meta<'task, 'meta>(&'task self) -> crate::runtime::TaskMeta<'meta> {
+ pub(crate) fn task_meta<'meta>(&self) -> crate::runtime::TaskMeta<'meta> {
self.0.task_meta()
}
}
impl<S> LocalNotified<S> {
#[cfg(tokio_unstable)]
#[inline]
- pub(crate) fn task_meta<'task, 'meta>(&'task self) -> crate::runtime::TaskMeta<'meta> {
+ pub(crate) fn task_meta<'meta>(&self) -> crate::runtime::TaskMeta<'meta> {
self.task.task_meta()
}
}
// the compiler infers the lifetimes to be the same, and considers the task
// to be borrowed for the lifetime of the returned `TaskMeta`.
#[cfg(tokio_unstable)]
- pub(crate) fn task_meta<'task, 'meta>(&'task self) -> crate::runtime::TaskMeta<'meta> {
+ pub(crate) fn task_meta<'meta>(&self) -> crate::runtime::TaskMeta<'meta> {
crate::runtime::TaskMeta {
id: self.id(),
spawned_at: self.spawned_at().into(),
is_last: bool,
prefix: &str,
) -> fmt::Result {
- let root_fmt = format!("{}", root);
+ let root_fmt = format!("{root}");
let current;
let next;
if is_last {
current = format!("{prefix}└╼\u{a0}{root_fmt}");
- next = format!("{}\u{a0}\u{a0}\u{a0}", prefix);
+ next = format!("{prefix}\u{a0}\u{a0}\u{a0}");
} else {
current = format!("{prefix}├╼\u{a0}{root_fmt}");
- next = format!("{}│\u{a0}\u{a0}", prefix);
+ next = format!("{prefix}│\u{a0}\u{a0}");
}
write!(f, "{}", {
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
fn deterministic_select_multi_thread() {
let seed = b"bytes used to generate seed";
+ let (tx, rx) = std::sync::mpsc::channel();
let rt1 = tokio::runtime::Builder::new_multi_thread()
.worker_threads(1)
+ .on_thread_park(move || tx.send(()).unwrap())
.rng_seed(RngSeed::from_bytes(seed))
.build()
.unwrap();
+
+ // This makes sure that `enter_runtime()` from worker thread is called before the one from main thread,
+ // ensuring that the RNG state is consistent. See also https://github.com/tokio-rs/tokio/pull/7495.
+ rx.recv().unwrap();
+
let rt1_values = rt1.block_on(async {
- let _ = tokio::spawn(async { (select_0_to_9().await, select_0_to_9().await) }).await;
+ tokio::spawn(async { (select_0_to_9().await, select_0_to_9().await) })
+ .await
+ .unwrap()
});
+ let (tx, rx) = std::sync::mpsc::channel();
let rt2 = tokio::runtime::Builder::new_multi_thread()
.worker_threads(1)
+ .on_thread_park(move || tx.send(()).unwrap())
.rng_seed(RngSeed::from_bytes(seed))
.build()
.unwrap();
+
+ // This makes sure that `enter_runtime()` from worker thread is called before the one from main thread,
+ // ensuring that the RNG state is consistent. See also https://github.com/tokio-rs/tokio/pull/7495.
+ rx.recv().unwrap();
+
let rt2_values = rt2.block_on(async {
- let _ = tokio::spawn(async { (select_0_to_9().await, select_0_to_9().await) }).await;
+ tokio::spawn(async { (select_0_to_9().await, select_0_to_9().await) })
+ .await
+ .unwrap()
});
assert_eq!(rt1_values, rt2_values);
let count_realized = count.load(Ordering::SeqCst);
assert_eq!(
TASKS, count_realized,
- "Total number of spawned task hook invocations was incorrect, expected {TASKS}, got {}",
- count_realized
+ "Total number of spawned task hook invocations was incorrect, expected {TASKS}, got {count_realized}"
);
let count_ids_realized = ids.lock().unwrap().len();
assert_eq!(
TASKS, count_ids_realized,
- "Total number of spawned task hook invocations was incorrect, expected {TASKS}, got {}",
- count_realized
+ "Total number of spawned task hook invocations was incorrect, expected {TASKS}, got {count_realized}"
);
}
event: &'static str,
count: &Arc<AtomicUsize>,
) -> impl Fn(&tokio::runtime::TaskMeta<'_>) {
- let count = Arc::clone(&count);
+ let count = Arc::clone(count);
move |data| {
eprintln!("{event} ({:?}): {:?}", data.id(), data.spawned_at());
// Assert that the spawn location is in this file.
count += 1;
joined.insert(id);
}
- Some(Err(err)) => panic!("failed: {}", err),
+ Some(Err(err)) => panic!("failed: {err}"),
None => {
break;
}
for line in good_line {
let s = format!("{}:{}:", file!(), line);
assert!(log.lock().unwrap().iter().any(|x| {
- eprintln!("{}", x);
- format!("{}", x).contains(&s)
+ eprintln!("{x}");
+ format!("{x}").contains(&s)
}));
}
for line in bad_line {
.lock()
.unwrap()
.iter()
- .any(|x| format!("{}", x).contains(&s)));
+ .any(|x| format!("{x}").contains(&s)));
}
}
.named("runtime.spawn")
.with_target("tokio::task")
.with_fields(
- expect::field("task.name").with_value(&tracing::field::debug(format_args!("{}", name))),
+ expect::field("task.name").with_value(&tracing::field::debug(format_args!("{name}"))),
)
}