chore: fix clippy lints (#707)

This commit is contained in:
David Pedersen
2021-07-09 18:23:55 +02:00
committed by GitHub
parent 5aa8ae1fec
commit 4b0ece6d28
19 changed files with 47 additions and 41 deletions
+1 -1
View File
@@ -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(
+1 -1
View File
@@ -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");
}
+1
View File
@@ -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>> {
+7 -1
View File
@@ -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
+1 -3
View File
@@ -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<_>>();
+7 -1
View File
@@ -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
+1 -1
View File
@@ -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");
}
+3 -3
View File
@@ -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(())
}
}
@@ -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"));
};
@@ -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"));
}
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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() {
+1 -1
View File
@@ -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,
}
+7 -14
View File
@@ -2524,8 +2524,7 @@ mod tests {
if key.as_str() == "x-word" {
found_x_word = true;
} else {
// Unexpected key
assert!(false);
panic!("Unexpected key");
}
}
}
@@ -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");
}
}
}
@@ -2567,8 +2565,7 @@ mod tests {
if key.as_str() == "x-word" {
found_x_word = true;
} else {
// Unexpected key
assert!(false);
panic!("Unexpected key");
}
}
}
@@ -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");
}
}
}
@@ -2610,8 +2606,7 @@ mod tests {
if key.as_str() == "x-word" {
found_x_word = true;
} else {
// Unexpected key
assert!(false);
panic!("Unexpected key");
}
}
}
@@ -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");
}
}
}
@@ -2653,8 +2647,7 @@ mod tests {
if *value == "hello" {
found_x_word = true;
} else {
// Unexpected key
assert!(false);
panic!("Unexpected key");
}
}
}
+2
View File
@@ -1,3 +1,5 @@
#![allow(clippy::upper_case_acronyms)]
use super::encoding::{
Ascii, Binary, InvalidMetadataValue, InvalidMetadataValueBytes, ValueEncoding,
};
+4 -4
View File
@@ -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"),
@@ -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);
}
}
+2 -2
View File
@@ -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);
@@ -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
+1 -1
View File
@@ -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 {
+3 -3
View File
@@ -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)?;
@@ -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()),
};
}
@@ -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),