From 42217738e0b121a8e5d48a9a55cb51ef6c98975f Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 14 Mar 2021 17:40:55 +0100 Subject: Don't use Substs for Ref/Raw/Array/Slice --- crates/hir/src/lib.rs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'crates/hir/src/lib.rs') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index eb1cd66fb..c0810c69b 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1598,7 +1598,7 @@ impl Type { pub fn remove_ref(&self) -> Option { match &self.ty.value.interned(&Interner) { - TyKind::Ref(.., substs) => Some(self.derived(substs[0].clone())), + TyKind::Ref(.., ty) => Some(self.derived(ty.clone())), _ => None, } } @@ -1752,10 +1752,30 @@ impl Type { return go(&self.ty.value); fn go(ty: &Ty) -> bool { - if ty.is_unknown() { - true - } else { - ty.substs().map_or(false, |substs| substs.iter().any(go)) + match ty.interned(&Interner) { + TyKind::Unknown => true, + + TyKind::Adt(_, substs) + | TyKind::AssociatedType(_, substs) + | TyKind::Tuple(_, substs) + | TyKind::OpaqueType(_, substs) + | TyKind::FnDef(_, substs) + | TyKind::Closure(_, substs) => substs.iter().any(go), + + TyKind::Array(ty) | TyKind::Slice(ty) | TyKind::Raw(_, ty) | TyKind::Ref(_, ty) => { + go(ty) + } + + TyKind::Scalar(_) + | TyKind::Str + | TyKind::Never + | TyKind::Placeholder(_) + | TyKind::BoundVar(_) + | TyKind::InferenceVar(_, _) + | TyKind::Dyn(_) + | TyKind::Function(_) + | TyKind::Alias(_) + | TyKind::ForeignType(_) => false, } } } @@ -1990,6 +2010,10 @@ impl Type { walk_bounds(db, &type_.derived(ty.clone()), bounds.as_ref(), cb); } + TyKind::Ref(_, ty) | TyKind::Raw(_, ty) | TyKind::Array(ty) | TyKind::Slice(ty) => { + walk_type(db, &type_.derived(ty.clone()), cb); + } + _ => {} } if let Some(substs) = ty.substs() { -- cgit v1.2.3