Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions compiler/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/prost_codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel="1.81.0"
channel="1.95.0"
profile="default"
components=["rustfmt", "clippy"]
4 changes: 2 additions & 2 deletions src/asynchronous/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ 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),
rx.recv(),
)
.await
.map_err(|e| Error::Others(format!("Receive packet timeout {e:?}")))?
.ok_or_else(|| Error::RemoteClosed)?
.ok_or(Error::RemoteClosed)?
};

let msg = result?;
Expand Down
4 changes: 4 additions & 0 deletions tests/run-examples.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
7 changes: 2 additions & 5 deletions ttrpc-codegen/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
44 changes: 16 additions & 28 deletions ttrpc-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
})
},
)?;

Expand All @@ -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<String> {
Expand All @@ -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
))),
}
}
}
Expand Down
11 changes: 2 additions & 9 deletions ttrpc-codegen/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> {
Expand Down Expand Up @@ -912,13 +911,7 @@ impl<'a> Parser<'a> {

fn next_ident_if_in(&mut self, idents: &[&str]) -> ParserResult<Option<String>> {
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()?;
Expand Down
Loading