mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
internal: better print style for hir
This commit is contained in:
parent
913371fb0b
commit
dcbc76b967
@ -48,22 +48,36 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
|
|||||||
let mut p = Printer { db, body, buf: header, indent_level: 0, needs_indent: false };
|
let mut p = Printer { db, body, buf: header, indent_level: 0, needs_indent: false };
|
||||||
if let DefWithBodyId::FunctionId(it) = owner {
|
if let DefWithBodyId::FunctionId(it) = owner {
|
||||||
p.buf.push('(');
|
p.buf.push('(');
|
||||||
let params = &db.function_data(it).params;
|
let function_data = &db.function_data(it);
|
||||||
let mut params = params.iter();
|
let (mut params, ret_type) = (function_data.params.iter(), &function_data.ret_type);
|
||||||
if let Some(self_param) = body.self_param {
|
if let Some(self_param) = body.self_param {
|
||||||
p.print_binding(self_param);
|
p.print_binding(self_param);
|
||||||
p.buf.push(':');
|
p.buf.push(':');
|
||||||
|
p.buf.push(' ');
|
||||||
if let Some(ty) = params.next() {
|
if let Some(ty) = params.next() {
|
||||||
p.print_type_ref(ty);
|
p.print_type_ref(ty);
|
||||||
|
p.buf.push(',');
|
||||||
|
p.buf.push(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
body.params.iter().zip(params).for_each(|(¶m, ty)| {
|
body.params.iter().zip(params).for_each(|(¶m, ty)| {
|
||||||
p.print_pat(param);
|
p.print_pat(param);
|
||||||
p.buf.push(':');
|
p.buf.push(':');
|
||||||
|
p.buf.push(' ');
|
||||||
p.print_type_ref(ty);
|
p.print_type_ref(ty);
|
||||||
|
p.buf.push(',');
|
||||||
|
p.buf.push(' ');
|
||||||
});
|
});
|
||||||
|
// remove the last ", " in param list
|
||||||
|
p.buf.truncate(p.buf.len() - 2);
|
||||||
p.buf.push(')');
|
p.buf.push(')');
|
||||||
p.buf.push(' ');
|
p.buf.push(' ');
|
||||||
|
// return type
|
||||||
|
p.buf.push('-');
|
||||||
|
p.buf.push('>');
|
||||||
|
p.buf.push(' ');
|
||||||
|
p.print_type_ref(ret_type);
|
||||||
|
p.buf.push(' ');
|
||||||
}
|
}
|
||||||
p.print_expr(body.body_expr);
|
p.print_expr(body.body_expr);
|
||||||
if matches!(owner, DefWithBodyId::StaticId(_) | DefWithBodyId::ConstId(_)) {
|
if matches!(owner, DefWithBodyId::StaticId(_) | DefWithBodyId::ConstId(_)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user