style: address clippy lints (#827)

This commit is contained in:
Jonas Platte 2025-06-12 19:30:19 +02:00 committed by GitHub
parent ec81e5797b
commit 6a3ab07b4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 35 additions and 32 deletions

View File

@ -18,7 +18,7 @@ lazy_static = "1.4.0"
pin-project-lite = "0.2.7"
quickcheck = "1"
rand = "0.8"
slab = "0.4"
slab = "0.4.9"
sync_wrapper = "1"
tokio = "1.6.2"
tokio-stream = "0.1.0"

View File

@ -109,7 +109,7 @@ mod tests {
assert_eq!(
"LayerFn { f: tower_layer::layer_fn::tests::layer_fn_has_useful_debug_impl::{{closure}} }".to_string(),
format!("{:?}", layer),
format!("{layer:?}"),
);
}
}

View File

@ -105,7 +105,7 @@ pub trait Layer<S> {
fn layer(&self, inner: S) -> Self::Service;
}
impl<'a, T, S> Layer<S> for &'a T
impl<T, S> Layer<S> for &T
where
T: ?Sized + Layer<S>,
{

View File

@ -18,7 +18,6 @@ use std::{
future::Future,
sync::{Arc, Mutex},
task::{Context, Poll},
u64,
};
/// Spawn a layer onto a mock service.

View File

@ -46,13 +46,13 @@ struct Summary {
async fn main() {
tracing::subscriber::set_global_default(tracing_subscriber::FmtSubscriber::default()).unwrap();
println!("REQUESTS={}", REQUESTS);
println!("CONCURRENCY={}", CONCURRENCY);
println!("ENDPOINT_CAPACITY={}", ENDPOINT_CAPACITY);
println!("REQUESTS={REQUESTS}");
println!("CONCURRENCY={CONCURRENCY}");
println!("ENDPOINT_CAPACITY={ENDPOINT_CAPACITY}");
print!("MAX_ENDPOINT_LATENCIES=[");
for max in &MAX_ENDPOINT_LATENCIES {
let l = max.as_secs() * 1_000 + u64::from(max.subsec_millis());
print!("{}ms, ", l);
print!("{l}ms, ");
}
println!("]");
@ -149,7 +149,7 @@ where
<D::Service as Service<Req>>::Future: Send,
<D::Service as load::Load>::Metric: std::fmt::Debug,
{
println!("{}", name);
println!("{name}");
let requests = stream::repeat(Req).take(REQUESTS);
let service = ConcurrencyLimit::new(lb, CONCURRENCY);
@ -193,7 +193,7 @@ impl Summary {
}
for (i, c) in self.count_by_instance.iter().enumerate() {
let p = *c as f64 / total as f64 * 100.0;
println!(" [{:02}] {:>5.01}%", i, p);
println!(" [{i:02}] {p:>5.01}%");
}
println!(" wall {:4}s", self.start.elapsed().as_secs());

View File

@ -56,7 +56,7 @@ where
}
impl<Request> fmt::Debug for BufferLayer<Request> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("BufferLayer")
.field("bound", &self.bound)
.finish()
@ -65,10 +65,7 @@ impl<Request> fmt::Debug for BufferLayer<Request> {
impl<Request> Clone for BufferLayer<Request> {
fn clone(&self) -> Self {
Self {
bound: self.bound,
_p: PhantomData,
}
*self
}
}

View File

@ -398,7 +398,7 @@ mod tests {
assert_eq!(super::nanos(Duration::new(0, 123)), 123.0);
assert_eq!(super::nanos(Duration::new(1, 23)), 1_000_000_023.0);
assert_eq!(
super::nanos(Duration::new(::std::u64::MAX, 999_999_999)),
super::nanos(Duration::new(u64::MAX, 999_999_999)),
18446744074709553000.0
);
}

View File

@ -72,7 +72,7 @@ impl TpsBudget {
assert!(ttl <= Duration::from_secs(60));
assert!(retry_percent >= 0.0);
assert!(retry_percent <= 1000.0);
assert!(min_per_sec < ::std::i32::MAX as u32);
assert!(min_per_sec < i32::MAX as u32);
let (deposit_amount, withdraw_amount) = if retry_percent == 0.0 {
// If there is no percent, then you gain nothing from deposits.

View File

@ -186,14 +186,14 @@ mod tests {
let mut pending_svc = future_service(ready(Ok(DebugService)));
assert_eq!(
format!("{:?}", pending_svc),
format!("{pending_svc:?}"),
"FutureService { state: State::Future(<core::future::ready::Ready<core::result::Result<tower::util::future_service::tests::DebugService, core::convert::Infallible>>>) }"
);
pending_svc.ready().await.unwrap();
assert_eq!(
format!("{:?}", pending_svc),
format!("{pending_svc:?}"),
"FutureService { state: State::Service(DebugService) }"
);
}

View File

@ -88,7 +88,7 @@ where
loop {
match this.state.as_mut().project() {
StateProj::NotReady { svc, req } => {
let _ = ready!(svc.poll_ready(cx))?;
ready!(svc.poll_ready(cx))?;
let f = svc.call(req.take().expect("already called"));
this.state.set(State::called(f));
}

View File

@ -132,20 +132,24 @@ mod tests {
quickcheck! {
fn next_f64(counter: u64) -> TestResult {
let mut rng = HasherRng::default();
rng.counter = counter;
let mut rng = HasherRng {
counter,
..HasherRng::default()
};
let n = rng.next_f64();
TestResult::from_bool(n < 1.0 && n >= 0.0)
TestResult::from_bool((0.0..1.0).contains(&n))
}
fn next_range(counter: u64, range: Range<u64>) -> TestResult {
if range.start >= range.end{
if range.start >= range.end{
return TestResult::discard();
}
let mut rng = HasherRng::default();
rng.counter = counter;
let mut rng = HasherRng {
counter,
..HasherRng::default()
};
let n = rng.next_range(range.clone());
@ -153,12 +157,14 @@ mod tests {
}
fn sample_floyd2(counter: u64, length: u64) -> TestResult {
if length < 2 || length > 256 {
if !(2..=256).contains(&length) {
return TestResult::discard();
}
let mut rng = HasherRng::default();
rng.counter = counter;
let mut rng = HasherRng {
counter,
..HasherRng::default()
};
let [a, b] = super::sample_floyd2(&mut rng, length);

View File

@ -45,7 +45,7 @@ fn stress() {
for _ in 0..100_000 {
for _ in 0..(rand::random::<u8>() % 8) {
if !services.is_empty() && rand::random() {
if nready == 0 || rand::random::<u8>() > u8::max_value() / 4 {
if nready == 0 || rand::random::<u8>() > u8::MAX / 4 {
// ready a service
// TODO: sometimes ready a removed service?
for (_, (handle, ready)) in &mut services {
@ -114,7 +114,8 @@ fn stress() {
} else {
// remove
while !services.is_empty() {
let k = rand::random::<usize>() % (services.iter().last().unwrap().0 + 1);
let k =
rand::random::<usize>() % (services.iter().next_back().unwrap().0 + 1);
if services.contains(k) {
let (handle, ready) = services.remove(k);
if ready {
@ -129,7 +130,7 @@ fn stress() {
} else {
// fail a service
while !services.is_empty() {
let k = rand::random::<usize>() % (services.iter().last().unwrap().0 + 1);
let k = rand::random::<usize>() % (services.iter().next_back().unwrap().0 + 1);
if services.contains(k) {
let (mut handle, ready) = services.remove(k);
if ready {