mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Fix code_model::Type::walk not walking all types
This commit is contained in:
parent
a3f5491a1a
commit
faf2dd49e4
3 changed files with 25 additions and 26 deletions
|
@ -1924,21 +1924,18 @@ impl Type {
|
||||||
fn walk_type(db: &dyn HirDatabase, type_: &Type, cb: &mut impl FnMut(Type)) {
|
fn walk_type(db: &dyn HirDatabase, type_: &Type, cb: &mut impl FnMut(Type)) {
|
||||||
let ty = type_.ty.value.strip_references();
|
let ty = type_.ty.value.strip_references();
|
||||||
match ty {
|
match ty {
|
||||||
Ty::Adt(_, parameters) => {
|
Ty::Adt(..) => {
|
||||||
cb(type_.derived(ty.clone()));
|
cb(type_.derived(ty.clone()));
|
||||||
walk_substs(db, type_, parameters, cb);
|
|
||||||
}
|
}
|
||||||
Ty::AssociatedType(_, parameters) => {
|
Ty::AssociatedType(..) => {
|
||||||
if let Some(_) = ty.associated_type_parent_trait(db) {
|
if let Some(_) = ty.associated_type_parent_trait(db) {
|
||||||
cb(type_.derived(ty.clone()));
|
cb(type_.derived(ty.clone()));
|
||||||
}
|
}
|
||||||
walk_substs(db, type_, parameters, cb);
|
|
||||||
}
|
}
|
||||||
Ty::OpaqueType(_, parameters) => {
|
Ty::OpaqueType(..) => {
|
||||||
if let Some(bounds) = ty.impl_trait_bounds(db) {
|
if let Some(bounds) = ty.impl_trait_bounds(db) {
|
||||||
walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb);
|
walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb);
|
||||||
}
|
}
|
||||||
walk_substs(db, type_, parameters, cb);
|
|
||||||
}
|
}
|
||||||
Ty::Opaque(opaque_ty) => {
|
Ty::Opaque(opaque_ty) => {
|
||||||
if let Some(bounds) = ty.impl_trait_bounds(db) {
|
if let Some(bounds) = ty.impl_trait_bounds(db) {
|
||||||
|
@ -1956,7 +1953,10 @@ impl Type {
|
||||||
walk_bounds(db, &type_.derived(ty.clone()), bounds.as_ref(), cb);
|
walk_bounds(db, &type_.derived(ty.clone()), bounds.as_ref(), cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => (),
|
_ => {}
|
||||||
|
}
|
||||||
|
if let Some(substs) = ty.substs() {
|
||||||
|
walk_substs(db, type_, &substs, cb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -341,11 +341,12 @@ impl HirDisplay for Ty {
|
||||||
write!(f, ")")?;
|
write!(f, ")")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Ty::FnPtr { is_varargs, ref substs, .. } => {
|
Ty::FnPtr { is_varargs, substs, .. } => {
|
||||||
let sig = FnSig::from_fn_ptr_substs(&substs, is_varargs);
|
let sig = FnSig::from_fn_ptr_substs(&substs, *is_varargs);
|
||||||
sig.hir_fmt(f)?;
|
sig.hir_fmt(f)?;
|
||||||
}
|
}
|
||||||
&Ty::FnDef(def, ref parameters) => {
|
Ty::FnDef(def, parameters) => {
|
||||||
|
let def = *def;
|
||||||
let sig = f.db.callable_item_signature(def).subst(parameters);
|
let sig = f.db.callable_item_signature(def).subst(parameters);
|
||||||
match def {
|
match def {
|
||||||
CallableDefId::FunctionId(ff) => {
|
CallableDefId::FunctionId(ff) => {
|
||||||
|
@ -383,10 +384,10 @@ impl HirDisplay for Ty {
|
||||||
write!(f, " -> {}", ret_display)?;
|
write!(f, " -> {}", ret_display)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Ty::Adt(def_id, ref parameters) => {
|
Ty::Adt(def_id, parameters) => {
|
||||||
match f.display_target {
|
match f.display_target {
|
||||||
DisplayTarget::Diagnostics | DisplayTarget::Test => {
|
DisplayTarget::Diagnostics | DisplayTarget::Test => {
|
||||||
let name = match def_id {
|
let name = match *def_id {
|
||||||
AdtId::StructId(it) => f.db.struct_data(it).name.clone(),
|
AdtId::StructId(it) => f.db.struct_data(it).name.clone(),
|
||||||
AdtId::UnionId(it) => f.db.union_data(it).name.clone(),
|
AdtId::UnionId(it) => f.db.union_data(it).name.clone(),
|
||||||
AdtId::EnumId(it) => f.db.enum_data(it).name.clone(),
|
AdtId::EnumId(it) => f.db.enum_data(it).name.clone(),
|
||||||
|
@ -396,7 +397,7 @@ impl HirDisplay for Ty {
|
||||||
DisplayTarget::SourceCode { module_id } => {
|
DisplayTarget::SourceCode { module_id } => {
|
||||||
if let Some(path) = find_path::find_path(
|
if let Some(path) = find_path::find_path(
|
||||||
f.db.upcast(),
|
f.db.upcast(),
|
||||||
ItemInNs::Types(def_id.into()),
|
ItemInNs::Types((*def_id).into()),
|
||||||
module_id,
|
module_id,
|
||||||
) {
|
) {
|
||||||
write!(f, "{}", path)?;
|
write!(f, "{}", path)?;
|
||||||
|
@ -447,13 +448,13 @@ impl HirDisplay for Ty {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Ty::AssociatedType(type_alias, ref parameters) => {
|
Ty::AssociatedType(type_alias, parameters) => {
|
||||||
let trait_ = match type_alias.lookup(f.db.upcast()).container {
|
let trait_ = match type_alias.lookup(f.db.upcast()).container {
|
||||||
AssocContainerId::TraitId(it) => it,
|
AssocContainerId::TraitId(it) => it,
|
||||||
_ => panic!("not an associated type"),
|
_ => panic!("not an associated type"),
|
||||||
};
|
};
|
||||||
let trait_ = f.db.trait_data(trait_);
|
let trait_ = f.db.trait_data(trait_);
|
||||||
let type_alias_data = f.db.type_alias_data(type_alias);
|
let type_alias_data = f.db.type_alias_data(*type_alias);
|
||||||
|
|
||||||
// Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types)
|
// Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types)
|
||||||
if f.display_target.is_test() {
|
if f.display_target.is_test() {
|
||||||
|
@ -465,13 +466,13 @@ impl HirDisplay for Ty {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let projection_ty =
|
let projection_ty =
|
||||||
ProjectionTy { associated_ty: type_alias, parameters: parameters.clone() };
|
ProjectionTy { associated_ty: *type_alias, parameters: parameters.clone() };
|
||||||
|
|
||||||
projection_ty.hir_fmt(f)?;
|
projection_ty.hir_fmt(f)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Ty::ForeignType(type_alias, ref parameters) => {
|
Ty::ForeignType(type_alias, parameters) => {
|
||||||
let type_alias = f.db.type_alias_data(type_alias);
|
let type_alias = f.db.type_alias_data(*type_alias);
|
||||||
write!(f, "{}", type_alias.name)?;
|
write!(f, "{}", type_alias.name)?;
|
||||||
if parameters.len() > 0 {
|
if parameters.len() > 0 {
|
||||||
write!(f, "<")?;
|
write!(f, "<")?;
|
||||||
|
@ -479,9 +480,9 @@ impl HirDisplay for Ty {
|
||||||
write!(f, ">")?;
|
write!(f, ">")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Ty::OpaqueType(opaque_ty_id, ref parameters) => {
|
Ty::OpaqueType(opaque_ty_id, parameters) => {
|
||||||
match opaque_ty_id {
|
match opaque_ty_id {
|
||||||
OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
|
&OpaqueTyId::ReturnTypeImplTrait(func, idx) => {
|
||||||
let datas =
|
let datas =
|
||||||
f.db.return_type_impl_traits(func).expect("impl trait id without data");
|
f.db.return_type_impl_traits(func).expect("impl trait id without data");
|
||||||
let data = (*datas)
|
let data = (*datas)
|
||||||
|
|
|
@ -726,11 +726,11 @@ impl Ty {
|
||||||
|
|
||||||
pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig> {
|
pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig> {
|
||||||
match self {
|
match self {
|
||||||
&Ty::FnPtr { is_varargs, substs: ref parameters, .. } => {
|
Ty::FnPtr { is_varargs, substs: parameters, .. } => {
|
||||||
Some(FnSig::from_fn_ptr_substs(¶meters, is_varargs))
|
Some(FnSig::from_fn_ptr_substs(¶meters, *is_varargs))
|
||||||
}
|
}
|
||||||
&Ty::FnDef(def, ref parameters) => {
|
Ty::FnDef(def, parameters) => {
|
||||||
let sig = db.callable_item_signature(def);
|
let sig = db.callable_item_signature(*def);
|
||||||
Some(sig.subst(¶meters))
|
Some(sig.subst(¶meters))
|
||||||
}
|
}
|
||||||
Ty::Closure { substs: parameters, .. } => {
|
Ty::Closure { substs: parameters, .. } => {
|
||||||
|
@ -783,7 +783,6 @@ impl Ty {
|
||||||
| Ty::AssociatedType(_, substs)
|
| Ty::AssociatedType(_, substs)
|
||||||
| Ty::ForeignType(_, substs)
|
| Ty::ForeignType(_, substs)
|
||||||
| Ty::Closure { substs, .. } => Some(substs),
|
| Ty::Closure { substs, .. } => Some(substs),
|
||||||
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -802,7 +801,6 @@ impl Ty {
|
||||||
| Ty::AssociatedType(_, substs)
|
| Ty::AssociatedType(_, substs)
|
||||||
| Ty::ForeignType(_, substs)
|
| Ty::ForeignType(_, substs)
|
||||||
| Ty::Closure { substs, .. } => Some(substs),
|
| Ty::Closure { substs, .. } => Some(substs),
|
||||||
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue