chore: fix clippy lints (#707)
This commit is contained in:
@@ -27,7 +27,7 @@ impl BlockingClient {
|
|||||||
let rt = Builder::new_multi_thread().enable_all().build().unwrap();
|
let rt = Builder::new_multi_thread().enable_all().build().unwrap();
|
||||||
let client = rt.block_on(GreeterClient::connect(dst))?;
|
let client = rt.block_on(GreeterClient::connect(dst))?;
|
||||||
|
|
||||||
Ok(Self { rt, client })
|
Ok(Self { client, rt })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn say_hello(
|
pub fn say_hello(
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use tonic::{Request, Response, Status};
|
|||||||
mod proto {
|
mod proto {
|
||||||
tonic::include_proto!("helloworld");
|
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");
|
tonic::include_file_descriptor_set!("helloworld_descriptor");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ mod service {
|
|||||||
impl Service<Request<BoxBody>> for AuthSvc {
|
impl Service<Request<BoxBody>> for AuthSvc {
|
||||||
type Response = Response<Body>;
|
type Response = Response<Body>;
|
||||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
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>>;
|
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>> {
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
|
|||||||
@@ -36,7 +36,13 @@ pub fn generate<T: Service>(
|
|||||||
/// Generated client implementations.
|
/// Generated client implementations.
|
||||||
#(#mod_attributes)*
|
#(#mod_attributes)*
|
||||||
pub mod #client_mod {
|
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::*;
|
use tonic::codegen::*;
|
||||||
|
|
||||||
#service_doc
|
#service_doc
|
||||||
|
|||||||
@@ -284,9 +284,7 @@ fn generate_doc_comments<T: AsRef<str>>(comments: &[T]) -> TokenStream {
|
|||||||
pub(crate) fn match_name(pattern: &str, path: &str) -> bool {
|
pub(crate) fn match_name(pattern: &str, path: &str) -> bool {
|
||||||
if pattern.is_empty() {
|
if pattern.is_empty() {
|
||||||
false
|
false
|
||||||
} else if pattern == "." {
|
} else if pattern == "." || pattern == path {
|
||||||
true
|
|
||||||
} else if pattern == path {
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
let pattern_segments = pattern.split('.').collect::<Vec<_>>();
|
let pattern_segments = pattern.split('.').collect::<Vec<_>>();
|
||||||
|
|||||||
@@ -69,7 +69,13 @@ pub fn generate<T: Service>(
|
|||||||
/// Generated server implementations.
|
/// Generated server implementations.
|
||||||
#(#mod_attributes)*
|
#(#mod_attributes)*
|
||||||
pub mod #server_mod {
|
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::*;
|
use tonic::codegen::*;
|
||||||
|
|
||||||
#generated_trait
|
#generated_trait
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ pub(crate) mod proto {
|
|||||||
#![allow(unreachable_pub)]
|
#![allow(unreachable_pub)]
|
||||||
tonic::include_proto!("grpc.reflection.v1alpha");
|
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");
|
tonic::include_file_descriptor_set!("reflection_v1alpha1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ impl<'b> Builder<'b> {
|
|||||||
field: &FieldDescriptorProto,
|
field: &FieldDescriptorProto,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let field_name = extract_name(prefix, "field", field.name.as_ref())?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ impl ReflectionServiceState {
|
|||||||
None => Err(Status::not_found(format!("symbol '{}' not found", symbol))),
|
None => Err(Status::not_found(format!("symbol '{}' not found", symbol))),
|
||||||
Some(fd) => {
|
Some(fd) => {
|
||||||
let mut encoded_fd = Vec::new();
|
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"));
|
return Err(Status::internal("encoding error"));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -283,7 +283,7 @@ impl ReflectionServiceState {
|
|||||||
None => Err(Status::not_found(format!("file '{}' not found", filename))),
|
None => Err(Status::not_found(format!("file '{}' not found", filename))),
|
||||||
Some(fd) => {
|
Some(fd) => {
|
||||||
let mut encoded_fd = Vec::new();
|
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"));
|
return Err(Status::internal("encoding error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ mod pb {
|
|||||||
|
|
||||||
tonic::include_proto!("grpc.reflection.v1alpha");
|
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");
|
tonic::include_file_descriptor_set!("reflection_v1alpha1");
|
||||||
|
|
||||||
pub(crate) fn get_encoded_reflection_service_fd() -> Vec<u8> {
|
pub(crate) fn get_encoded_reflection_service_fd() -> Vec<u8> {
|
||||||
let mut expected = Vec::new();
|
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")
|
.expect("decode reflection service file descriptor set")
|
||||||
.file[0]
|
.file[0]
|
||||||
.encode(&mut expected)
|
.encode(&mut expected)
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ impl Encoding {
|
|||||||
Self::from_header(headers.get(header::ACCEPT))
|
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 {
|
match self {
|
||||||
Encoding::Base64 => GRPC_WEB_TEXT_PROTO,
|
Encoding::Base64 => GRPC_WEB_TEXT_PROTO,
|
||||||
Encoding::None => GRPC_WEB_PROTO,
|
Encoding::None => GRPC_WEB_PROTO,
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ mod tests {
|
|||||||
($header:expr, $expected:expr) => {
|
($header:expr, $expected:expr) => {
|
||||||
fn sorted(value: &str) -> Vec<&str> {
|
fn sorted(value: &str) -> Vec<&str> {
|
||||||
let mut vec = value.split(",").collect::<Vec<_>>();
|
let mut vec = value.split(",").collect::<Vec<_>>();
|
||||||
vec.sort();
|
vec.sort_unstable();
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ async fn smoke_server_stream() {
|
|||||||
let r3 = stream(r3).await;
|
let r3 = stream(r3).await;
|
||||||
let r4 = stream(r4).await;
|
let r4 = stream(r4).await;
|
||||||
|
|
||||||
assert!(&r1 == &r2 && &r2 == &r3 && &r3 == &r4);
|
assert!(r1 == r2 && r2 == r3 && r3 == r4);
|
||||||
}
|
}
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn smoke_error() {
|
async fn smoke_error() {
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ mod tests {
|
|||||||
impl MockBody {
|
impl MockBody {
|
||||||
pub(super) fn new(b: &[u8], partial_len: usize, count: usize) -> Self {
|
pub(super) fn new(b: &[u8], partial_len: usize, count: usize) -> Self {
|
||||||
MockBody {
|
MockBody {
|
||||||
data: Bytes::copy_from_slice(&b[..]),
|
data: Bytes::copy_from_slice(b),
|
||||||
partial_len,
|
partial_len,
|
||||||
count,
|
count,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2524,8 +2524,7 @@ mod tests {
|
|||||||
if key.as_str() == "x-word" {
|
if key.as_str() == "x-word" {
|
||||||
found_x_word = true;
|
found_x_word = true;
|
||||||
} else {
|
} else {
|
||||||
// Unexpected key
|
panic!("Unexpected key");
|
||||||
assert!(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2545,8 +2544,7 @@ mod tests {
|
|||||||
if key.as_str() == "x-word-bin" {
|
if key.as_str() == "x-word-bin" {
|
||||||
found_x_word_bin = true;
|
found_x_word_bin = true;
|
||||||
} else {
|
} else {
|
||||||
// Unexpected key
|
panic!("Unexpected key");
|
||||||
assert!(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2567,8 +2565,7 @@ mod tests {
|
|||||||
if key.as_str() == "x-word" {
|
if key.as_str() == "x-word" {
|
||||||
found_x_word = true;
|
found_x_word = true;
|
||||||
} else {
|
} else {
|
||||||
// Unexpected key
|
panic!("Unexpected key");
|
||||||
assert!(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2588,8 +2585,7 @@ mod tests {
|
|||||||
if key.as_str() == "x-word-bin" {
|
if key.as_str() == "x-word-bin" {
|
||||||
found_x_word_bin = true;
|
found_x_word_bin = true;
|
||||||
} else {
|
} else {
|
||||||
// Unexpected key
|
panic!("Unexpected key");
|
||||||
assert!(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2610,8 +2606,7 @@ mod tests {
|
|||||||
if key.as_str() == "x-word" {
|
if key.as_str() == "x-word" {
|
||||||
found_x_word = true;
|
found_x_word = true;
|
||||||
} else {
|
} else {
|
||||||
// Unexpected key
|
panic!("Unexpected key");
|
||||||
assert!(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2631,8 +2626,7 @@ mod tests {
|
|||||||
if key.as_str() == "x-number-bin" {
|
if key.as_str() == "x-number-bin" {
|
||||||
found_x_number_bin = true;
|
found_x_number_bin = true;
|
||||||
} else {
|
} else {
|
||||||
// Unexpected key
|
panic!("Unexpected key");
|
||||||
assert!(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2653,8 +2647,7 @@ mod tests {
|
|||||||
if *value == "hello" {
|
if *value == "hello" {
|
||||||
found_x_word = true;
|
found_x_word = true;
|
||||||
} else {
|
} else {
|
||||||
// Unexpected key
|
panic!("Unexpected key");
|
||||||
assert!(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::upper_case_acronyms)]
|
||||||
|
|
||||||
use super::encoding::{
|
use super::encoding::{
|
||||||
Ascii, Binary, InvalidMetadataValue, InvalidMetadataValueBytes, ValueEncoding,
|
Ascii, Binary, InvalidMetadataValue, InvalidMetadataValueBytes, ValueEncoding,
|
||||||
};
|
};
|
||||||
|
|||||||
+4
-4
@@ -738,7 +738,7 @@ impl Code {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_header_value(&self) -> HeaderValue {
|
fn to_header_value(self) -> HeaderValue {
|
||||||
match self {
|
match self {
|
||||||
Code::Ok => HeaderValue::from_static("0"),
|
Code::Ok => HeaderValue::from_static("0"),
|
||||||
Code::Cancelled => HeaderValue::from_static("1"),
|
Code::Cancelled => HeaderValue::from_static("1"),
|
||||||
@@ -921,16 +921,16 @@ mod tests {
|
|||||||
|
|
||||||
let status = Status::with_details(Code::Unavailable, "some message", DETAILS.into());
|
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 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);
|
assert_eq!(header_map[super::GRPC_STATUS_DETAILS_HEADER], b64_details);
|
||||||
|
|
||||||
let status = Status::from_header_map(&header_map).unwrap();
|
let status = Status::from_header_map(&header_map).unwrap();
|
||||||
|
|
||||||
assert_eq!(&status.details()[..], DETAILS);
|
assert_eq!(status.details(), DETAILS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ impl Channel {
|
|||||||
C::Future: Unpin + Send,
|
C::Future: Unpin + Send,
|
||||||
C::Response: AsyncRead + AsyncWrite + HyperConnection + Unpin + Send + 'static,
|
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 = Connection::lazy(connector, endpoint);
|
||||||
let svc = Buffer::new(Either::A(svc), buffer_size);
|
let svc = Buffer::new(Either::A(svc), buffer_size);
|
||||||
@@ -152,7 +152,7 @@ impl Channel {
|
|||||||
C::Future: Unpin + Send,
|
C::Future: Unpin + Send,
|
||||||
C::Response: AsyncRead + AsyncWrite + HyperConnection + Unpin + Send + 'static,
|
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)
|
let svc = Connection::connect(connector, endpoint)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ where
|
|||||||
tracing::trace!("Reconnect::call");
|
tracing::trace!("Reconnect::call");
|
||||||
if let Some(error) = self.error.take() {
|
if let Some(error) = self.error.take() {
|
||||||
tracing::debug!("error: {}", error);
|
tracing::debug!("error: {}", error);
|
||||||
return ResponseFuture::error(error.into());
|
return ResponseFuture::error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
let service = match self.state {
|
let service = match self.state {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ impl TlsConnector {
|
|||||||
domain: String,
|
domain: String,
|
||||||
) -> Result<Self, crate::Error> {
|
) -> Result<Self, crate::Error> {
|
||||||
let mut config = ClientConfig::new();
|
let mut config = ClientConfig::new();
|
||||||
config.set_protocols(&[Vec::from(&ALPN_H2[..])]);
|
config.set_protocols(&[Vec::from(ALPN_H2)]);
|
||||||
|
|
||||||
if let Some(identity) = identity {
|
if let Some(identity) = identity {
|
||||||
let (client_cert, client_key) = rustls_keys::load_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() {
|
config.root_store = match rustls_native_certs::load_native_certs() {
|
||||||
Ok(store) | Err((Some(store), _)) => store,
|
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_single_cert(cert, key)?;
|
||||||
config.set_protocols(&[Vec::from(&ALPN_H2[..])]);
|
config.set_protocols(&[Vec::from(ALPN_H2)]);
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
inner: Arc::new(config),
|
inner: Arc::new(config),
|
||||||
|
|||||||
Reference in New Issue
Block a user