Skip to content

Fix clippy lint #1181

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

Merged
merged 25 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
eab3485
chrore(examples): Allow clippy::derive_partial_eq_without_eq to gener…
tottoto Dec 6, 2022
a41ed5f
chore(examples): Remove useless conversion detected by clippy
tottoto Dec 6, 2022
c4e87c7
chore(tonic): Fix clippy lint
tottoto Dec 6, 2022
8d21753
chore(types): Fix clippy lint
tottoto Dec 6, 2022
a78762b
chore(reflection): Fix clippy lint
tottoto Dec 6, 2022
fd6ffb7
chore(web): Fix clippy lint
tottoto Dec 6, 2022
37703f4
chrore(tests): Allow clippy::derive_partial_eq_without_eq to generate…
tottoto Dec 6, 2022
edaf0f8
chrore(interop): Allow clippy::derive_partial_eq_without_eq to genera…
tottoto Dec 6, 2022
7a6ddd5
chore(health): Fix clippy lint
tottoto Dec 6, 2022
3ba3c9c
chore(interop): Fix clippy lint
tottoto Dec 6, 2022
75dde6d
chore(web): Fix clippy lint
tottoto Dec 6, 2022
43bc8bc
chore(tonic): Fix clippy lint
tottoto Dec 6, 2022
7bcaa15
chore(tests): Fix clippy lint
tottoto Dec 6, 2022
f1b764d
feat(build): Allow clippy::derive_partial_eq_without_eq as default
tottoto Dec 7, 2022
187d7e1
Remove manually added attributes to allow clippy::derive_partial_eq_w…
tottoto Dec 7, 2022
28f38ab
Update generated code
tottoto Dec 7, 2022
7fe1d32
Add config to allow clippy::derive_partial_eq_without_eq to extern_pa…
tottoto Dec 7, 2022
1f0fc9c
Revert "feat(build): Allow clippy::derive_partial_eq_without_eq as de…
tottoto Dec 9, 2022
3ec1cb1
Add patch to use unreleased prost-build
tottoto Dec 9, 2022
23ebd27
chore(reflection): Fix code generation
tottoto Dec 9, 2022
68b61d0
chore: Update generated code
tottoto Dec 9, 2022
e7efd33
Update to prost-build 0.11.4
tottoto Dec 10, 2022
7c455f7
Fix clippy lint
tottoto Dec 10, 2022
728b040
Revert "Add config to allow clippy::derive_partial_eq_without_eq to e…
tottoto Dec 10, 2022
4c66d8c
Remove Eq impl from prost message
tottoto Dec 12, 2022
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
2 changes: 1 addition & 1 deletion examples/src/blocking/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Greeter for MyGreeter {
println!("Got a request: {:?}", request);

let reply = hello_world::HelloReply {
message: format!("Hello {}!", request.into_inner().name).into(),
message: format!("Hello {}!", request.into_inner().name),
};

Ok(Response::new(reply))
Expand Down
6 changes: 3 additions & 3 deletions interop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl fmt::Display for TestAssertion {
macro_rules! test_assert {
($description:expr, $assertion:expr) => {
if $assertion {
crate::TestAssertion::Passed {
$crate::TestAssertion::Passed {
description: $description,
}
} else {
Expand All @@ -126,11 +126,11 @@ macro_rules! test_assert {
};
($description:expr, $assertion:expr, $why:expr) => {
if $assertion {
crate::TestAssertion::Passed {
$crate::TestAssertion::Passed {
description: $description,
}
} else {
crate::TestAssertion::Failed {
$crate::TestAssertion::Failed {
description: $description,
expression: stringify!($assertion),
why: Some($why),
Expand Down
2 changes: 1 addition & 1 deletion tests/disable_comments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ prost = "0.11"
tonic = { path = "../../tonic" }

[build-dependencies]
prost-build = "0.11"
prost-build = "0.11.4"
tonic-build = { path = "../../tonic-build" }
2 changes: 1 addition & 1 deletion tests/disable_comments/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
let mut config = prost_build::Config::default();
config.disable_comments(&["test.Input1", "test.Output1"]);
config.disable_comments(["test.Input1", "test.Output1"]);
tonic_build::configure()
.disable_comments("test.Service1")
.disable_comments("test.Service1.Rpc1")
Expand Down
2 changes: 1 addition & 1 deletion tests/extern_path/uuid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ version = "0.1.0"
bytes = "1.0"
prost = "0.11"
[build-dependencies]
prost-build = "0.11"
prost-build = "0.11.4"
2 changes: 1 addition & 1 deletion tests/integration_tests/tests/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn status_from_server_stream_with_source() {
&self,
_: Request<InputStream>,
) -> Result<Response<Self::StreamCallStream>, Status> {
let s = Unsync(0 as *mut ());
let s = Unsync(std::ptr::null_mut::<()>());

Ok(Response::new(Box::pin(s) as Self::StreamCallStream))
}
Expand Down
1 change: 1 addition & 0 deletions tests/root-crate-path/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Animal {
#[prost(string, optional, tag = "1")]
Expand Down
2 changes: 1 addition & 1 deletion tests/wellknown-compiled/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ prost = "0.11"
tonic = {path = "../../tonic"}

[build-dependencies]
prost-build = "0.11"
prost-build = "0.11.4"
tonic-build = {path = "../../tonic-build"}
2 changes: 1 addition & 1 deletion tonic-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ version = "0.8.4"
[dependencies]
prettyplease = { version = "0.1" }
proc-macro2 = "1.0"
prost-build = { version = "0.11.2", optional = true }
prost-build = { version = "0.11.4", optional = true }
quote = "1.0"
syn = "1.0"

Expand Down
2 changes: 2 additions & 0 deletions tonic-health/src/generated/grpc.health.v1.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct HealthCheckRequest {
#[prost(string, tag = "1")]
pub service: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct HealthCheckResponse {
#[prost(enumeration = "health_check_response::ServingStatus", tag = "1")]
Expand Down
2 changes: 1 addition & 1 deletion tonic-health/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod proto {
pub mod server;

/// An enumeration of values representing gRPC service health.
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ServingStatus {
/// Unknown status
Unknown,
Expand Down
2 changes: 1 addition & 1 deletion tonic-reflection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ tonic = { version = "0.8", path = "../tonic", default-features = false, features

[dev-dependencies]
tonic = { version = "0.8", path = "../tonic", default-features = false, features = ["transport"] }
tonic-build = { version = "0.8", path = "../tonic-build", default-features = false, features = ["prost"] }
tonic-build = { version = "0.8", path = "../tonic-build", default-features = false, features = ["prost", "cleanup-markdown"] }
futures = "0.3"
futures-util = "0.3"
10 changes: 10 additions & 0 deletions tonic-reflection/src/generated/grpc.reflection.v1alpha.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// The message sent by the client when calling ServerReflectionInfo method.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ServerReflectionRequest {
#[prost(string, tag = "1")]
Expand All @@ -16,6 +17,7 @@ pub mod server_reflection_request {
/// To use reflection service, the client should set one of the following
/// fields in message_request. The server distinguishes requests by their
/// defined field and then handles them using corresponding methods.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum MessageRequest {
/// Find a proto file by the file name.
Expand Down Expand Up @@ -48,6 +50,7 @@ pub mod server_reflection_request {
}
/// The type name and extension number sent by the client when requesting
/// file_containing_extension.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ExtensionRequest {
/// Fully-qualified type name. The format should be <package>.<type>
Expand All @@ -57,6 +60,7 @@ pub struct ExtensionRequest {
pub extension_number: i32,
}
/// The message sent by the server to answer ServerReflectionInfo method.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ServerReflectionResponse {
#[prost(string, tag = "1")]
Expand All @@ -74,6 +78,7 @@ pub struct ServerReflectionResponse {
pub mod server_reflection_response {
/// The server sets one of the following fields according to the
/// message_request in the request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum MessageResponse {
/// This message is used to answer file_by_filename, file_containing_symbol,
Expand All @@ -98,6 +103,7 @@ pub mod server_reflection_response {
/// Serialized FileDescriptorProto messages sent by the server answering
/// a file_by_filename, file_containing_symbol, or file_containing_extension
/// request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FileDescriptorResponse {
/// Serialized FileDescriptorProto messages. We avoid taking a dependency on
Expand All @@ -108,6 +114,7 @@ pub struct FileDescriptorResponse {
}
/// A list of extension numbers sent by the server answering
/// all_extension_numbers_of_type request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ExtensionNumberResponse {
/// Full name of the base type, including the package name. The format
Expand All @@ -118,6 +125,7 @@ pub struct ExtensionNumberResponse {
pub extension_number: ::prost::alloc::vec::Vec<i32>,
}
/// A list of ServiceResponse sent by the server answering list_services request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ListServiceResponse {
/// The information of each service may be expanded in the future, so we use
Expand All @@ -127,6 +135,7 @@ pub struct ListServiceResponse {
}
/// The information of a single service used by ListServiceResponse to answer
/// list_services request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ServiceResponse {
/// Full name of a registered service, including its package name. The format
Expand All @@ -135,6 +144,7 @@ pub struct ServiceResponse {
pub name: ::prost::alloc::string::String,
}
/// The error code and error message sent by the server when an error occurs.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorResponse {
/// This field uses the error codes defined in grpc::StatusCode.
Expand Down
15 changes: 15 additions & 0 deletions tonic-types/src/generated/google.rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
///
/// You can find out more about this error model and how to work with it in the
/// [API Design Guide](<https://cloud.google.com/apis/design/errors>).
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Status {
/// The status code, which should be an enum value of \\[google.rpc.Code\]\[google.rpc.Code\\].
Expand Down Expand Up @@ -33,13 +34,15 @@ pub struct Status {
/// the delay between retries based on `retry_delay`, until either a maximum
/// number of retries have been reached or a maximum retry delay cap has been
/// reached.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RetryInfo {
/// Clients should wait at least this long between retrying the same request.
#[prost(message, optional, tag = "1")]
pub retry_delay: ::core::option::Option<::prost_types::Duration>,
}
/// Describes additional debugging info.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DebugInfo {
/// The stack trace entries indicating where the error occurred.
Expand All @@ -60,6 +63,7 @@ pub struct DebugInfo {
///
/// Also see RetryInfo and Help types for other details about handling a
/// quota failure.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct QuotaFailure {
/// Describes all quota violations.
Expand All @@ -70,6 +74,7 @@ pub struct QuotaFailure {
pub mod quota_failure {
/// A message type used to describe a single quota violation. For example, a
/// daily quota or a custom quota that was exceeded.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Violation {
/// The subject on which the quota check failed.
Expand Down Expand Up @@ -116,6 +121,7 @@ pub mod quota_failure {
/// }
/// }
/// ```
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ErrorInfo {
/// The reason of the error. This is a constant value that identifies the
Expand Down Expand Up @@ -151,6 +157,7 @@ pub struct ErrorInfo {
/// For example, if an RPC failed because it required the Terms of Service to be
/// acknowledged, it could list the terms of service violation in the
/// PreconditionFailure message.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PreconditionFailure {
/// Describes all precondition violations.
Expand All @@ -160,6 +167,7 @@ pub struct PreconditionFailure {
/// Nested message and enum types in `PreconditionFailure`.
pub mod precondition_failure {
/// A message type used to describe a single precondition failure.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Violation {
/// The type of PreconditionFailure. We recommend using a service-specific
Expand All @@ -182,6 +190,7 @@ pub mod precondition_failure {
}
/// Describes violations in a client request. This error type focuses on the
/// syntactic aspects of the request.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BadRequest {
/// Describes all violations in a client request.
Expand All @@ -191,6 +200,7 @@ pub struct BadRequest {
/// Nested message and enum types in `BadRequest`.
pub mod bad_request {
/// A message type used to describe a single bad request field.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FieldViolation {
/// A path leading to a field in the request body. The value will be a
Expand All @@ -205,6 +215,7 @@ pub mod bad_request {
}
/// Contains metadata about the request that clients can attach when filing a bug
/// or providing other forms of feedback.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct RequestInfo {
/// An opaque string that should only be interpreted by the service generating
Expand All @@ -217,6 +228,7 @@ pub struct RequestInfo {
pub serving_data: ::prost::alloc::string::String,
}
/// Describes the resource that is being accessed.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct ResourceInfo {
/// A name for the type of resource being accessed, e.g. "sql table",
Expand Down Expand Up @@ -245,6 +257,7 @@ pub struct ResourceInfo {
/// For example, if a quota check failed with an error indicating the calling
/// project hasn't enabled the accessed service, this can contain a URL pointing
/// directly to the right place in the developer console to flip the bit.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Help {
/// URL(s) pointing to additional information on handling the current error.
Expand All @@ -254,6 +267,7 @@ pub struct Help {
/// Nested message and enum types in `Help`.
pub mod help {
/// Describes a URL link.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Link {
/// Describes what the link offers.
Expand All @@ -266,6 +280,7 @@ pub mod help {
}
/// Provides a localized error message that is safe to return to the user
/// which can be attached to an RPC error.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LocalizedMessage {
/// The locale used following the specification defined at
Expand Down
6 changes: 6 additions & 0 deletions tonic-types/src/richer_error/error_details/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,9 @@ impl ErrorDetails {
false
}
}

impl Default for ErrorDetails {
fn default() -> Self {
Self::new()
}
}
28 changes: 12 additions & 16 deletions tonic-types/src/richer_error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ trait FromAny {
Self: Sized;
}

fn gen_details_bytes(code: Code, message: &String, details: Vec<Any>) -> Bytes {
fn gen_details_bytes(code: Code, message: &str, details: Vec<Any>) -> Bytes {
let status = pb::Status {
code: code as i32,
message: message.clone(),
message: message.to_owned(),
details,
};

Expand Down Expand Up @@ -379,7 +379,7 @@ impl StatusExt for tonic::Status {
}

fn get_error_details(&self) -> ErrorDetails {
self.check_error_details().unwrap_or(ErrorDetails::new())
self.check_error_details().unwrap_or_default()
}

fn check_error_details_vec(&self) -> Result<Vec<ErrorDetail>, DecodeError> {
Expand All @@ -403,19 +403,17 @@ impl StatusExt for tonic::Status {
}

fn get_error_details_vec(&self) -> Vec<ErrorDetail> {
self.check_error_details_vec().unwrap_or(Vec::new())
self.check_error_details_vec().unwrap_or_default()
}

fn get_details_retry_info(&self) -> Option<RetryInfo> {
let status = pb::Status::decode(self.details()).ok()?;

for any in status.details.into_iter() {
match any.type_url.as_str() {
RetryInfo::TYPE_URL => match RetryInfo::from_any(any) {
Ok(detail) => return Some(detail),
Err(_) => {}
},
_ => {}
if any.type_url.as_str() == RetryInfo::TYPE_URL {
if let Ok(detail) = RetryInfo::from_any(any) {
return Some(detail);
}
}
}

Expand All @@ -426,12 +424,10 @@ impl StatusExt for tonic::Status {
let status = pb::Status::decode(self.details()).ok()?;

for any in status.details.into_iter() {
match any.type_url.as_str() {
BadRequest::TYPE_URL => match BadRequest::from_any(any) {
Ok(detail) => return Some(detail),
Err(_) => {}
},
_ => {}
if any.type_url.as_str() == BadRequest::TYPE_URL {
if let Ok(detail) = BadRequest::from_any(any) {
return Some(detail);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tonic-types/src/richer_error/std_messages/bad_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ mod tests {
);

assert!(
br_details.is_empty() == false,
!br_details.is_empty(),
"filled BadRequest returns 'true' from .is_empty()"
);

Expand Down
Loading