Skip to content

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/tools/rust-analyzer/crates/hir-def/src/body/pretty.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,30 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
4848
let mut p = Printer { db, body, buf: header, indent_level: 0, needs_indent: false };
4949
if let DefWithBodyId::FunctionId(it) = owner {
5050
p.buf.push('(');
51-
let params = &db.function_data(it).params;
52-
let mut params = params.iter();
51+
let function_data = &db.function_data(it);
52+
let (mut params, ret_type) = (function_data.params.iter(), &function_data.ret_type);
5353
if let Some(self_param) = body.self_param {
5454
p.print_binding(self_param);
55-
p.buf.push(':');
55+
p.buf.push_str(": ");
5656
if let Some(ty) = params.next() {
5757
p.print_type_ref(ty);
58+
p.buf.push_str(", ");
5859
}
5960
}
6061
body.params.iter().zip(params).for_each(|(&param, ty)| {
6162
p.print_pat(param);
62-
p.buf.push(':');
63+
p.buf.push_str(": ");
6364
p.print_type_ref(ty);
65+
p.buf.push_str(", ");
6466
});
67+
// remove the last ", " in param list
68+
if body.params.len() > 0 {
69+
p.buf.truncate(p.buf.len() - 2);
70+
}
6571
p.buf.push(')');
72+
// return type
73+
p.buf.push_str(" -> ");
74+
p.print_type_ref(ret_type);
6675
p.buf.push(' ');
6776
}
6877
p.print_expr(body.body_expr);

src/tools/rust-analyzer/crates/hir-def/src/body/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn main() {
156156
);
157157

158158
expect![[r#"
159-
fn main() {
159+
fn main() -> () {
160160
let are = "are";
161161
let count = 10;
162162
builtin#lang(Arguments::new_v1_formatted)(
@@ -258,7 +258,7 @@ impl SsrError {
258258

259259
assert_eq!(db.body_with_source_map(def).1.diagnostics(), &[]);
260260
expect![[r#"
261-
fn main() {
261+
fn main() -> () {
262262
_ = $crate::error::SsrError::new(
263263
builtin#lang(Arguments::new_v1_formatted)(
264264
&[
@@ -303,7 +303,7 @@ macro_rules! m {
303303
};
304304
}
305305
306-
fn f() {
306+
fn f(a: i32, b: u32) -> String {
307307
m!();
308308
}
309309
"#,
@@ -317,7 +317,7 @@ fn f() {
317317
}
318318

319319
expect![[r#"
320-
fn f() {
320+
fn f(a: i32, b: u32) -> String {
321321
{
322322
$crate::panicking::panic_fmt(
323323
builtin#lang(Arguments::new_v1_formatted)(

0 commit comments

Comments
 (0)