diff --git a/compiler/src/codegen.rs b/compiler/src/codegen.rs index e98303ff..4f6aa464 100644 --- a/compiler/src/codegen.rs +++ b/compiler/src/codegen.rs @@ -724,9 +724,7 @@ pub fn gen( continue; } - results - .file - .extend(gen_file(file, &root_scope, customize).into_iter()); + results.file.extend(gen_file(file, &root_scope, customize)); } results diff --git a/compiler/src/prost_codegen.rs b/compiler/src/prost_codegen.rs index 8ab164f8..2da7dc6a 100644 --- a/compiler/src/prost_codegen.rs +++ b/compiler/src/prost_codegen.rs @@ -16,7 +16,7 @@ use derive_new::new; use prost::Message; use prost_build::{protoc, protoc_include, Config, Method, Service, ServiceGenerator}; use prost_types::FileDescriptorSet; -use std::io::{Error, ErrorKind, Read}; +use std::io::{Error, Read}; use std::path::Path; use std::{fs, io, process::Command}; @@ -53,10 +53,10 @@ where let output = cmd.output()?; if !output.status.success() { - return Err(Error::new( - ErrorKind::Other, - format!("protoc failed: {}", String::from_utf8_lossy(&output.stderr)), - )); + return Err(Error::other(format!( + "protoc failed: {}", + String::from_utf8_lossy(&output.stderr) + ))); } let mut buf = Vec::new(); diff --git a/compiler/src/util/mod.rs b/compiler/src/util/mod.rs index 859d8550..5365edb8 100644 --- a/compiler/src/util/mod.rs +++ b/compiler/src/util/mod.rs @@ -28,7 +28,7 @@ struct NameSpliter<'a> { } impl<'a> NameSpliter<'a> { - fn new(s: &str) -> NameSpliter { + fn new(s: &str) -> NameSpliter<'_> { NameSpliter { name: s.as_bytes(), pos: 0, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 7e550c68..81cc8af8 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel="1.81.0" +channel="1.95.0" profile="default" components=["rustfmt", "clippy"] diff --git a/src/asynchronous/client.rs b/src/asynchronous/client.rs index 6198ba36..524d6432 100644 --- a/src/asynchronous/client.rs +++ b/src/asynchronous/client.rs @@ -95,7 +95,7 @@ impl Client { .map_err(|_| Error::LocalClosed)?; let result = if timeout_nano == 0 { - rx.recv().await.ok_or_else(|| Error::RemoteClosed)? + rx.recv().await.ok_or(Error::RemoteClosed)? } else { tokio::time::timeout( std::time::Duration::from_nanos(timeout_nano as u64), @@ -103,7 +103,7 @@ impl Client { ) .await .map_err(|e| Error::Others(format!("Receive packet timeout {e:?}")))? - .ok_or_else(|| Error::RemoteClosed)? + .ok_or(Error::RemoteClosed)? }; let msg = result?; diff --git a/tests/run-examples.rs b/tests/run-examples.rs index d3c04b23..d2996c0a 100644 --- a/tests/run-examples.rs +++ b/tests/run-examples.rs @@ -1,3 +1,7 @@ +// wait_with_output is eventually called, but clippy can't see through the +// branching cleanup paths and flags `wait_with_output("server", server)`. +#![allow(clippy::zombie_processes)] + use std::{ io::{BufRead, BufReader}, process::{Child, Command}, diff --git a/ttrpc-codegen/src/convert.rs b/ttrpc-codegen/src/convert.rs index be3dec24..c01f1a42 100644 --- a/ttrpc-codegen/src/convert.rs +++ b/ttrpc-codegen/src/convert.rs @@ -38,7 +38,7 @@ trait ProtobufOptions { } } -impl<'a> ProtobufOptions for &'a [model::ProtobufOption] { +impl ProtobufOptions for &[model::ProtobufOption] { fn by_name(&self, name: &str) -> Option<&model::ProtobufConstant> { let option_name = name; for model::ProtobufOption { name, value } in *self { @@ -359,10 +359,7 @@ impl<'a> LookupScope<'a> { current_path: &AbsolutePath, path: &RelativePath, ) -> Option<(AbsolutePath, MessageOrEnum)> { - let (first, rem) = match path.split_first_rem() { - Some(x) => x, - None => return None, - }; + let (first, rem) = path.split_first_rem()?; if rem.is_empty() { match self.find_member(first) { diff --git a/ttrpc-codegen/src/lib.rs b/ttrpc-codegen/src/lib.rs index a198a9a2..5f2d2f87 100644 --- a/ttrpc-codegen/src/lib.rs +++ b/ttrpc-codegen/src/lib.rs @@ -265,13 +265,10 @@ impl<'a> Run<'a> { fs::File::open(fs_path)?.read_to_string(&mut content)?; let parsed = model::FileDescriptor::parse(content).map_err(|e| { - io::Error::new( - io::ErrorKind::Other, - WithFileError { - file: format!("{}", fs_path.display()), - error: e.into(), - }, - ) + io::Error::other(WithFileError { + file: format!("{}", fs_path.display()), + error: e.into(), + }) })?; for import_path in &parsed.import_paths { @@ -286,13 +283,10 @@ impl<'a> Run<'a> { let descriptor = convert::file_descriptor(protobuf_path.to_owned(), &parsed, &this_file_deps).map_err( |e| { - io::Error::new( - io::ErrorKind::Other, - WithFileError { - file: format!("{}", fs_path.display()), - error: e.into(), - }, - ) + io::Error::other(WithFileError { + file: format!("{}", fs_path.display()), + error: e.into(), + }) }, )?; @@ -312,13 +306,10 @@ impl<'a> Run<'a> { } } - Err(io::Error::new( - io::ErrorKind::Other, - format!( - "protobuf path {:?} is not found in import path {:?}", - protobuf_path, self.includes - ), - )) + Err(io::Error::other(format!( + "protobuf path {:?} is not found in import path {:?}", + protobuf_path, self.includes + ))) } fn add_fs_file(&mut self, fs_path: &Path) -> io::Result { @@ -334,13 +325,10 @@ impl<'a> Run<'a> { self.add_file(&protobuf_path, fs_path)?; Ok(protobuf_path) } - None => Err(io::Error::new( - io::ErrorKind::Other, - format!( - "file {:?} must reside in include path {:?}", - fs_path, self.includes - ), - )), + None => Err(io::Error::other(format!( + "file {:?} must reside in include path {:?}", + fs_path, self.includes + ))), } } } diff --git a/ttrpc-codegen/src/parser.rs b/ttrpc-codegen/src/parser.rs index ba7fb386..0c39cb10 100644 --- a/ttrpc-codegen/src/parser.rs +++ b/ttrpc-codegen/src/parser.rs @@ -230,8 +230,7 @@ impl<'a> Lexer<'a> { } fn lookahead_char_is_in(&self, alphabet: &str) -> bool { - self.lookahead_char() - .map_or(false, |c| alphabet.contains(c)) + self.lookahead_char().is_some_and(|c| alphabet.contains(c)) } fn next_char_opt(&mut self) -> Option { @@ -912,13 +911,7 @@ impl<'a> Parser<'a> { fn next_ident_if_in(&mut self, idents: &[&str]) -> ParserResult> { let v = match self.lookahead()? { - Some(Token::Ident(next)) => { - if idents.iter().any(|i| i == next) { - next.clone() - } else { - return Ok(None); - } - } + Some(Token::Ident(next)) if idents.iter().any(|i| i == next) => next.clone(), _ => return Ok(None), }; self.advance()?;