aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/display.rs
diff options
context:
space:
mode:
authorBenjamin Coenen <[email protected]>2020-10-28 14:09:47 +0000
committerBenjamin Coenen <[email protected]>2020-10-28 14:23:23 +0000
commit0aca7b78de234526e1d85a4dfd23fb4f374908ea (patch)
treec0b1a4c5e2cd450c2b07cd7e3ef067a35f510365 /crates/hir_ty/src/display.rs
parentef2f7bb2438e66fd046791bb67849b6c61d946ab (diff)
do not use associated types placeholder for inlay hint
Signed-off-by: Benjamin Coenen <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/display.rs')
-rw-r--r--crates/hir_ty/src/display.rs56
1 files changed, 21 insertions, 35 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index ddfd8c8af..0bf181a92 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -84,26 +84,17 @@ pub trait HirDisplay {
84 } 84 }
85 85
86 /// Returns a String representation of `self` for test purposes 86 /// Returns a String representation of `self` for test purposes
87 fn display_test<'a>( 87 fn display_test<'a>(&'a self, db: &'a dyn HirDatabase) -> HirDisplayWrapper<'a, Self>
88 &'a self, 88 where
89 db: &'a dyn HirDatabase, 89 Self: Sized,
90 module_id: ModuleId, 90 {
91 ) -> Result<String, DisplaySourceCodeError> { 91 HirDisplayWrapper {
92 let mut result = String::new();
93 match self.hir_fmt(&mut HirFormatter {
94 db, 92 db,
95 fmt: &mut result, 93 t: self,
96 buf: String::with_capacity(20),
97 curr_size: 0,
98 max_size: None, 94 max_size: None,
99 omit_verbose_types: false, 95 omit_verbose_types: false,
100 display_target: DisplayTarget::Test { module_id }, 96 display_target: DisplayTarget::Test,
101 }) { 97 }
102 Ok(()) => {}
103 Err(HirDisplayError::FmtError) => panic!("Writing to String can't fail!"),
104 Err(HirDisplayError::DisplaySourceCodeError(e)) => return Err(e),
105 };
106 Ok(result)
107 } 98 }
108} 99}
109 100
@@ -158,7 +149,7 @@ enum DisplayTarget {
158 /// The generated code should compile, so paths need to be qualified. 149 /// The generated code should compile, so paths need to be qualified.
159 SourceCode { module_id: ModuleId }, 150 SourceCode { module_id: ModuleId },
160 /// Only for test purpose to keep real types 151 /// Only for test purpose to keep real types
161 Test { module_id: ModuleId }, 152 Test,
162} 153}
163 154
164impl DisplayTarget { 155impl DisplayTarget {
@@ -166,7 +157,7 @@ impl DisplayTarget {
166 matches!(self, Self::SourceCode {..}) 157 matches!(self, Self::SourceCode {..})
167 } 158 }
168 fn is_test(&self) -> bool { 159 fn is_test(&self) -> bool {
169 matches!(self, Self::Test {..}) 160 matches!(self, Self::Test)
170 } 161 }
171} 162}
172 163
@@ -348,7 +339,7 @@ impl HirDisplay for ApplicationTy {
348 } 339 }
349 TypeCtor::Adt(def_id) => { 340 TypeCtor::Adt(def_id) => {
350 match f.display_target { 341 match f.display_target {
351 DisplayTarget::Diagnostics => { 342 DisplayTarget::Diagnostics | DisplayTarget::Test => {
352 let name = match def_id { 343 let name = match def_id {
353 AdtId::StructId(it) => f.db.struct_data(it).name.clone(), 344 AdtId::StructId(it) => f.db.struct_data(it).name.clone(),
354 AdtId::UnionId(it) => f.db.union_data(it).name.clone(), 345 AdtId::UnionId(it) => f.db.union_data(it).name.clone(),
@@ -356,7 +347,7 @@ impl HirDisplay for ApplicationTy {
356 }; 347 };
357 write!(f, "{}", name)?; 348 write!(f, "{}", name)?;
358 } 349 }
359 DisplayTarget::SourceCode { module_id } | DisplayTarget::Test { module_id } => { 350 DisplayTarget::SourceCode { module_id } => {
360 if let Some(path) = find_path::find_path( 351 if let Some(path) = find_path::find_path(
361 f.db.upcast(), 352 f.db.upcast(),
362 ItemInNs::Types(def_id.into()), 353 ItemInNs::Types(def_id.into()),
@@ -417,28 +408,23 @@ impl HirDisplay for ApplicationTy {
417 _ => panic!("not an associated type"), 408 _ => panic!("not an associated type"),
418 }; 409 };
419 let trait_ = f.db.trait_data(trait_); 410 let trait_ = f.db.trait_data(trait_);
420 let type_alias = f.db.type_alias_data(type_alias); 411 let type_alias_data = f.db.type_alias_data(type_alias);
421 412
422 // Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types) 413 // Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types)
423 if f.display_target.is_test() || self.parameters.len() > 1 { 414 if f.display_target.is_test() {
424 write!(f, "{}::{}", trait_.name, type_alias.name)?; 415 write!(f, "{}::{}", trait_.name, type_alias_data.name)?;
425 if self.parameters.len() > 0 { 416 if self.parameters.len() > 0 {
426 write!(f, "<")?; 417 write!(f, "<")?;
427 f.write_joined(&*self.parameters.0, ", ")?; 418 f.write_joined(&*self.parameters.0, ", ")?;
428 write!(f, ">")?; 419 write!(f, ">")?;
429 } 420 }
430 } else { 421 } else {
431 if self.parameters.len() == 1 { 422 let projection_ty = ProjectionTy {
432 write!( 423 associated_ty: type_alias,
433 f, 424 parameters: self.parameters.clone(),
434 "<{} as {}>::{}", 425 };
435 self.parameters.as_single().display(f.db), 426
436 trait_.name, 427 projection_ty.hir_fmt(f)?;
437 type_alias.name
438 )?;
439 } else {
440 write!(f, "{}::{}", trait_.name, type_alias.name)?;
441 }
442 } 428 }
443 } 429 }
444 TypeCtor::ForeignType(type_alias) => { 430 TypeCtor::ForeignType(type_alias) => {