aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir/src/code_model.rs14
-rw-r--r--crates/hir_ty/src/display.rs27
-rw-r--r--crates/hir_ty/src/lib.rs10
3 files changed, 25 insertions, 26 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 8e77a4a41..cdb54eca2 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -1924,21 +1924,18 @@ impl Type {
1924 fn walk_type(db: &dyn HirDatabase, type_: &Type, cb: &mut impl FnMut(Type)) { 1924 fn walk_type(db: &dyn HirDatabase, type_: &Type, cb: &mut impl FnMut(Type)) {
1925 let ty = type_.ty.value.strip_references(); 1925 let ty = type_.ty.value.strip_references();
1926 match ty { 1926 match ty {
1927 Ty::Adt(_, parameters) => { 1927 Ty::Adt(..) => {
1928 cb(type_.derived(ty.clone())); 1928 cb(type_.derived(ty.clone()));
1929 walk_substs(db, type_, parameters, cb);
1930 } 1929 }
1931 Ty::AssociatedType(_, parameters) => { 1930 Ty::AssociatedType(..) => {
1932 if let Some(_) = ty.associated_type_parent_trait(db) { 1931 if let Some(_) = ty.associated_type_parent_trait(db) {
1933 cb(type_.derived(ty.clone())); 1932 cb(type_.derived(ty.clone()));
1934 } 1933 }
1935 walk_substs(db, type_, parameters, cb);
1936 } 1934 }
1937 Ty::OpaqueType(_, parameters) => { 1935 Ty::OpaqueType(..) => {
1938 if let Some(bounds) = ty.impl_trait_bounds(db) { 1936 if let Some(bounds) = ty.impl_trait_bounds(db) {
1939 walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb); 1937 walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb);
1940 } 1938 }
1941 walk_substs(db, type_, parameters, cb);
1942 } 1939 }
1943 Ty::Opaque(opaque_ty) => { 1940 Ty::Opaque(opaque_ty) => {
1944 if let Some(bounds) = ty.impl_trait_bounds(db) { 1941 if let Some(bounds) = ty.impl_trait_bounds(db) {
@@ -1956,7 +1953,10 @@ impl Type {
1956 walk_bounds(db, &type_.derived(ty.clone()), bounds.as_ref(), cb); 1953 walk_bounds(db, &type_.derived(ty.clone()), bounds.as_ref(), cb);
1957 } 1954 }
1958 1955
1959 _ => (), 1956 _ => {}
1957 }
1958 if let Some(substs) = ty.substs() {
1959 walk_substs(db, type_, &substs, cb);
1960 } 1960 }
1961 } 1961 }
1962 1962
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(&parameters, is_varargs)) 730 Some(FnSig::from_fn_ptr_substs(&parameters, *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(&parameters)) 734 Some(sig.subst(&parameters))
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 }