diff options
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/display.rs | 25 | ||||
-rw-r--r-- | crates/hir/src/lib.rs | 22 |
2 files changed, 27 insertions, 20 deletions
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs new file mode 100644 index 000000000..86f48256e --- /dev/null +++ b/crates/hir/src/display.rs | |||
@@ -0,0 +1,25 @@ | |||
1 | //! HirDisplay implementations for various hir types. | ||
2 | use hir_ty::display::{ | ||
3 | write_bounds_like_dyn_trait_with_prefix, HirDisplay, HirDisplayError, HirFormatter, | ||
4 | }; | ||
5 | |||
6 | use crate::{Substs, Type, TypeParam}; | ||
7 | |||
8 | impl HirDisplay for Type { | ||
9 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
10 | self.ty.value.hir_fmt(f) | ||
11 | } | ||
12 | } | ||
13 | |||
14 | impl HirDisplay for TypeParam { | ||
15 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
16 | write!(f, "{}", self.name(f.db))?; | ||
17 | let bounds = f.db.generic_predicates_for_param(self.id); | ||
18 | let substs = Substs::type_params(f.db, self.id.parent); | ||
19 | let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>(); | ||
20 | if !(predicates.is_empty() || f.omit_verbose_types()) { | ||
21 | write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?; | ||
22 | } | ||
23 | Ok(()) | ||
24 | } | ||
25 | } | ||
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index c5161dadd..469ed5b5e 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -29,6 +29,8 @@ mod has_source; | |||
29 | pub mod diagnostics; | 29 | pub mod diagnostics; |
30 | pub mod db; | 30 | pub mod db; |
31 | 31 | ||
32 | mod display; | ||
33 | |||
32 | use std::{iter, sync::Arc}; | 34 | use std::{iter, sync::Arc}; |
33 | 35 | ||
34 | use arrayvec::ArrayVec; | 36 | use arrayvec::ArrayVec; |
@@ -50,7 +52,6 @@ use hir_def::{ | |||
50 | use hir_expand::{diagnostics::DiagnosticSink, name::name, MacroDefKind}; | 52 | use hir_expand::{diagnostics::DiagnosticSink, name::name, MacroDefKind}; |
51 | use hir_ty::{ | 53 | use hir_ty::{ |
52 | autoderef, | 54 | autoderef, |
53 | display::{write_bounds_like_dyn_trait_with_prefix, HirDisplayError, HirFormatter}, | ||
54 | method_resolution::{self, TyFingerprint}, | 55 | method_resolution::{self, TyFingerprint}, |
55 | to_assoc_type_id, | 56 | to_assoc_type_id, |
56 | traits::{FnTrait, Solution, SolutionVariables}, | 57 | traits::{FnTrait, Solution, SolutionVariables}, |
@@ -1412,19 +1413,6 @@ impl TypeParam { | |||
1412 | } | 1413 | } |
1413 | } | 1414 | } |
1414 | 1415 | ||
1415 | impl HirDisplay for TypeParam { | ||
1416 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
1417 | write!(f, "{}", self.name(f.db))?; | ||
1418 | let bounds = f.db.generic_predicates_for_param(self.id); | ||
1419 | let substs = Substs::type_params(f.db, self.id.parent); | ||
1420 | let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>(); | ||
1421 | if !(predicates.is_empty() || f.omit_verbose_types()) { | ||
1422 | write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?; | ||
1423 | } | ||
1424 | Ok(()) | ||
1425 | } | ||
1426 | } | ||
1427 | |||
1428 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 1416 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
1429 | pub struct LifetimeParam { | 1417 | pub struct LifetimeParam { |
1430 | pub(crate) id: LifetimeParamId, | 1418 | pub(crate) id: LifetimeParamId, |
@@ -2054,12 +2042,6 @@ impl Type { | |||
2054 | } | 2042 | } |
2055 | } | 2043 | } |
2056 | 2044 | ||
2057 | impl HirDisplay for Type { | ||
2058 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
2059 | self.ty.value.hir_fmt(f) | ||
2060 | } | ||
2061 | } | ||
2062 | |||
2063 | // FIXME: closures | 2045 | // FIXME: closures |
2064 | #[derive(Debug)] | 2046 | #[derive(Debug)] |
2065 | pub struct Callable { | 2047 | pub struct Callable { |