diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
commit | f05d7b41a719d848844b054a16477b29d0f063c6 (patch) | |
tree | 0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /crates/ra_hir_ty/src/display.rs | |
parent | 73ff610e41959e3e7c78a2b4b25b086883132956 (diff) | |
parent | 6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff) |
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'crates/ra_hir_ty/src/display.rs')
-rw-r--r-- | crates/ra_hir_ty/src/display.rs | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs index 23cea1a2a..19770e609 100644 --- a/crates/ra_hir_ty/src/display.rs +++ b/crates/ra_hir_ty/src/display.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use std::fmt; | 3 | use std::fmt; |
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | db::HirDatabase, utils::generics, ApplicationTy, CallableDef, FnSig, GenericPredicate, | 6 | db::HirDatabase, utils::generics, ApplicationTy, CallableDefId, FnSig, GenericPredicate, |
7 | Obligation, OpaqueTyId, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, | 7 | Obligation, OpaqueTyId, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, |
8 | }; | 8 | }; |
9 | use hir_def::{ | 9 | use hir_def::{ |
@@ -243,22 +243,36 @@ impl HirDisplay for ApplicationTy { | |||
243 | write!(f, ")")?; | 243 | write!(f, ")")?; |
244 | } | 244 | } |
245 | } | 245 | } |
246 | TypeCtor::FnPtr { .. } => { | 246 | TypeCtor::FnPtr { is_varargs, .. } => { |
247 | let sig = FnSig::from_fn_ptr_substs(&self.parameters); | 247 | let sig = FnSig::from_fn_ptr_substs(&self.parameters, is_varargs); |
248 | write!(f, "fn(")?; | 248 | write!(f, "fn(")?; |
249 | f.write_joined(sig.params(), ", ")?; | 249 | f.write_joined(sig.params(), ", ")?; |
250 | if is_varargs { | ||
251 | if sig.params().is_empty() { | ||
252 | write!(f, "...")?; | ||
253 | } else { | ||
254 | write!(f, ", ...")?; | ||
255 | } | ||
256 | } | ||
250 | write!(f, ")")?; | 257 | write!(f, ")")?; |
251 | let ret = sig.ret(); | 258 | let ret = sig.ret(); |
252 | if *ret != Ty::unit() { | 259 | if *ret != Ty::unit() { |
253 | write!(f, " -> {}", ret.display(f.db))?; | 260 | let ret_display = if f.omit_verbose_types() { |
261 | ret.display_truncated(f.db, f.max_size) | ||
262 | } else { | ||
263 | ret.display(f.db) | ||
264 | }; | ||
265 | write!(f, " -> {}", ret_display)?; | ||
254 | } | 266 | } |
255 | } | 267 | } |
256 | TypeCtor::FnDef(def) => { | 268 | TypeCtor::FnDef(def) => { |
257 | let sig = f.db.callable_item_signature(def).subst(&self.parameters); | 269 | let sig = f.db.callable_item_signature(def).subst(&self.parameters); |
258 | match def { | 270 | match def { |
259 | CallableDef::FunctionId(ff) => write!(f, "fn {}", f.db.function_data(ff).name)?, | 271 | CallableDefId::FunctionId(ff) => { |
260 | CallableDef::StructId(s) => write!(f, "{}", f.db.struct_data(s).name)?, | 272 | write!(f, "fn {}", f.db.function_data(ff).name)? |
261 | CallableDef::EnumVariantId(e) => { | 273 | } |
274 | CallableDefId::StructId(s) => write!(f, "{}", f.db.struct_data(s).name)?, | ||
275 | CallableDefId::EnumVariantId(e) => { | ||
262 | write!(f, "{}", f.db.enum_data(e.parent).variants[e.local_id].name)? | 276 | write!(f, "{}", f.db.enum_data(e.parent).variants[e.local_id].name)? |
263 | } | 277 | } |
264 | }; | 278 | }; |
@@ -279,7 +293,12 @@ impl HirDisplay for ApplicationTy { | |||
279 | write!(f, ")")?; | 293 | write!(f, ")")?; |
280 | let ret = sig.ret(); | 294 | let ret = sig.ret(); |
281 | if *ret != Ty::unit() { | 295 | if *ret != Ty::unit() { |
282 | write!(f, " -> {}", ret.display(f.db))?; | 296 | let ret_display = if f.omit_verbose_types() { |
297 | ret.display_truncated(f.db, f.max_size) | ||
298 | } else { | ||
299 | ret.display(f.db) | ||
300 | }; | ||
301 | write!(f, " -> {}", ret_display)?; | ||
283 | } | 302 | } |
284 | } | 303 | } |
285 | TypeCtor::Adt(def_id) => { | 304 | TypeCtor::Adt(def_id) => { |
@@ -369,7 +388,7 @@ impl HirDisplay for ApplicationTy { | |||
369 | let data = (*datas) | 388 | let data = (*datas) |
370 | .as_ref() | 389 | .as_ref() |
371 | .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); | 390 | .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); |
372 | data.clone().subst(&self.parameters) | 391 | data.subst(&self.parameters) |
373 | } | 392 | } |
374 | }; | 393 | }; |
375 | write!(f, "impl ")?; | 394 | write!(f, "impl ")?; |
@@ -388,7 +407,13 @@ impl HirDisplay for ApplicationTy { | |||
388 | f.write_joined(sig.params(), ", ")?; | 407 | f.write_joined(sig.params(), ", ")?; |
389 | write!(f, "|")?; | 408 | write!(f, "|")?; |
390 | }; | 409 | }; |
391 | write!(f, " -> {}", sig.ret().display(f.db))?; | 410 | |
411 | let ret_display = if f.omit_verbose_types() { | ||
412 | sig.ret().display_truncated(f.db, f.max_size) | ||
413 | } else { | ||
414 | sig.ret().display(f.db) | ||
415 | }; | ||
416 | write!(f, " -> {}", ret_display)?; | ||
392 | } else { | 417 | } else { |
393 | write!(f, "{{closure}}")?; | 418 | write!(f, "{{closure}}")?; |
394 | } | 419 | } |
@@ -456,7 +481,7 @@ impl HirDisplay for Ty { | |||
456 | let data = (*datas) | 481 | let data = (*datas) |
457 | .as_ref() | 482 | .as_ref() |
458 | .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); | 483 | .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); |
459 | data.clone().subst(&opaque_ty.parameters) | 484 | data.subst(&opaque_ty.parameters) |
460 | } | 485 | } |
461 | }; | 486 | }; |
462 | write!(f, "impl ")?; | 487 | write!(f, "impl ")?; |