diff options
Diffstat (limited to 'crates/hir/src/display.rs')
-rw-r--r-- | crates/hir/src/display.rs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 97a78ca25..01a4d205f 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs | |||
@@ -9,33 +9,33 @@ use hir_ty::display::{ | |||
9 | write_bounds_like_dyn_trait_with_prefix, write_visibility, HirDisplay, HirDisplayError, | 9 | write_bounds_like_dyn_trait_with_prefix, write_visibility, HirDisplay, HirDisplayError, |
10 | HirFormatter, | 10 | HirFormatter, |
11 | }; | 11 | }; |
12 | use hir_ty::Interner; | ||
12 | use syntax::ast::{self, NameOwner}; | 13 | use syntax::ast::{self, NameOwner}; |
13 | 14 | ||
14 | use crate::{ | 15 | use crate::{ |
15 | Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasVisibility, LifetimeParam, | 16 | Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasVisibility, LifetimeParam, |
16 | Module, Static, Struct, Substitution, Trait, Type, TypeAlias, TypeParam, Union, Variant, | 17 | Module, Static, Struct, Trait, TyBuilder, Type, TypeAlias, TypeParam, Union, Variant, |
17 | }; | 18 | }; |
18 | 19 | ||
19 | impl HirDisplay for Function { | 20 | impl HirDisplay for Function { |
20 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 21 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
21 | let data = f.db.function_data(self.id); | 22 | let data = f.db.function_data(self.id); |
22 | write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; | 23 | write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; |
23 | let qual = &data.qualifier; | 24 | if data.is_default() { |
24 | if qual.is_default { | ||
25 | write!(f, "default ")?; | 25 | write!(f, "default ")?; |
26 | } | 26 | } |
27 | if qual.is_const { | 27 | if data.is_const() { |
28 | write!(f, "const ")?; | 28 | write!(f, "const ")?; |
29 | } | 29 | } |
30 | if qual.is_async { | 30 | if data.is_async() { |
31 | write!(f, "async ")?; | 31 | write!(f, "async ")?; |
32 | } | 32 | } |
33 | if qual.is_unsafe { | 33 | if data.is_unsafe() { |
34 | write!(f, "unsafe ")?; | 34 | write!(f, "unsafe ")?; |
35 | } | 35 | } |
36 | if let Some(abi) = &qual.abi { | 36 | if let Some(abi) = &data.abi { |
37 | // FIXME: String escape? | 37 | // FIXME: String escape? |
38 | write!(f, "extern \"{}\" ", abi)?; | 38 | write!(f, "extern \"{}\" ", &**abi)?; |
39 | } | 39 | } |
40 | write!(f, "fn {}", data.name)?; | 40 | write!(f, "fn {}", data.name)?; |
41 | 41 | ||
@@ -68,7 +68,7 @@ impl HirDisplay for Function { | |||
68 | write!(f, ", ")?; | 68 | write!(f, ", ")?; |
69 | } else { | 69 | } else { |
70 | first = false; | 70 | first = false; |
71 | if data.has_self_param { | 71 | if data.has_self_param() { |
72 | write_self_param(type_ref, f)?; | 72 | write_self_param(type_ref, f)?; |
73 | continue; | 73 | continue; |
74 | } | 74 | } |
@@ -88,10 +88,10 @@ impl HirDisplay for Function { | |||
88 | // `FunctionData::ret_type` will be `::core::future::Future<Output = ...>` for async fns. | 88 | // `FunctionData::ret_type` will be `::core::future::Future<Output = ...>` for async fns. |
89 | // Use ugly pattern match to strip the Future trait. | 89 | // Use ugly pattern match to strip the Future trait. |
90 | // Better way? | 90 | // Better way? |
91 | let ret_type = if !qual.is_async { | 91 | let ret_type = if !data.is_async() { |
92 | &data.ret_type | 92 | &data.ret_type |
93 | } else { | 93 | } else { |
94 | match &data.ret_type { | 94 | match &*data.ret_type { |
95 | TypeRef::ImplTrait(bounds) => match &bounds[0] { | 95 | TypeRef::ImplTrait(bounds) => match &bounds[0] { |
96 | TypeBound::Path(path) => { | 96 | TypeBound::Path(path) => { |
97 | path.segments().iter().last().unwrap().args_and_bindings.unwrap().bindings | 97 | path.segments().iter().last().unwrap().args_and_bindings.unwrap().bindings |
@@ -235,8 +235,9 @@ impl HirDisplay for TypeParam { | |||
235 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 235 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
236 | write!(f, "{}", self.name(f.db))?; | 236 | write!(f, "{}", self.name(f.db))?; |
237 | let bounds = f.db.generic_predicates_for_param(self.id); | 237 | let bounds = f.db.generic_predicates_for_param(self.id); |
238 | let substs = Substitution::type_params(f.db, self.id.parent); | 238 | let substs = TyBuilder::type_params_subst(f.db, self.id.parent); |
239 | let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>(); | 239 | let predicates = |
240 | bounds.iter().cloned().map(|b| b.substitute(&Interner, &substs)).collect::<Vec<_>>(); | ||
240 | if !(predicates.is_empty() || f.omit_verbose_types()) { | 241 | if !(predicates.is_empty() || f.omit_verbose_types()) { |
241 | write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?; | 242 | write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?; |
242 | } | 243 | } |