mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Auto merge of #17377 - Young-Flash:hir_print, r=Veykril
internal: better print style for hir before: ![before](https://github.com/rust-lang/rust-analyzer/assets/71162630/cd5e27b3-b4b1-450f-ba50-3c4f4e345d70) after: ![after](https://github.com/rust-lang/rust-analyzer/assets/71162630/04e11345-cadd-49cb-b10c-6888ef51758e)
This commit is contained in:
commit
575becbf27
2 changed files with 17 additions and 8 deletions
|
@ -48,21 +48,30 @@ 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 };
|
||||
if let DefWithBodyId::FunctionId(it) = owner {
|
||||
p.buf.push('(');
|
||||
let params = &db.function_data(it).params;
|
||||
let mut params = params.iter();
|
||||
let function_data = &db.function_data(it);
|
||||
let (mut params, ret_type) = (function_data.params.iter(), &function_data.ret_type);
|
||||
if let Some(self_param) = body.self_param {
|
||||
p.print_binding(self_param);
|
||||
p.buf.push(':');
|
||||
p.buf.push_str(": ");
|
||||
if let Some(ty) = params.next() {
|
||||
p.print_type_ref(ty);
|
||||
p.buf.push_str(", ");
|
||||
}
|
||||
}
|
||||
body.params.iter().zip(params).for_each(|(¶m, ty)| {
|
||||
p.print_pat(param);
|
||||
p.buf.push(':');
|
||||
p.buf.push_str(": ");
|
||||
p.print_type_ref(ty);
|
||||
p.buf.push_str(", ");
|
||||
});
|
||||
// remove the last ", " in param list
|
||||
if body.params.len() > 0 {
|
||||
p.buf.truncate(p.buf.len() - 2);
|
||||
}
|
||||
p.buf.push(')');
|
||||
// return type
|
||||
p.buf.push_str(" -> ");
|
||||
p.print_type_ref(ret_type);
|
||||
p.buf.push(' ');
|
||||
}
|
||||
p.print_expr(body.body_expr);
|
||||
|
|
|
@ -156,7 +156,7 @@ fn main() {
|
|||
);
|
||||
|
||||
expect![[r#"
|
||||
fn main() {
|
||||
fn main() -> () {
|
||||
let are = "are";
|
||||
let count = 10;
|
||||
builtin#lang(Arguments::new_v1_formatted)(
|
||||
|
@ -258,7 +258,7 @@ impl SsrError {
|
|||
|
||||
assert_eq!(db.body_with_source_map(def).1.diagnostics(), &[]);
|
||||
expect![[r#"
|
||||
fn main() {
|
||||
fn main() -> () {
|
||||
_ = $crate::error::SsrError::new(
|
||||
builtin#lang(Arguments::new_v1_formatted)(
|
||||
&[
|
||||
|
@ -303,7 +303,7 @@ macro_rules! m {
|
|||
};
|
||||
}
|
||||
|
||||
fn f() {
|
||||
fn f(a: i32, b: u32) -> String {
|
||||
m!();
|
||||
}
|
||||
"#,
|
||||
|
@ -317,7 +317,7 @@ fn f() {
|
|||
}
|
||||
|
||||
expect![[r#"
|
||||
fn f() {
|
||||
fn f(a: i32, b: u32) -> String {
|
||||
{
|
||||
$crate::panicking::panic_fmt(
|
||||
builtin#lang(Arguments::new_v1_formatted)(
|
||||
|
|
Loading…
Reference in a new issue