diff options
Diffstat (limited to 'crates/hir_ty/src/display.rs')
-rw-r--r-- | crates/hir_ty/src/display.rs | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index f3a4333cb..a0882a2a1 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -2,18 +2,20 @@ | |||
2 | 2 | ||
3 | use std::{borrow::Cow, fmt}; | 3 | use std::{borrow::Cow, fmt}; |
4 | 4 | ||
5 | use crate::{ | ||
6 | db::HirDatabase, primitive, utils::generics, AliasTy, CallableDefId, CallableSig, | ||
7 | GenericPredicate, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, Substs, | ||
8 | TraitRef, Ty, | ||
9 | }; | ||
10 | use arrayvec::ArrayVec; | 5 | use arrayvec::ArrayVec; |
6 | use chalk_ir::Mutability; | ||
11 | use hir_def::{ | 7 | use hir_def::{ |
12 | db::DefDatabase, find_path, generics::TypeParamProvenance, item_scope::ItemInNs, AdtId, | 8 | db::DefDatabase, find_path, generics::TypeParamProvenance, item_scope::ItemInNs, |
13 | AssocContainerId, HasModule, Lookup, ModuleId, TraitId, | 9 | AssocContainerId, HasModule, Lookup, ModuleId, TraitId, |
14 | }; | 10 | }; |
15 | use hir_expand::name::Name; | 11 | use hir_expand::name::Name; |
16 | 12 | ||
13 | use crate::{ | ||
14 | db::HirDatabase, primitive, utils::generics, AdtId, AliasTy, CallableDefId, CallableSig, | ||
15 | GenericPredicate, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, Substs, | ||
16 | TraitRef, Ty, | ||
17 | }; | ||
18 | |||
17 | pub struct HirFormatter<'a> { | 19 | pub struct HirFormatter<'a> { |
18 | pub db: &'a dyn HirDatabase, | 20 | pub db: &'a dyn HirDatabase, |
19 | fmt: &'a mut dyn fmt::Write, | 21 | fmt: &'a mut dyn fmt::Write, |
@@ -291,9 +293,23 @@ impl HirDisplay for Ty { | |||
291 | t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); | 293 | t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); |
292 | 294 | ||
293 | if matches!(self, Ty::Raw(..)) { | 295 | if matches!(self, Ty::Raw(..)) { |
294 | write!(f, "*{}", m.as_keyword_for_ptr())?; | 296 | write!( |
297 | f, | ||
298 | "*{}", | ||
299 | match m { | ||
300 | Mutability::Not => "const ", | ||
301 | Mutability::Mut => "mut ", | ||
302 | } | ||
303 | )?; | ||
295 | } else { | 304 | } else { |
296 | write!(f, "&{}", m.as_keyword_for_ref())?; | 305 | write!( |
306 | f, | ||
307 | "&{}", | ||
308 | match m { | ||
309 | Mutability::Not => "", | ||
310 | Mutability::Mut => "mut ", | ||
311 | } | ||
312 | )?; | ||
297 | } | 313 | } |
298 | 314 | ||
299 | let datas; | 315 | let datas; |
@@ -385,13 +401,13 @@ impl HirDisplay for Ty { | |||
385 | write!(f, " -> {}", ret_display)?; | 401 | write!(f, " -> {}", ret_display)?; |
386 | } | 402 | } |
387 | } | 403 | } |
388 | Ty::Adt(def_id, parameters) => { | 404 | Ty::Adt(AdtId(def_id), parameters) => { |
389 | match f.display_target { | 405 | match f.display_target { |
390 | DisplayTarget::Diagnostics | DisplayTarget::Test => { | 406 | DisplayTarget::Diagnostics | DisplayTarget::Test => { |
391 | let name = match *def_id { | 407 | let name = match *def_id { |
392 | AdtId::StructId(it) => f.db.struct_data(it).name.clone(), | 408 | hir_def::AdtId::StructId(it) => f.db.struct_data(it).name.clone(), |
393 | AdtId::UnionId(it) => f.db.union_data(it).name.clone(), | 409 | hir_def::AdtId::UnionId(it) => f.db.union_data(it).name.clone(), |
394 | AdtId::EnumId(it) => f.db.enum_data(it).name.clone(), | 410 | hir_def::AdtId::EnumId(it) => f.db.enum_data(it).name.clone(), |
395 | }; | 411 | }; |
396 | write!(f, "{}", name)?; | 412 | write!(f, "{}", name)?; |
397 | } | 413 | } |