Skip to content

Commit faf2dd4

Browse files
committed
Fix code_model::Type::walk not walking all types
1 parent a3f5491 commit faf2dd4

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

crates/hir/src/code_model.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,21 +1924,18 @@ impl Type {
19241924
fn walk_type(db: &dyn HirDatabase, type_: &Type, cb: &mut impl FnMut(Type)) {
19251925
let ty = type_.ty.value.strip_references();
19261926
match ty {
1927-
Ty::Adt(_, parameters) => {
1927+
Ty::Adt(..) => {
19281928
cb(type_.derived(ty.clone()));
1929-
walk_substs(db, type_, parameters, cb);
19301929
}
1931-
Ty::AssociatedType(_, parameters) => {
1930+
Ty::AssociatedType(..) => {
19321931
if let Some(_) = ty.associated_type_parent_trait(db) {
19331932
cb(type_.derived(ty.clone()));
19341933
}
1935-
walk_substs(db, type_, parameters, cb);
19361934
}
1937-
Ty::OpaqueType(_, parameters) => {
1935+
Ty::OpaqueType(..) => {
19381936
if let Some(bounds) = ty.impl_trait_bounds(db) {
19391937
walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb);
19401938
}
1941-
walk_substs(db, type_, parameters, cb);
19421939
}
19431940
Ty::Opaque(opaque_ty) => {
19441941
if let Some(bounds) = ty.impl_trait_bounds(db) {
@@ -1956,7 +1953,10 @@ impl Type {
19561953
walk_bounds(db, &type_.derived(ty.clone()), bounds.as_ref(), cb);
19571954
}
19581955

1959-
_ => (),
1956+
_ => {}
1957+
}
1958+
if let Some(substs) = ty.substs() {
1959+
walk_substs(db, type_, &substs, cb);
19601960
}
19611961
}
19621962

crates/hir_ty/src/display.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,12 @@ impl HirDisplay for Ty {
341341
write!(f, ")")?;
342342
}
343343
}
344-
&Ty::FnPtr { is_varargs, ref substs, .. } => {
345-
let sig = FnSig::from_fn_ptr_substs(&substs, is_varargs);
344+
Ty::FnPtr { is_varargs, substs, .. } => {
345+
let sig = FnSig::from_fn_ptr_substs(&substs, *is_varargs);
346346
sig.hir_fmt(f)?;
347347
}
348-
&Ty::FnDef(def, ref parameters) => {
348+
Ty::FnDef(def, parameters) => {
349+
let def = *def;
349350
let sig = f.db.callable_item_signature(def).subst(parameters);
350351
match def {
351352
CallableDefId::FunctionId(ff) => {
@@ -383,10 +384,10 @@ impl HirDisplay for Ty {
383384
write!(f, " -> {}", ret_display)?;
384385
}
385386
}
386-
&Ty::Adt(def_id, ref parameters) => {
387+
Ty::Adt(def_id, parameters) => {
387388
match f.display_target {
388389
DisplayTarget::Diagnostics | DisplayTarget::Test => {
389-
let name = match def_id {
390+
let name = match *def_id {
390391
AdtId::StructId(it) => f.db.struct_data(it).name.clone(),
391392
AdtId::UnionId(it) => f.db.union_data(it).name.clone(),
392393
AdtId::EnumId(it) => f.db.enum_data(it).name.clone(),
@@ -396,7 +397,7 @@ impl HirDisplay for Ty {
396397
DisplayTarget::SourceCode { module_id } => {
397398
if let Some(path) = find_path::find_path(
398399
f.db.upcast(),
399-
ItemInNs::Types(def_id.into()),
400+
ItemInNs::Types((*def_id).into()),
400401
module_id,
401402
) {
402403
write!(f, "{}", path)?;
@@ -447,13 +448,13 @@ impl HirDisplay for Ty {
447448
}
448449
}
449450
}
450-
&Ty::AssociatedType(type_alias, ref parameters) => {
451+
Ty::AssociatedType(type_alias, parameters) => {
451452
let trait_ = match type_alias.lookup(f.db.upcast()).container {
452453
AssocContainerId::TraitId(it) => it,
453454
_ => panic!("not an associated type"),
454455
};
455456
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);
457458

458459
// Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types)
459460
if f.display_target.is_test() {
@@ -465,23 +466,23 @@ impl HirDisplay for Ty {
465466
}
466467
} else {
467468
let projection_ty =
468-
ProjectionTy { associated_ty: type_alias, parameters: parameters.clone() };
469+
ProjectionTy { associated_ty: *type_alias, parameters: parameters.clone() };
469470

470471
projection_ty.hir_fmt(f)?;
471472
}
472473
}
473-
&Ty::ForeignType(type_alias, ref parameters) => {
474-
let type_alias = f.db.type_alias_data(type_alias);
474+
Ty::ForeignType(type_alias, parameters) => {
475+
let type_alias = f.db.type_alias_data(*type_alias);
475476
write!(f, "{}", type_alias.name)?;
476477
if parameters.len() > 0 {
477478
write!(f, "<")?;
478479
f.write_joined(&*parameters.0, ", ")?;
479480
write!(f, ">")?;
480481
}
481482
}
482-
&Ty::OpaqueType(opaque_ty_id, ref parameters) => {
483+
Ty::OpaqueType(opaque_ty_id, parameters) => {
483484
match opaque_ty_id {
484-
OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
485+
&OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
485486
let datas =
486487
f.db.return_type_impl_traits(func).expect("impl trait id without data");
487488
let data = (*datas)

crates/hir_ty/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -726,11 +726,11 @@ impl Ty {
726726

727727
pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig> {
728728
match self {
729-
&Ty::FnPtr { is_varargs, substs: ref parameters, .. } => {
730-
Some(FnSig::from_fn_ptr_substs(&parameters, is_varargs))
729+
Ty::FnPtr { is_varargs, substs: parameters, .. } => {
730+
Some(FnSig::from_fn_ptr_substs(&parameters, *is_varargs))
731731
}
732-
&Ty::FnDef(def, ref parameters) => {
733-
let sig = db.callable_item_signature(def);
732+
Ty::FnDef(def, parameters) => {
733+
let sig = db.callable_item_signature(*def);
734734
Some(sig.subst(&parameters))
735735
}
736736
Ty::Closure { substs: parameters, .. } => {
@@ -783,7 +783,6 @@ impl Ty {
783783
| Ty::AssociatedType(_, substs)
784784
| Ty::ForeignType(_, substs)
785785
| Ty::Closure { substs, .. } => Some(substs),
786-
787786
_ => None,
788787
}
789788
}
@@ -802,7 +801,6 @@ impl Ty {
802801
| Ty::AssociatedType(_, substs)
803802
| Ty::ForeignType(_, substs)
804803
| Ty::Closure { substs, .. } => Some(substs),
805-
806804
_ => None,
807805
}
808806
}

0 commit comments

Comments
 (0)