Skip to content

Commit 2ad0673

Browse files
committed
ci: bump rust-toolchain pin to 1.95.0 and apply clippy --fix suggestions
The current 1.81.0 pin can no longer resolve the checked-in Cargo.lock: transitive dependencies (home v0.5.12 among others) now require edition2024 and rustc >= 1.88, neither of which 1.81 supports. 1.95.0 is current stable at time of writing, and successfully resolves and compiles the full workspace (crate, compiler, codegen, examples). Newer clippy then flags a handful of stylistic issues that trip `-D warnings` in `make check-all`: - io::Error::new(ErrorKind::Other, ...) -> io::Error::other(...) - .map_or(false, ...) -> .is_some_and(...) - unnecessary explicit lifetimes (foo<'a> -> foo<'_>) - .ok_or_else(|| lit) -> .ok_or(lit) - redundant .into_iter() on an IntoIterator argument - a few match-one-pattern reductions to `?` / if-let-guard These are all applied via `cargo clippy --fix` and then `cargo fmt` and reviewed; no behavior change. The one manually added line is a `#![allow(clippy::zombie_processes)]` at the top of tests/run-examples.rs where the lint is a false positive (the branching cleanup does wait on each spawned child, clippy just can't see it through the control flow). Locally verified: `make check-all`, `make`, `make -C compiler`, `make -C ttrpc-codegen`, `make -C example build-examples` all pass.
1 parent f31f592 commit 2ad0673

9 files changed

Lines changed: 34 additions & 54 deletions

File tree

compiler/src/codegen.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,9 +724,7 @@ pub fn gen(
724724
continue;
725725
}
726726

727-
results
728-
.file
729-
.extend(gen_file(file, &root_scope, customize).into_iter());
727+
results.file.extend(gen_file(file, &root_scope, customize));
730728
}
731729

732730
results

compiler/src/prost_codegen.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use derive_new::new;
1616
use prost::Message;
1717
use prost_build::{protoc, protoc_include, Config, Method, Service, ServiceGenerator};
1818
use prost_types::FileDescriptorSet;
19-
use std::io::{Error, ErrorKind, Read};
19+
use std::io::{Error, Read};
2020
use std::path::Path;
2121
use std::{fs, io, process::Command};
2222

@@ -53,10 +53,10 @@ where
5353

5454
let output = cmd.output()?;
5555
if !output.status.success() {
56-
return Err(Error::new(
57-
ErrorKind::Other,
58-
format!("protoc failed: {}", String::from_utf8_lossy(&output.stderr)),
59-
));
56+
return Err(Error::other(format!(
57+
"protoc failed: {}",
58+
String::from_utf8_lossy(&output.stderr)
59+
)));
6060
}
6161

6262
let mut buf = Vec::new();

compiler/src/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct NameSpliter<'a> {
2828
}
2929

3030
impl<'a> NameSpliter<'a> {
31-
fn new(s: &str) -> NameSpliter {
31+
fn new(s: &str) -> NameSpliter<'_> {
3232
NameSpliter {
3333
name: s.as_bytes(),
3434
pos: 0,

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel="1.81.0"
2+
channel="1.95.0"
33
profile="default"
44
components=["rustfmt", "clippy"]

src/asynchronous/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ impl Client {
9595
.map_err(|_| Error::LocalClosed)?;
9696

9797
let result = if timeout_nano == 0 {
98-
rx.recv().await.ok_or_else(|| Error::RemoteClosed)?
98+
rx.recv().await.ok_or(Error::RemoteClosed)?
9999
} else {
100100
tokio::time::timeout(
101101
std::time::Duration::from_nanos(timeout_nano as u64),
102102
rx.recv(),
103103
)
104104
.await
105105
.map_err(|e| Error::Others(format!("Receive packet timeout {e:?}")))?
106-
.ok_or_else(|| Error::RemoteClosed)?
106+
.ok_or(Error::RemoteClosed)?
107107
};
108108

109109
let msg = result?;

tests/run-examples.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// wait_with_output is eventually called, but clippy can't see through the
2+
// branching cleanup paths and flags `wait_with_output("server", server)`.
3+
#![allow(clippy::zombie_processes)]
4+
15
use std::{
26
io::{BufRead, BufReader},
37
process::{Child, Command},

ttrpc-codegen/src/convert.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ trait ProtobufOptions {
3838
}
3939
}
4040

41-
impl<'a> ProtobufOptions for &'a [model::ProtobufOption] {
41+
impl ProtobufOptions for &[model::ProtobufOption] {
4242
fn by_name(&self, name: &str) -> Option<&model::ProtobufConstant> {
4343
let option_name = name;
4444
for model::ProtobufOption { name, value } in *self {
@@ -359,10 +359,7 @@ impl<'a> LookupScope<'a> {
359359
current_path: &AbsolutePath,
360360
path: &RelativePath,
361361
) -> Option<(AbsolutePath, MessageOrEnum)> {
362-
let (first, rem) = match path.split_first_rem() {
363-
Some(x) => x,
364-
None => return None,
365-
};
362+
let (first, rem) = path.split_first_rem()?;
366363

367364
if rem.is_empty() {
368365
match self.find_member(first) {

ttrpc-codegen/src/lib.rs

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,10 @@ impl<'a> Run<'a> {
265265
fs::File::open(fs_path)?.read_to_string(&mut content)?;
266266

267267
let parsed = model::FileDescriptor::parse(content).map_err(|e| {
268-
io::Error::new(
269-
io::ErrorKind::Other,
270-
WithFileError {
271-
file: format!("{}", fs_path.display()),
272-
error: e.into(),
273-
},
274-
)
268+
io::Error::other(WithFileError {
269+
file: format!("{}", fs_path.display()),
270+
error: e.into(),
271+
})
275272
})?;
276273

277274
for import_path in &parsed.import_paths {
@@ -286,13 +283,10 @@ impl<'a> Run<'a> {
286283
let descriptor =
287284
convert::file_descriptor(protobuf_path.to_owned(), &parsed, &this_file_deps).map_err(
288285
|e| {
289-
io::Error::new(
290-
io::ErrorKind::Other,
291-
WithFileError {
292-
file: format!("{}", fs_path.display()),
293-
error: e.into(),
294-
},
295-
)
286+
io::Error::other(WithFileError {
287+
file: format!("{}", fs_path.display()),
288+
error: e.into(),
289+
})
296290
},
297291
)?;
298292

@@ -312,13 +306,10 @@ impl<'a> Run<'a> {
312306
}
313307
}
314308

315-
Err(io::Error::new(
316-
io::ErrorKind::Other,
317-
format!(
318-
"protobuf path {:?} is not found in import path {:?}",
319-
protobuf_path, self.includes
320-
),
321-
))
309+
Err(io::Error::other(format!(
310+
"protobuf path {:?} is not found in import path {:?}",
311+
protobuf_path, self.includes
312+
)))
322313
}
323314

324315
fn add_fs_file(&mut self, fs_path: &Path) -> io::Result<String> {
@@ -334,13 +325,10 @@ impl<'a> Run<'a> {
334325
self.add_file(&protobuf_path, fs_path)?;
335326
Ok(protobuf_path)
336327
}
337-
None => Err(io::Error::new(
338-
io::ErrorKind::Other,
339-
format!(
340-
"file {:?} must reside in include path {:?}",
341-
fs_path, self.includes
342-
),
343-
)),
328+
None => Err(io::Error::other(format!(
329+
"file {:?} must reside in include path {:?}",
330+
fs_path, self.includes
331+
))),
344332
}
345333
}
346334
}

ttrpc-codegen/src/parser.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ impl<'a> Lexer<'a> {
230230
}
231231

232232
fn lookahead_char_is_in(&self, alphabet: &str) -> bool {
233-
self.lookahead_char()
234-
.map_or(false, |c| alphabet.contains(c))
233+
self.lookahead_char().is_some_and(|c| alphabet.contains(c))
235234
}
236235

237236
fn next_char_opt(&mut self) -> Option<char> {
@@ -912,13 +911,7 @@ impl<'a> Parser<'a> {
912911

913912
fn next_ident_if_in(&mut self, idents: &[&str]) -> ParserResult<Option<String>> {
914913
let v = match self.lookahead()? {
915-
Some(Token::Ident(next)) => {
916-
if idents.iter().any(|i| i == next) {
917-
next.clone()
918-
} else {
919-
return Ok(None);
920-
}
921-
}
914+
Some(Token::Ident(next)) if idents.iter().any(|i| i == next) => next.clone(),
922915
_ => return Ok(None),
923916
};
924917
self.advance()?;

0 commit comments

Comments
 (0)