aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/display.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/display.rs')
-rw-r--r--crates/ra_hir_ty/src/display.rs63
1 files changed, 36 insertions, 27 deletions
diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs
index f5edaea8c..b9c4d2e89 100644
--- a/crates/ra_hir_ty/src/display.rs
+++ b/crates/ra_hir_ty/src/display.rs
@@ -136,6 +136,12 @@ enum DisplayTarget {
136 SourceCode { module_id: ModuleId }, 136 SourceCode { module_id: ModuleId },
137} 137}
138 138
139impl DisplayTarget {
140 fn is_source_code(&self) -> bool {
141 matches!(self, Self::SourceCode {..})
142 }
143}
144
139#[derive(Debug)] 145#[derive(Debug)]
140pub enum DisplaySourceCodeError { 146pub enum DisplaySourceCodeError {
141 PathNotFound, 147 PathNotFound,
@@ -303,37 +309,40 @@ impl HirDisplay for ApplicationTy {
303 309
304 if self.parameters.len() > 0 { 310 if self.parameters.len() > 0 {
305 let mut non_default_parameters = Vec::with_capacity(self.parameters.len()); 311 let mut non_default_parameters = Vec::with_capacity(self.parameters.len());
306 let parameters_to_write = if f.omit_verbose_types() { 312 let parameters_to_write =
307 match self 313 if f.display_target.is_source_code() || f.omit_verbose_types() {
308 .ctor 314 match self
309 .as_generic_def() 315 .ctor
310 .map(|generic_def_id| f.db.generic_defaults(generic_def_id)) 316 .as_generic_def()
311 .filter(|defaults| !defaults.is_empty()) 317 .map(|generic_def_id| f.db.generic_defaults(generic_def_id))
312 { 318 .filter(|defaults| !defaults.is_empty())
313 None => self.parameters.0.as_ref(), 319 {
314 Some(default_parameters) => { 320 None => self.parameters.0.as_ref(),
315 for (i, parameter) in self.parameters.iter().enumerate() { 321 Some(default_parameters) => {
316 match (parameter, default_parameters.get(i)) { 322 for (i, parameter) in self.parameters.iter().enumerate() {
317 (&Ty::Unknown, _) | (_, None) => { 323 match (parameter, default_parameters.get(i)) {
318 non_default_parameters.push(parameter.clone()) 324 (&Ty::Unknown, _) | (_, None) => {
319 } 325 non_default_parameters.push(parameter.clone())
320 (_, Some(default_parameter)) 326 }
321 if parameter != default_parameter => 327 (_, Some(default_parameter))
322 { 328 if parameter != default_parameter =>
323 non_default_parameters.push(parameter.clone()) 329 {
330 non_default_parameters.push(parameter.clone())
331 }
332 _ => (),
324 } 333 }
325 _ => (),
326 } 334 }
335 &non_default_parameters
327 } 336 }
328 &non_default_parameters
329 } 337 }
330 } 338 } else {
331 } else { 339 self.parameters.0.as_ref()
332 self.parameters.0.as_ref() 340 };
333 }; 341 if !parameters_to_write.is_empty() {
334 write!(f, "<")?; 342 write!(f, "<")?;
335 f.write_joined(parameters_to_write, ", ")?; 343 f.write_joined(parameters_to_write, ", ")?;
336 write!(f, ">")?; 344 write!(f, ">")?;
345 }
337 } 346 }
338 } 347 }
339 TypeCtor::AssociatedType(type_alias) => { 348 TypeCtor::AssociatedType(type_alias) => {