mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
fix: better Fn
traits formatting
This commit is contained in:
parent
4566414789
commit
24f816c481
1 changed files with 16 additions and 3 deletions
|
@ -1164,10 +1164,23 @@ impl HirDisplay for Path {
|
||||||
// Do we actually format expressions?
|
// Do we actually format expressions?
|
||||||
if generic_args.desugared_from_fn {
|
if generic_args.desugared_from_fn {
|
||||||
// First argument will be a tuple, which already includes the parentheses.
|
// First argument will be a tuple, which already includes the parentheses.
|
||||||
generic_args.args[0].hir_fmt(f)?;
|
// If the tuple only contains 1 item, write it manually to avoid the trailing `,`.
|
||||||
|
if let hir_def::path::GenericArg::Type(TypeRef::Tuple(v)) =
|
||||||
|
&generic_args.args[0]
|
||||||
|
{
|
||||||
|
if v.len() == 1 {
|
||||||
|
write!(f, "(")?;
|
||||||
|
v[0].hir_fmt(f)?;
|
||||||
|
write!(f, ")")?;
|
||||||
|
} else {
|
||||||
|
generic_args.args[0].hir_fmt(f)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
if let Some(ret) = &generic_args.bindings[0].type_ref {
|
if let Some(ret) = &generic_args.bindings[0].type_ref {
|
||||||
write!(f, " -> ")?;
|
if !matches!(ret, TypeRef::Tuple(v) if v.is_empty()) {
|
||||||
ret.hir_fmt(f)?;
|
write!(f, " -> ")?;
|
||||||
|
ret.hir_fmt(f)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue