Skip to content

Commit

Permalink
chore: Fix clippy warning (#1500)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucio Franco <[email protected]>
  • Loading branch information
tottoto and LucioFranco authored Nov 13, 2023
1 parent ff71e89 commit 522a8d7
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 26 deletions.
12 changes: 6 additions & 6 deletions codegen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};

fn main() {
// tonic-health
Expand Down Expand Up @@ -45,11 +45,11 @@ fn main() {
}

fn codegen(
root_dir: &PathBuf,
root_dir: &Path,
iface_files: &[&str],
include_dirs: &[&str],
out_dir: &PathBuf,
file_descriptor_set_path: &PathBuf,
out_dir: &Path,
file_descriptor_set_path: &Path,
build_client: bool,
build_server: bool,
) {
Expand All @@ -59,12 +59,12 @@ fn codegen(
.unwrap();

let iface_files: Vec<PathBuf> = iface_files
.into_iter()
.iter()
.map(|&path| root_dir.join(path))
.collect();

let include_dirs: Vec<PathBuf> = include_dirs
.into_iter()
.iter()
.map(|&path| root_dir.join(path))
.collect();
let out_dir = root_dir.join(out_dir);
Expand Down
10 changes: 2 additions & 8 deletions examples/src/dynamic/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ impl Echo for MyEcho {
}

fn init_echo(args: &[String], builder: &mut RoutesBuilder) {
let enabled = args
.into_iter()
.find(|arg| arg.as_str() == "echo")
.is_some();
let enabled = args.iter().any(|arg| arg.as_str() == "echo");
if enabled {
println!("Adding Echo service...");
let svc = EchoServer::new(MyEcho::default());
Expand All @@ -62,10 +59,7 @@ impl Greeter for MyGreeter {
}

fn init_greeter(args: &[String], builder: &mut RoutesBuilder) {
let enabled = args
.into_iter()
.find(|arg| arg.as_str() == "greeter")
.is_some();
let enabled = args.iter().any(|arg| arg.as_str() == "greeter");

if enabled {
println!("Adding Greeter service...");
Expand Down
2 changes: 2 additions & 0 deletions tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::{Ident, Lit, LitStr};

#[allow(clippy::too_many_arguments)]
pub(crate) fn generate_internal<T: Service>(
service: &T,
emit_package: bool,
Expand Down Expand Up @@ -209,6 +210,7 @@ pub(crate) fn generate_internal<T: Service>(
}
}

#[allow(clippy::too_many_arguments)]
fn generate_trait<T: Service>(
service: &T,
emit_package: bool,
Expand Down
8 changes: 4 additions & 4 deletions tonic-web/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ fn make_trailers_frame(trailers: HeaderMap) -> Vec<u8> {
/// or the buffer just contained grpc message frames.
fn find_trailers(buf: &[u8]) -> Result<FindTrailers, Status> {
let mut len = 0;
let mut temp_buf = &buf[..];
let mut temp_buf = buf;

loop {
// To check each frame, there must be at least GRPC_HEADER_SIZE
Expand Down Expand Up @@ -457,7 +457,7 @@ fn find_trailers(buf: &[u8]) -> Result<FindTrailers, Status> {
return Ok(FindTrailers::IncompleteBuf);
}

temp_buf = &buf[len as usize..];
temp_buf = &buf[len..];
}
}

Expand Down Expand Up @@ -514,7 +514,7 @@ mod tests {
fn find_trailers_non_buffered() {
// Byte version of this:
// b"\x80\0\0\0\x0fgrpc-status:0\r\n"
let buf = vec![
let buf = [
128, 0, 0, 0, 15, 103, 114, 112, 99, 45, 115, 116, 97, 116, 117, 115, 58, 48, 13, 10,
];

Expand All @@ -527,7 +527,7 @@ mod tests {
fn find_trailers_buffered() {
// Byte version of this:
// b"\0\0\0\0L\n$975738af-1a17-4aea-b887-ed0bbced6093\x1a$da609e9b-f470-4cc0-a691-3fd6a005a436\x80\0\0\0\x0fgrpc-status:0\r\n"
let buf = vec![
let buf = [
0, 0, 0, 0, 76, 10, 36, 57, 55, 53, 55, 51, 56, 97, 102, 45, 49, 97, 49, 55, 45, 52,
97, 101, 97, 45, 98, 56, 56, 55, 45, 101, 100, 48, 98, 98, 99, 101, 100, 54, 48, 57,
51, 26, 36, 100, 97, 54, 48, 57, 101, 57, 98, 45, 102, 52, 55, 48, 45, 52, 99, 99, 48,
Expand Down
2 changes: 1 addition & 1 deletion tonic-web/tests/integration/tests/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async fn spawn() -> Result<(Client, Client, Client, Client), Error> {
let ((s1, u1), (s2, u2), (s3, u3), (s4, u4)) =
join!(grpc(true), grpc(false), grpc_web(true), grpc_web(false));

let _ = tokio::spawn(async move { join!(s1, s2, s3, s4) });
drop(tokio::spawn(async move { join!(s1, s2, s3, s4) }));

tokio::time::sleep(Duration::from_millis(30)).await;

Expand Down
4 changes: 2 additions & 2 deletions tonic-web/tests/integration/tests/grpc_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ async fn spawn() -> String {
let url = format!("http://{}", listener.local_addr().unwrap());
let listener_stream = TcpListenerStream::new(listener);

let _ = tokio::spawn(async move {
drop(tokio::spawn(async move {
Server::builder()
.accept_http1(true)
.layer(GrpcWebLayer::new())
.add_service(TestServer::new(Svc))
.serve_with_incoming(listener_stream)
.await
.unwrap()
});
}));

url
}
Expand Down
4 changes: 2 additions & 2 deletions tonic/src/codec/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ where
BytesMut::new()
};

return EncodedBytes {
Self {
source: Fuse::new(source),
encoder,
compression_encoding,
max_message_size,
buf,
uncompression_buf,
};
}
}
}

Expand Down
1 change: 0 additions & 1 deletion tonic/src/codec/prost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ mod tests {
}
}

#[allow(clippy::drop_ref)]
fn poll_trailers(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
Expand Down
2 changes: 1 addition & 1 deletion tonic/src/metadata/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ impl<VE: ValueEncoding> Eq for MetadataValue<VE> {}
impl<VE: ValueEncoding> PartialOrd for MetadataValue<VE> {
#[inline]
fn partial_cmp(&self, other: &MetadataValue<VE>) -> Option<cmp::Ordering> {
self.inner.partial_cmp(&other.inner)
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tonic/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl Status {
.expect("Invalid status header, expected base64 encoded value")
})
.map(Bytes::from)
.unwrap_or_else(Bytes::new);
.unwrap_or_default();

let mut other_headers = header_map.clone();
other_headers.remove(GRPC_STATUS_HEADER_CODE);
Expand Down

0 comments on commit 522a8d7

Please sign in to comment.