diff options
author | Lukas Wirth <[email protected]> | 2020-10-06 13:40:27 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-10-06 13:40:27 +0100 |
commit | 643bbf15a2a76e7241156249261bf0d060deecd4 (patch) | |
tree | 0afb188139ea4822f1e596a9f93c580827057cb2 /crates/hir_ty/src | |
parent | e5f252ade72fee4776396122dc91a17ddc185a66 (diff) |
Fix trait object hir formatting behind pointer and references
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r-- | crates/hir_ty/src/display.rs | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index f389c5a4b..d2e151f25 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -221,7 +221,16 @@ impl HirDisplay for ApplicationTy { | |||
221 | } | 221 | } |
222 | TypeCtor::RawPtr(m) => { | 222 | TypeCtor::RawPtr(m) => { |
223 | let t = self.parameters.as_single(); | 223 | let t = self.parameters.as_single(); |
224 | write!(f, "*{}{}", m.as_keyword_for_ptr(), t.display(f.db))?; | 224 | let ty_display = t.display(f.db); |
225 | |||
226 | write!(f, "*{}", m.as_keyword_for_ptr())?; | ||
227 | if matches!(t, Ty::Dyn(predicates) if predicates.len() > 1) { | ||
228 | write!(f, "(")?; | ||
229 | write!(f, "{}", ty_display)?; | ||
230 | write!(f, ")")?; | ||
231 | } else { | ||
232 | write!(f, "{}", ty_display)?; | ||
233 | } | ||
225 | } | 234 | } |
226 | TypeCtor::Ref(m) => { | 235 | TypeCtor::Ref(m) => { |
227 | let t = self.parameters.as_single(); | 236 | let t = self.parameters.as_single(); |
@@ -230,7 +239,15 @@ impl HirDisplay for ApplicationTy { | |||
230 | } else { | 239 | } else { |
231 | t.display(f.db) | 240 | t.display(f.db) |
232 | }; | 241 | }; |
233 | write!(f, "&{}{}", m.as_keyword_for_ref(), ty_display)?; | 242 | |
243 | write!(f, "&{}", m.as_keyword_for_ref())?; | ||
244 | if matches!(t, Ty::Dyn(predicates) if predicates.len() > 1) { | ||
245 | write!(f, "(")?; | ||
246 | write!(f, "{}", ty_display)?; | ||
247 | write!(f, ")")?; | ||
248 | } else { | ||
249 | write!(f, "{}", ty_display)?; | ||
250 | } | ||
234 | } | 251 | } |
235 | TypeCtor::Never => write!(f, "!")?, | 252 | TypeCtor::Never => write!(f, "!")?, |
236 | TypeCtor::Tuple { .. } => { | 253 | TypeCtor::Tuple { .. } => { |
@@ -636,14 +653,14 @@ impl HirDisplay for GenericPredicate { | |||
636 | 653 | ||
637 | impl HirDisplay for Obligation { | 654 | impl HirDisplay for Obligation { |
638 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 655 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
639 | Ok(match self { | 656 | match self { |
640 | Obligation::Trait(tr) => write!(f, "Implements({})", tr.display(f.db))?, | 657 | Obligation::Trait(tr) => write!(f, "Implements({})", tr.display(f.db)), |
641 | Obligation::Projection(proj) => write!( | 658 | Obligation::Projection(proj) => write!( |
642 | f, | 659 | f, |
643 | "Normalize({} => {})", | 660 | "Normalize({} => {})", |
644 | proj.projection_ty.display(f.db), | 661 | proj.projection_ty.display(f.db), |
645 | proj.ty.display(f.db) | 662 | proj.ty.display(f.db) |
646 | )?, | 663 | ), |
647 | }) | 664 | } |
648 | } | 665 | } |
649 | } | 666 | } |