Skip to content

Commit 62a6233

Browse files
authored
Rust: do not print -> () for signatures that have no results. (#509)
This commit fixes the printing of an unnecessary `-> ()` for function signatures that have no results. While we ignore clippy lints in the generated code, Rust analyzer will blindly copy the unnecessary return specification when implementing missing trait members. This might cause clippy warnings in user code as a result.
1 parent fafe05f commit 62a6233

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

crates/gen-rust-lib/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ pub trait RustGenerator<'a> {
9595
sig: &FnSig,
9696
) -> Vec<String> {
9797
let params = self.print_docs_and_params(func, param_mode, &sig);
98-
self.push_str(" -> ");
99-
self.print_result_params(&func.results, TypeMode::Owned);
98+
self.print_results(&func.results, TypeMode::Owned);
10099
params
101100
}
102101

@@ -152,12 +151,15 @@ pub trait RustGenerator<'a> {
152151
params
153152
}
154153

155-
fn print_result_params(&mut self, results: &Results, mode: TypeMode) {
154+
fn print_results(&mut self, results: &Results, mode: TypeMode) {
156155
match results.len() {
157-
0 => self.push_str("()"),
158-
1 => self.print_ty(results.iter_types().next().unwrap(), mode),
156+
0 => {}
157+
1 => {
158+
self.push_str(" -> ");
159+
self.print_ty(results.iter_types().next().unwrap(), mode);
160+
}
159161
_ => {
160-
self.push_str("(");
162+
self.push_str(" -> (");
161163
for ty in results.iter_types() {
162164
self.print_ty(ty, mode);
163165
self.push_str(", ")

0 commit comments

Comments
 (0)