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

tower: fix annoying clippy lints #639

Merged
merged 2 commits into from
Feb 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tower-test/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ macro_rules! assert_request_eq {
Some(r) => r,
None => panic!("expected a request but none was received."),
};

assert_eq!(actual, $expect, $($arg)*);
// In some cases, this may be used with `bool` as the `Request` type, in
// which case, clippy emits a warning. However, this can't be changed to
// `assert!`, because the request type may *not* be `bool`...
#[allow(clippy::bool_assert_comparison)]
{
assert_eq!(actual, $expect, $($arg)*);
}
send_response
}};
}
4 changes: 2 additions & 2 deletions tower/examples/tower-balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn main() {
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_nanos() / 1_000 / 1_000);
let l = max.as_secs() * 1_000 + u64::from(max.subsec_millis());
print!("{}ms, ", l);
}
println!("]");
Expand Down Expand Up @@ -122,7 +122,7 @@ fn gen_disco() -> impl Discover<
let svc = tower::service_fn(move |_| {
let start = Instant::now();

let maxms = u64::from(latency.subsec_nanos() / 1_000 / 1_000)
let maxms = u64::from(latency.subsec_millis())
.saturating_add(latency.as_secs().saturating_mul(1_000));
let latency = Duration::from_millis(rand::thread_rng().gen_range(0..maxms));

Expand Down
2 changes: 1 addition & 1 deletion tower/src/balance/p2c/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn single_endpoint() {
handle.send_error("endpoint lost");
assert_pending!(svc.poll_ready());
assert!(
svc.get_ref().len() == 0,
svc.get_ref().is_empty(),
"balancer must drop failed endpoints"
);
}
Expand Down
2 changes: 1 addition & 1 deletion tower/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ where
fn call(&mut self, request: Request) -> Self::Future {
ResponseFuture::new(match self.predicate.check(request) {
Ok(request) => Either::Right(self.inner.call(request).err_into()),
Err(e) => Either::Left(futures_util::future::ready(Err(e.into()))),
Err(e) => Either::Left(futures_util::future::ready(Err(e))),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion tower/src/limit/rate/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ where
match self.state {
State::Ready { .. } => return Poll::Ready(ready!(self.inner.poll_ready(cx))),
State::Limited => {
if let Poll::Pending = Pin::new(&mut self.sleep).poll(cx) {
if Pin::new(&mut self.sleep).poll(cx).is_pending() {
tracing::trace!("rate limit exceeded; sleeping.");
return Poll::Pending;
}
Expand Down
5 changes: 4 additions & 1 deletion tower/src/steer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ where
if self.not_ready.is_empty() {
return Poll::Ready(Ok(()));
} else {
if let Poll::Pending = self.services[self.not_ready[0]].poll_ready(cx)? {
if self.services[self.not_ready[0]]
.poll_ready(cx)?
.is_pending()
{
return Poll::Pending;
}

Expand Down
2 changes: 1 addition & 1 deletion tower/tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn builder_service() {

let fut = client.ready().await.unwrap().call("hello");
assert_request_eq!(handle, true).send_response("world");
assert_eq!(fut.await.unwrap(), true);
assert!(fut.await.unwrap());
}

#[derive(Debug, Clone, Default)]
Expand Down