Skip to content

Commit

Permalink
chore: fix clippy lints (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpdrsn committed Jul 9, 2021
1 parent 5aa8ae1 commit 4b0ece6
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion examples/src/blocking/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl BlockingClient {
let rt = Builder::new_multi_thread().enable_all().build().unwrap();
let client = rt.block_on(GreeterClient::connect(dst))?;

Ok(Self { rt, client })
Ok(Self { client, rt })
}

pub fn say_hello(
Expand Down
2 changes: 1 addition & 1 deletion examples/src/reflection/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tonic::{Request, Response, Status};
mod proto {
tonic::include_proto!("helloworld");

pub(crate) const FILE_DESCRIPTOR_SET: &'static [u8] =
pub(crate) const FILE_DESCRIPTOR_SET: &[u8] =
tonic::include_file_descriptor_set!("helloworld_descriptor");
}

Expand Down
1 change: 1 addition & 0 deletions examples/src/tower/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ mod service {
impl Service<Request<BoxBody>> for AuthSvc {
type Response = Response<Body>;
type Error = Box<dyn std::error::Error + Send + Sync>;
#[allow(clippy::type_complexity)]
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Expand Down
8 changes: 7 additions & 1 deletion tonic-build/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ pub fn generate<T: Service>(
/// Generated client implementations.
#(#mod_attributes)*
pub mod #client_mod {
#![allow(unused_variables, dead_code, missing_docs)]
#![allow(
unused_variables,
dead_code,
missing_docs,
// will trigger if compression is disabled
clippy::let_unit_value,
)]
use tonic::codegen::*;

#service_doc
Expand Down
4 changes: 1 addition & 3 deletions tonic-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ fn generate_doc_comments<T: AsRef<str>>(comments: &[T]) -> TokenStream {
pub(crate) fn match_name(pattern: &str, path: &str) -> bool {
if pattern.is_empty() {
false
} else if pattern == "." {
true
} else if pattern == path {
} else if pattern == "." || pattern == path {
true
} else {
let pattern_segments = pattern.split('.').collect::<Vec<_>>();
Expand Down
8 changes: 7 additions & 1 deletion tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ pub fn generate<T: Service>(
/// Generated server implementations.
#(#mod_attributes)*
pub mod #server_mod {
#![allow(unused_variables, dead_code, missing_docs)]
#![allow(
unused_variables,
dead_code,
missing_docs,
// will trigger if compression is disabled
clippy::let_unit_value,
)]
use tonic::codegen::*;

#generated_trait
Expand Down
2 changes: 1 addition & 1 deletion tonic-reflection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) mod proto {
#![allow(unreachable_pub)]
tonic::include_proto!("grpc.reflection.v1alpha");

pub(crate) const FILE_DESCRIPTOR_SET: &'static [u8] =
pub(crate) const FILE_DESCRIPTOR_SET: &[u8] =
tonic::include_file_descriptor_set!("reflection_v1alpha1");
}

Expand Down
6 changes: 3 additions & 3 deletions tonic-reflection/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<'b> Builder<'b> {
field: &FieldDescriptorProto,
) -> Result<(), Error> {
let field_name = extract_name(prefix, "field", field.name.as_ref())?;
self.symbols.insert(field_name, fd.clone());
self.symbols.insert(field_name, fd);
Ok(())
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ impl ReflectionServiceState {
None => Err(Status::not_found(format!("symbol '{}' not found", symbol))),
Some(fd) => {
let mut encoded_fd = Vec::new();
if let Err(_) = fd.clone().encode(&mut encoded_fd) {
if fd.clone().encode(&mut encoded_fd).is_err() {
return Err(Status::internal("encoding error"));
};

Expand All @@ -283,7 +283,7 @@ impl ReflectionServiceState {
None => Err(Status::not_found(format!("file '{}' not found", filename))),
Some(fd) => {
let mut encoded_fd = Vec::new();
if let Err(_) = fd.clone().encode(&mut encoded_fd) {
if fd.clone().encode(&mut encoded_fd).is_err() {
return Err(Status::internal("encoding error"));
}

Expand Down
4 changes: 2 additions & 2 deletions tonic-reflection/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ mod pb {

tonic::include_proto!("grpc.reflection.v1alpha");

pub(crate) const REFLECTION_SERVICE_DESCRIPTOR: &'static [u8] =
pub(crate) const REFLECTION_SERVICE_DESCRIPTOR: &[u8] =
tonic::include_file_descriptor_set!("reflection_v1alpha1");

pub(crate) fn get_encoded_reflection_service_fd() -> Vec<u8> {
let mut expected = Vec::new();
&prost_types::FileDescriptorSet::decode(REFLECTION_SERVICE_DESCRIPTOR)
prost_types::FileDescriptorSet::decode(REFLECTION_SERVICE_DESCRIPTOR)
.expect("decode reflection service file descriptor set")
.file[0]
.encode(&mut expected)
Expand Down
2 changes: 1 addition & 1 deletion tonic-web/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl Encoding {
Self::from_header(headers.get(header::ACCEPT))
}

pub(crate) fn to_content_type(&self) -> &'static str {
pub(crate) fn to_content_type(self) -> &'static str {
match self {
Encoding::Base64 => GRPC_WEB_TEXT_PROTO,
Encoding::None => GRPC_WEB_PROTO,
Expand Down
2 changes: 1 addition & 1 deletion tonic-web/src/cors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
($header:expr, $expected:expr) => {
fn sorted(value: &str) -> Vec<&str> {
let mut vec = value.split(",").collect::<Vec<_>>();
vec.sort();
vec.sort_unstable();
vec
}

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 @@ -65,7 +65,7 @@ async fn smoke_server_stream() {
let r3 = stream(r3).await;
let r4 = stream(r4).await;

assert!(&r1 == &r2 && &r2 == &r3 && &r3 == &r4);
assert!(r1 == r2 && r2 == r3 && r3 == r4);
}
#[tokio::test]
async fn smoke_error() {
Expand Down
2 changes: 1 addition & 1 deletion tonic/src/codec/prost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mod tests {
impl MockBody {
pub(super) fn new(b: &[u8], partial_len: usize, count: usize) -> Self {
MockBody {
data: Bytes::copy_from_slice(&b[..]),
data: Bytes::copy_from_slice(b),
partial_len,
count,
}
Expand Down
21 changes: 7 additions & 14 deletions tonic/src/metadata/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2524,8 +2524,7 @@ mod tests {
if key.as_str() == "x-word" {
found_x_word = true;
} else {
// Unexpected key
assert!(false);
panic!("Unexpected key");
}
}
}
Expand All @@ -2545,8 +2544,7 @@ mod tests {
if key.as_str() == "x-word-bin" {
found_x_word_bin = true;
} else {
// Unexpected key
assert!(false);
panic!("Unexpected key");
}
}
}
Expand All @@ -2567,8 +2565,7 @@ mod tests {
if key.as_str() == "x-word" {
found_x_word = true;
} else {
// Unexpected key
assert!(false);
panic!("Unexpected key");
}
}
}
Expand All @@ -2588,8 +2585,7 @@ mod tests {
if key.as_str() == "x-word-bin" {
found_x_word_bin = true;
} else {
// Unexpected key
assert!(false);
panic!("Unexpected key");
}
}
}
Expand All @@ -2610,8 +2606,7 @@ mod tests {
if key.as_str() == "x-word" {
found_x_word = true;
} else {
// Unexpected key
assert!(false);
panic!("Unexpected key");
}
}
}
Expand All @@ -2631,8 +2626,7 @@ mod tests {
if key.as_str() == "x-number-bin" {
found_x_number_bin = true;
} else {
// Unexpected key
assert!(false);
panic!("Unexpected key");
}
}
}
Expand All @@ -2653,8 +2647,7 @@ mod tests {
if *value == "hello" {
found_x_word = true;
} else {
// Unexpected key
assert!(false);
panic!("Unexpected key");
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tonic/src/metadata/value.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::upper_case_acronyms)]

use super::encoding::{
Ascii, Binary, InvalidMetadataValue, InvalidMetadataValueBytes, ValueEncoding,
};
Expand Down
8 changes: 4 additions & 4 deletions tonic/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ impl Code {
}
}

fn to_header_value(&self) -> HeaderValue {
fn to_header_value(self) -> HeaderValue {
match self {
Code::Ok => HeaderValue::from_static("0"),
Code::Cancelled => HeaderValue::from_static("1"),
Expand Down Expand Up @@ -921,16 +921,16 @@ mod tests {

let status = Status::with_details(Code::Unavailable, "some message", DETAILS.into());

assert_eq!(&status.details()[..], DETAILS);
assert_eq!(status.details(), DETAILS);

let header_map = status.to_header_map().unwrap();

let b64_details = base64::encode_config(&DETAILS[..], base64::STANDARD_NO_PAD);
let b64_details = base64::encode_config(DETAILS, base64::STANDARD_NO_PAD);

assert_eq!(header_map[super::GRPC_STATUS_DETAILS_HEADER], b64_details);

let status = Status::from_header_map(&header_map).unwrap();

assert_eq!(&status.details()[..], DETAILS);
assert_eq!(status.details(), DETAILS);
}
}
4 changes: 2 additions & 2 deletions tonic/src/transport/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Channel {
C::Future: Unpin + Send,
C::Response: AsyncRead + AsyncWrite + HyperConnection + Unpin + Send + 'static,
{
let buffer_size = endpoint.buffer_size.clone().unwrap_or(DEFAULT_BUFFER_SIZE);
let buffer_size = endpoint.buffer_size.unwrap_or(DEFAULT_BUFFER_SIZE);

let svc = Connection::lazy(connector, endpoint);
let svc = Buffer::new(Either::A(svc), buffer_size);
Expand All @@ -152,7 +152,7 @@ impl Channel {
C::Future: Unpin + Send,
C::Response: AsyncRead + AsyncWrite + HyperConnection + Unpin + Send + 'static,
{
let buffer_size = endpoint.buffer_size.clone().unwrap_or(DEFAULT_BUFFER_SIZE);
let buffer_size = endpoint.buffer_size.unwrap_or(DEFAULT_BUFFER_SIZE);

let svc = Connection::connect(connector, endpoint)
.await
Expand Down
2 changes: 1 addition & 1 deletion tonic/src/transport/service/reconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ where
tracing::trace!("Reconnect::call");
if let Some(error) = self.error.take() {
tracing::debug!("error: {}", error);
return ResponseFuture::error(error.into());
return ResponseFuture::error(error);
}

let service = match self.state {
Expand Down
6 changes: 3 additions & 3 deletions tonic/src/transport/service/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl TlsConnector {
domain: String,
) -> Result<Self, crate::Error> {
let mut config = ClientConfig::new();
config.set_protocols(&[Vec::from(&ALPN_H2[..])]);
config.set_protocols(&[Vec::from(ALPN_H2)]);

if let Some(identity) = identity {
let (client_cert, client_key) = rustls_keys::load_identity(identity)?;
Expand All @@ -60,7 +60,7 @@ impl TlsConnector {
{
config.root_store = match rustls_native_certs::load_native_certs() {
Ok(store) | Err((Some(store), _)) => store,
Err((None, error)) => Err(error)?,
Err((None, error)) => return Err(error.into()),
};
}

Expand Down Expand Up @@ -153,7 +153,7 @@ impl TlsAcceptor {
}
};
config.set_single_cert(cert, key)?;
config.set_protocols(&[Vec::from(&ALPN_H2[..])]);
config.set_protocols(&[Vec::from(ALPN_H2)]);

Ok(Self {
inner: Arc::new(config),
Expand Down

0 comments on commit 4b0ece6

Please sign in to comment.