diff options
author | Lukas Wirth <[email protected]> | 2021-02-28 18:46:59 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2021-02-28 19:15:56 +0000 |
commit | faf2dd49e4845e1437b704a28bb5603be5fd605b (patch) | |
tree | f3183d296fada9a5847687f5bbdf0c336ed65504 /crates/hir_ty/src | |
parent | a3f5491a1a312393429a44028e7496fe0a12f8c2 (diff) |
Fix code_model::Type::walk not walking all types
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r-- | crates/hir_ty/src/display.rs | 27 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 10 |
2 files changed, 18 insertions, 19 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 1a3b9095a..cd9dcf6c0 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -341,11 +341,12 @@ impl HirDisplay for Ty { | |||
341 | write!(f, ")")?; | 341 | write!(f, ")")?; |
342 | } | 342 | } |
343 | } | 343 | } |
344 | &Ty::FnPtr { is_varargs, ref substs, .. } => { | 344 | Ty::FnPtr { is_varargs, substs, .. } => { |
345 | let sig = FnSig::from_fn_ptr_substs(&substs, is_varargs); | 345 | let sig = FnSig::from_fn_ptr_substs(&substs, *is_varargs); |
346 | sig.hir_fmt(f)?; | 346 | sig.hir_fmt(f)?; |
347 | } | 347 | } |
348 | &Ty::FnDef(def, ref parameters) => { | 348 | Ty::FnDef(def, parameters) => { |
349 | let def = *def; | ||
349 | let sig = f.db.callable_item_signature(def).subst(parameters); | 350 | let sig = f.db.callable_item_signature(def).subst(parameters); |
350 | match def { | 351 | match def { |
351 | CallableDefId::FunctionId(ff) => { | 352 | CallableDefId::FunctionId(ff) => { |
@@ -383,10 +384,10 @@ impl HirDisplay for Ty { | |||
383 | write!(f, " -> {}", ret_display)?; | 384 | write!(f, " -> {}", ret_display)?; |
384 | } | 385 | } |
385 | } | 386 | } |
386 | &Ty::Adt(def_id, ref parameters) => { | 387 | Ty::Adt(def_id, parameters) => { |
387 | match f.display_target { | 388 | match f.display_target { |
388 | DisplayTarget::Diagnostics | DisplayTarget::Test => { | 389 | DisplayTarget::Diagnostics | DisplayTarget::Test => { |
389 | let name = match def_id { | 390 | let name = match *def_id { |
390 | AdtId::StructId(it) => f.db.struct_data(it).name.clone(), | 391 | AdtId::StructId(it) => f.db.struct_data(it).name.clone(), |
391 | AdtId::UnionId(it) => f.db.union_data(it).name.clone(), | 392 | AdtId::UnionId(it) => f.db.union_data(it).name.clone(), |
392 | AdtId::EnumId(it) => f.db.enum_data(it).name.clone(), | 393 | AdtId::EnumId(it) => f.db.enum_data(it).name.clone(), |
@@ -396,7 +397,7 @@ impl HirDisplay for Ty { | |||
396 | DisplayTarget::SourceCode { module_id } => { | 397 | DisplayTarget::SourceCode { module_id } => { |
397 | if let Some(path) = find_path::find_path( | 398 | if let Some(path) = find_path::find_path( |
398 | f.db.upcast(), | 399 | f.db.upcast(), |
399 | ItemInNs::Types(def_id.into()), | 400 | ItemInNs::Types((*def_id).into()), |
400 | module_id, | 401 | module_id, |
401 | ) { | 402 | ) { |
402 | write!(f, "{}", path)?; | 403 | write!(f, "{}", path)?; |
@@ -447,13 +448,13 @@ impl HirDisplay for Ty { | |||
447 | } | 448 | } |
448 | } | 449 | } |
449 | } | 450 | } |
450 | &Ty::AssociatedType(type_alias, ref parameters) => { | 451 | Ty::AssociatedType(type_alias, parameters) => { |
451 | let trait_ = match type_alias.lookup(f.db.upcast()).container { | 452 | let trait_ = match type_alias.lookup(f.db.upcast()).container { |
452 | AssocContainerId::TraitId(it) => it, | 453 | AssocContainerId::TraitId(it) => it, |
453 | _ => panic!("not an associated type"), | 454 | _ => panic!("not an associated type"), |
454 | }; | 455 | }; |
455 | let trait_ = f.db.trait_data(trait_); | 456 | let trait_ = f.db.trait_data(trait_); |
456 | let type_alias_data = f.db.type_alias_data(type_alias); | 457 | let type_alias_data = f.db.type_alias_data(*type_alias); |
457 | 458 | ||
458 | // Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types) | 459 | // Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types) |
459 | if f.display_target.is_test() { | 460 | if f.display_target.is_test() { |
@@ -465,13 +466,13 @@ impl HirDisplay for Ty { | |||
465 | } | 466 | } |
466 | } else { | 467 | } else { |
467 | let projection_ty = | 468 | let projection_ty = |
468 | ProjectionTy { associated_ty: type_alias, parameters: parameters.clone() }; | 469 | ProjectionTy { associated_ty: *type_alias, parameters: parameters.clone() }; |
469 | 470 | ||
470 | projection_ty.hir_fmt(f)?; | 471 | projection_ty.hir_fmt(f)?; |
471 | } | 472 | } |
472 | } | 473 | } |
473 | &Ty::ForeignType(type_alias, ref parameters) => { | 474 | Ty::ForeignType(type_alias, parameters) => { |
474 | let type_alias = f.db.type_alias_data(type_alias); | 475 | let type_alias = f.db.type_alias_data(*type_alias); |
475 | write!(f, "{}", type_alias.name)?; | 476 | write!(f, "{}", type_alias.name)?; |
476 | if parameters.len() > 0 { | 477 | if parameters.len() > 0 { |
477 | write!(f, "<")?; | 478 | write!(f, "<")?; |
@@ -479,9 +480,9 @@ impl HirDisplay for Ty { | |||
479 | write!(f, ">")?; | 480 | write!(f, ">")?; |
480 | } | 481 | } |
481 | } | 482 | } |
482 | &Ty::OpaqueType(opaque_ty_id, ref parameters) => { | 483 | Ty::OpaqueType(opaque_ty_id, parameters) => { |
483 | match opaque_ty_id { | 484 | match opaque_ty_id { |
484 | OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 485 | &OpaqueTyId::ReturnTypeImplTrait(func, idx) => { |
485 | let datas = | 486 | let datas = |
486 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); | 487 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); |
487 | let data = (*datas) | 488 | let data = (*datas) |
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 5cbb9a3cc..117d69f01 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -726,11 +726,11 @@ impl Ty { | |||
726 | 726 | ||
727 | pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig> { | 727 | pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig> { |
728 | match self { | 728 | match self { |
729 | &Ty::FnPtr { is_varargs, substs: ref parameters, .. } => { | 729 | Ty::FnPtr { is_varargs, substs: parameters, .. } => { |
730 | Some(FnSig::from_fn_ptr_substs(¶meters, is_varargs)) | 730 | Some(FnSig::from_fn_ptr_substs(¶meters, *is_varargs)) |
731 | } | 731 | } |
732 | &Ty::FnDef(def, ref parameters) => { | 732 | Ty::FnDef(def, parameters) => { |
733 | let sig = db.callable_item_signature(def); | 733 | let sig = db.callable_item_signature(*def); |
734 | Some(sig.subst(¶meters)) | 734 | Some(sig.subst(¶meters)) |
735 | } | 735 | } |
736 | Ty::Closure { substs: parameters, .. } => { | 736 | Ty::Closure { substs: parameters, .. } => { |
@@ -783,7 +783,6 @@ impl Ty { | |||
783 | | Ty::AssociatedType(_, substs) | 783 | | Ty::AssociatedType(_, substs) |
784 | | Ty::ForeignType(_, substs) | 784 | | Ty::ForeignType(_, substs) |
785 | | Ty::Closure { substs, .. } => Some(substs), | 785 | | Ty::Closure { substs, .. } => Some(substs), |
786 | |||
787 | _ => None, | 786 | _ => None, |
788 | } | 787 | } |
789 | } | 788 | } |
@@ -802,7 +801,6 @@ impl Ty { | |||
802 | | Ty::AssociatedType(_, substs) | 801 | | Ty::AssociatedType(_, substs) |
803 | | Ty::ForeignType(_, substs) | 802 | | Ty::ForeignType(_, substs) |
804 | | Ty::Closure { substs, .. } => Some(substs), | 803 | | Ty::Closure { substs, .. } => Some(substs), |
805 | |||
806 | _ => None, | 804 | _ => None, |
807 | } | 805 | } |
808 | } | 806 | } |