1 //! This module is concerned with finding methods that a given type provides.
2 //! For details about how this works in rustc, see the method lookup page in the
3 //! [rustc guide](https://rust-lang.github.io/rustc-guide/method-lookup.html)
4 //! and the corresponding code mostly in librustc_typeck/check/method/probe.rs.
5 use std::{iter, sync::Arc};
7 use arrayvec::ArrayVec;
9 use chalk_ir::{cast::Cast, Mutability};
11 lang_item::LangItemTarget, AssocContainerId, AssocItemId, FunctionId, GenericDefId, HasModule,
12 ImplId, Lookup, ModuleId, TraitId,
14 use hir_expand::name::Name;
15 use rustc_hash::{FxHashMap, FxHashSet};
21 primitive::{self, FloatTy, IntTy, UintTy},
23 utils::all_super_traits,
24 AdtId, Canonical, DebruijnIndex, FnPointer, FnSig, ForeignDefId, InEnvironment, Interner,
25 Scalar, Substitution, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk,
28 /// This is used as a key for indexing impls.
29 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
30 pub enum TyFingerprint {
40 ForeignType(ForeignDefId),
45 /// Creates a TyFingerprint for looking up an impl. Only certain types can
46 /// have impls: if we have some `struct S`, we can have an `impl S`, but not
47 /// `impl &S`. Hence, this will return `None` for reference types and such.
48 pub fn for_impl(ty: &Ty) -> Option<TyFingerprint> {
49 let fp = match *ty.interned(&Interner) {
50 TyKind::Str => TyFingerprint::Str,
51 TyKind::Never => TyFingerprint::Never,
52 TyKind::Slice(..) => TyFingerprint::Slice,
53 TyKind::Array(..) => TyFingerprint::Array,
54 TyKind::Scalar(scalar) => TyFingerprint::Scalar(scalar),
55 TyKind::Adt(AdtId(adt), _) => TyFingerprint::Adt(adt),
56 TyKind::Tuple(cardinality, _) => TyFingerprint::Tuple(cardinality),
57 TyKind::Raw(mutability, ..) => TyFingerprint::RawPtr(mutability),
58 TyKind::ForeignType(alias_id, ..) => TyFingerprint::ForeignType(alias_id),
59 TyKind::Function(FnPointer { num_args, sig, .. }) => {
60 TyFingerprint::FnPtr(num_args, sig)
62 TyKind::Dyn(_) => ty.dyn_trait().map(|trait_| TyFingerprint::Dyn(trait_))?,
69 pub(crate) const ALL_INT_FPS: [TyFingerprint; 12] = [
70 TyFingerprint::Scalar(Scalar::Int(IntTy::I8)),
71 TyFingerprint::Scalar(Scalar::Int(IntTy::I16)),
72 TyFingerprint::Scalar(Scalar::Int(IntTy::I32)),
73 TyFingerprint::Scalar(Scalar::Int(IntTy::I64)),
74 TyFingerprint::Scalar(Scalar::Int(IntTy::I128)),
75 TyFingerprint::Scalar(Scalar::Int(IntTy::Isize)),
76 TyFingerprint::Scalar(Scalar::Uint(UintTy::U8)),
77 TyFingerprint::Scalar(Scalar::Uint(UintTy::U16)),
78 TyFingerprint::Scalar(Scalar::Uint(UintTy::U32)),
79 TyFingerprint::Scalar(Scalar::Uint(UintTy::U64)),
80 TyFingerprint::Scalar(Scalar::Uint(UintTy::U128)),
81 TyFingerprint::Scalar(Scalar::Uint(UintTy::Usize)),
84 pub(crate) const ALL_FLOAT_FPS: [TyFingerprint; 2] = [
85 TyFingerprint::Scalar(Scalar::Float(FloatTy::F32)),
86 TyFingerprint::Scalar(Scalar::Float(FloatTy::F64)),
89 /// Trait impls defined or available in some crate.
90 #[derive(Debug, Eq, PartialEq)]
91 pub struct TraitImpls {
92 // If the `Option<TyFingerprint>` is `None`, the impl may apply to any self type.
93 map: FxHashMap<TraitId, FxHashMap<Option<TyFingerprint>, Vec<ImplId>>>,
97 pub(crate) fn trait_impls_in_crate_query(db: &dyn HirDatabase, krate: CrateId) -> Arc<Self> {
98 let _p = profile::span("trait_impls_in_crate_query");
99 let mut impls = Self { map: FxHashMap::default() };
101 let crate_def_map = db.crate_def_map(krate);
102 for (_module_id, module_data) in crate_def_map.modules() {
103 for impl_id in module_data.scope.impls() {
104 let target_trait = match db.impl_trait(impl_id) {
105 Some(tr) => tr.value.hir_trait_id(),
108 let self_ty = db.impl_self_ty(impl_id);
109 let self_ty_fp = TyFingerprint::for_impl(&self_ty.value);
123 pub(crate) fn trait_impls_in_deps_query(db: &dyn HirDatabase, krate: CrateId) -> Arc<Self> {
124 let _p = profile::span("trait_impls_in_deps_query");
125 let crate_graph = db.crate_graph();
126 let mut res = Self { map: FxHashMap::default() };
128 for krate in crate_graph.transitive_deps(krate) {
129 res.merge(&db.trait_impls_in_crate(krate));
135 fn merge(&mut self, other: &Self) {
136 for (trait_, other_map) in &other.map {
137 let map = self.map.entry(*trait_).or_default();
138 for (fp, impls) in other_map {
139 let vec = map.entry(*fp).or_default();
145 /// Queries all trait impls for the given type.
146 pub fn for_self_ty(&self, fp: TyFingerprint) -> impl Iterator<Item = ImplId> + '_ {
149 .flat_map(move |impls| impls.get(&None).into_iter().chain(impls.get(&Some(fp))))
150 .flat_map(|it| it.iter().copied())
153 /// Queries all impls of the given trait.
154 pub fn for_trait(&self, trait_: TraitId) -> impl Iterator<Item = ImplId> + '_ {
158 .flat_map(|map| map.values().flat_map(|v| v.iter().copied()))
161 /// Queries all impls of `trait_` that may apply to `self_ty`.
162 pub fn for_trait_and_self_ty(
165 self_ty: TyFingerprint,
166 ) -> impl Iterator<Item = ImplId> + '_ {
170 .flat_map(move |map| map.get(&None).into_iter().chain(map.get(&Some(self_ty))))
171 .flat_map(|v| v.iter().copied())
174 pub fn all_impls(&self) -> impl Iterator<Item = ImplId> + '_ {
175 self.map.values().flat_map(|map| map.values().flat_map(|v| v.iter().copied()))
179 /// Inherent impls defined in some crate.
181 /// Inherent impls can only be defined in the crate that also defines the self type of the impl
182 /// (note that some primitives are considered to be defined by both libcore and liballoc).
184 /// This makes inherent impl lookup easier than trait impl lookup since we only have to consider a
186 #[derive(Debug, Eq, PartialEq)]
187 pub struct InherentImpls {
188 map: FxHashMap<TyFingerprint, Vec<ImplId>>,
192 pub(crate) fn inherent_impls_in_crate_query(db: &dyn HirDatabase, krate: CrateId) -> Arc<Self> {
193 let mut map: FxHashMap<_, Vec<_>> = FxHashMap::default();
195 let crate_def_map = db.crate_def_map(krate);
196 for (_module_id, module_data) in crate_def_map.modules() {
197 for impl_id in module_data.scope.impls() {
198 let data = db.impl_data(impl_id);
199 if data.target_trait.is_some() {
203 let self_ty = db.impl_self_ty(impl_id);
204 if let Some(fp) = TyFingerprint::for_impl(&self_ty.value) {
205 map.entry(fp).or_default().push(impl_id);
210 Arc::new(Self { map })
213 pub fn for_self_ty(&self, self_ty: &Ty) -> &[ImplId] {
214 match TyFingerprint::for_impl(self_ty) {
215 Some(fp) => self.map.get(&fp).map(|vec| vec.as_ref()).unwrap_or(&[]),
220 pub fn all_impls(&self) -> impl Iterator<Item = ImplId> + '_ {
221 self.map.values().flat_map(|v| v.iter().copied())
228 db: &dyn HirDatabase,
230 ) -> Option<ArrayVec<[CrateId; 2]>> {
231 // Types like slice can have inherent impls in several crates, (core and alloc).
232 // The corresponding impls are marked with lang items, so we can use them to find the required crates.
233 macro_rules! lang_item_crate {
234 ($($name:expr),+ $(,)?) => {{
235 let mut v = ArrayVec::<[LangItemTarget; 2]>::new();
237 v.extend(db.lang_item(cur_crate, $name.into()));
243 let mod_to_crate_ids = |module: ModuleId| Some(std::iter::once(module.krate()).collect());
245 let lang_item_targets = match self.interned(&Interner) {
246 TyKind::Adt(AdtId(def_id), _) => {
247 return mod_to_crate_ids(def_id.module(db.upcast()));
249 TyKind::ForeignType(id) => {
250 return mod_to_crate_ids(
251 from_foreign_def_id(*id).lookup(db.upcast()).module(db.upcast()),
254 TyKind::Scalar(Scalar::Bool) => lang_item_crate!("bool"),
255 TyKind::Scalar(Scalar::Char) => lang_item_crate!("char"),
256 TyKind::Scalar(Scalar::Float(f)) => match f {
257 // There are two lang items: one in libcore (fXX) and one in libstd (fXX_runtime)
258 FloatTy::F32 => lang_item_crate!("f32", "f32_runtime"),
259 FloatTy::F64 => lang_item_crate!("f64", "f64_runtime"),
261 &TyKind::Scalar(Scalar::Int(t)) => {
262 lang_item_crate!(primitive::int_ty_to_string(t))
264 &TyKind::Scalar(Scalar::Uint(t)) => {
265 lang_item_crate!(primitive::uint_ty_to_string(t))
267 TyKind::Str => lang_item_crate!("str_alloc", "str"),
268 TyKind::Slice(_) => lang_item_crate!("slice_alloc", "slice"),
269 TyKind::Raw(Mutability::Not, _) => lang_item_crate!("const_ptr"),
270 TyKind::Raw(Mutability::Mut, _) => lang_item_crate!("mut_ptr"),
272 return self.dyn_trait().and_then(|trait_| {
273 mod_to_crate_ids(GenericDefId::TraitId(trait_).module(db.upcast()))
278 let res = lang_item_targets
280 .filter_map(|it| match it {
281 LangItemTarget::ImplDefId(it) => Some(it),
284 .map(|it| it.lookup(db.upcast()).container.krate())
290 /// Look up the method with the given name, returning the actual autoderefed
291 /// receiver type (but without autoref applied yet).
292 pub(crate) fn lookup_method(
294 db: &dyn HirDatabase,
295 env: Arc<TraitEnvironment>,
297 traits_in_scope: &FxHashSet<TraitId>,
298 visible_from_module: Option<ModuleId>,
300 ) -> Option<(Ty, FunctionId)> {
301 iterate_method_candidates(
309 LookupMode::MethodCall,
311 AssocItemId::FunctionId(f) => Some((ty.clone(), f)),
317 /// Whether we're looking up a dotted method call (like `v.len()`) or a path
318 /// (like `Vec::new`).
319 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
320 pub enum LookupMode {
321 /// Looking up a method call like `v.len()`: We only consider candidates
322 /// that have a `self` parameter, and do autoderef.
324 /// Looking up a path like `Vec::new` or `Vec::default`: We consider all
325 /// candidates including associated constants, but don't do autoderef.
329 // This would be nicer if it just returned an iterator, but that runs into
330 // lifetime problems, because we need to borrow temp `CrateImplDefs`.
331 // FIXME add a context type here?
332 pub fn iterate_method_candidates<T>(
334 db: &dyn HirDatabase,
335 env: Arc<TraitEnvironment>,
337 traits_in_scope: &FxHashSet<TraitId>,
338 visible_from_module: Option<ModuleId>,
341 mut callback: impl FnMut(&Ty, AssocItemId) -> Option<T>,
344 iterate_method_candidates_impl(
354 assert!(slot.is_none());
355 slot = callback(ty, item);
362 fn iterate_method_candidates_impl(
364 db: &dyn HirDatabase,
365 env: Arc<TraitEnvironment>,
367 traits_in_scope: &FxHashSet<TraitId>,
368 visible_from_module: Option<ModuleId>,
371 callback: &mut dyn FnMut(&Ty, AssocItemId) -> bool,
374 LookupMode::MethodCall => {
375 // For method calls, rust first does any number of autoderef, and then one
376 // autoref (i.e. when the method takes &self or &mut self). We just ignore
377 // the autoref currently -- when we find a method matching the given name,
378 // we assume it fits.
380 // Also note that when we've got a receiver like &S, even if the method we
381 // find in the end takes &self, we still do the autoderef step (just as
382 // rustc does an autoderef and then autoref again).
383 let ty = InEnvironment { value: ty.clone(), environment: env.clone() };
385 // We have to be careful about the order we're looking at candidates
386 // in here. Consider the case where we're resolving `x.clone()`
387 // where `x: &Vec<_>`. This resolves to the clone method with self
388 // type `Vec<_>`, *not* `&_`. I.e. we need to consider methods where
389 // the receiver type exactly matches before cases where we have to
390 // do autoref. But in the autoderef steps, the `&_` self type comes
391 // up *before* the `Vec<_>` self type.
393 // On the other hand, we don't want to just pick any by-value method
394 // before any by-autoref method; it's just that we need to consider
395 // the methods by autoderef order of *receiver types*, not *self
398 let deref_chain = autoderef_method_receiver(db, krate, ty);
399 for i in 0..deref_chain.len() {
400 if iterate_method_candidates_with_autoref(
415 LookupMode::Path => {
416 // No autoderef for path lookups
417 iterate_method_candidates_for_self_ty(
430 fn iterate_method_candidates_with_autoref(
431 deref_chain: &[Canonical<Ty>],
432 db: &dyn HirDatabase,
433 env: Arc<TraitEnvironment>,
435 traits_in_scope: &FxHashSet<TraitId>,
436 visible_from_module: Option<ModuleId>,
438 mut callback: &mut dyn FnMut(&Ty, AssocItemId) -> bool,
440 if iterate_method_candidates_by_receiver(
453 let refed = Canonical {
454 kinds: deref_chain[0].kinds.clone(),
455 value: TyKind::Ref(Mutability::Not, deref_chain[0].value.clone()).intern(&Interner),
457 if iterate_method_candidates_by_receiver(
470 let ref_muted = Canonical {
471 kinds: deref_chain[0].kinds.clone(),
472 value: TyKind::Ref(Mutability::Mut, deref_chain[0].value.clone()).intern(&Interner),
474 if iterate_method_candidates_by_receiver(
490 fn iterate_method_candidates_by_receiver(
491 receiver_ty: &Canonical<Ty>,
492 rest_of_deref_chain: &[Canonical<Ty>],
493 db: &dyn HirDatabase,
494 env: Arc<TraitEnvironment>,
496 traits_in_scope: &FxHashSet<TraitId>,
497 visible_from_module: Option<ModuleId>,
499 mut callback: &mut dyn FnMut(&Ty, AssocItemId) -> bool,
501 // We're looking for methods with *receiver* type receiver_ty. These could
502 // be found in any of the derefs of receiver_ty, so we have to go through
504 for self_ty in std::iter::once(receiver_ty).chain(rest_of_deref_chain) {
505 if iterate_inherent_methods(
517 for self_ty in std::iter::once(receiver_ty).chain(rest_of_deref_chain) {
518 if iterate_trait_method_candidates(
534 fn iterate_method_candidates_for_self_ty(
535 self_ty: &Canonical<Ty>,
536 db: &dyn HirDatabase,
537 env: Arc<TraitEnvironment>,
539 traits_in_scope: &FxHashSet<TraitId>,
541 mut callback: &mut dyn FnMut(&Ty, AssocItemId) -> bool,
543 if iterate_inherent_methods(self_ty, db, name, None, krate, None, &mut callback) {
546 iterate_trait_method_candidates(self_ty, db, env, krate, traits_in_scope, name, None, callback)
549 fn iterate_trait_method_candidates(
550 self_ty: &Canonical<Ty>,
551 db: &dyn HirDatabase,
552 env: Arc<TraitEnvironment>,
554 traits_in_scope: &FxHashSet<TraitId>,
556 receiver_ty: Option<&Canonical<Ty>>,
557 callback: &mut dyn FnMut(&Ty, AssocItemId) -> bool,
559 // if ty is `dyn Trait`, the trait doesn't need to be in scope
561 self_ty.value.dyn_trait().into_iter().flat_map(|t| all_super_traits(db.upcast(), t));
562 let env_traits = if let TyKind::Placeholder(_) = self_ty.value.interned(&Interner) {
563 // if we have `T: Trait` in the param env, the trait doesn't need to be in scope
564 env.traits_in_scope_from_clauses(&self_ty.value)
565 .flat_map(|t| all_super_traits(db.upcast(), t))
571 inherent_trait.chain(env_traits.into_iter()).chain(traits_in_scope.iter().copied());
572 'traits: for t in traits {
573 let data = db.trait_data(t);
575 // we'll be lazy about checking whether the type implements the
576 // trait, but if we find out it doesn't, we'll skip the rest of the
578 let mut known_implemented = false;
579 for (_name, item) in data.items.iter() {
580 if !is_valid_candidate(db, name, receiver_ty, *item, self_ty, None) {
583 if !known_implemented {
584 let goal = generic_implements_goal(db, env.clone(), t, self_ty.clone());
585 if db.trait_solve(krate, goal).is_none() {
589 known_implemented = true;
590 if callback(&self_ty.value, *item) {
598 fn iterate_inherent_methods(
599 self_ty: &Canonical<Ty>,
600 db: &dyn HirDatabase,
602 receiver_ty: Option<&Canonical<Ty>>,
604 visible_from_module: Option<ModuleId>,
605 callback: &mut dyn FnMut(&Ty, AssocItemId) -> bool,
607 let def_crates = match self_ty.value.def_crates(db, krate) {
609 None => return false,
611 for krate in def_crates {
612 let impls = db.inherent_impls_in_crate(krate);
614 for &impl_def in impls.for_self_ty(&self_ty.value) {
615 for &item in db.impl_data(impl_def).items.iter() {
616 if !is_valid_candidate(db, name, receiver_ty, item, self_ty, visible_from_module) {
619 // we have to check whether the self type unifies with the type
620 // that the impl is for. If we have a receiver type, this
621 // already happens in `is_valid_candidate` above; if not, we
623 if receiver_ty.is_none() && inherent_impl_substs(db, impl_def, self_ty).is_none() {
624 cov_mark::hit!(impl_self_type_match_without_receiver);
627 if callback(&self_ty.value, item) {
636 /// Returns the self type for the index trait call.
637 pub fn resolve_indexing_op(
638 db: &dyn HirDatabase,
640 env: Arc<TraitEnvironment>,
642 index_trait: TraitId,
643 ) -> Option<Canonical<Ty>> {
644 let ty = InEnvironment { value: ty.clone(), environment: env.clone() };
645 let deref_chain = autoderef_method_receiver(db, krate, ty);
646 for ty in deref_chain {
647 let goal = generic_implements_goal(db, env.clone(), index_trait, ty.clone());
648 if db.trait_solve(krate, goal).is_some() {
655 fn is_valid_candidate(
656 db: &dyn HirDatabase,
658 receiver_ty: Option<&Canonical<Ty>>,
660 self_ty: &Canonical<Ty>,
661 visible_from_module: Option<ModuleId>,
664 AssocItemId::FunctionId(m) => {
665 let data = db.function_data(m);
666 if let Some(name) = name {
667 if &data.name != name {
671 if let Some(receiver_ty) = receiver_ty {
672 if !data.has_self_param {
675 let transformed_receiver_ty = match transform_receiver_ty(db, m, self_ty) {
677 None => return false,
679 if transformed_receiver_ty != receiver_ty.value {
683 if let Some(from_module) = visible_from_module {
684 if !db.fn_visibility(m).is_visible_from(db.upcast(), from_module) {
691 AssocItemId::ConstId(c) => {
692 let data = db.const_data(c);
693 name.map_or(true, |name| data.name.as_ref() == Some(name)) && receiver_ty.is_none()
699 pub(crate) fn inherent_impl_substs(
700 db: &dyn HirDatabase,
702 self_ty: &Canonical<Ty>,
703 ) -> Option<Substitution> {
704 // we create a var for each type parameter of the impl; we need to keep in
705 // mind here that `self_ty` might have vars of its own
706 let vars = Substitution::build_for_def(db, impl_id)
707 .fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty.kinds.len())
709 let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars);
710 let mut kinds = self_ty.kinds.to_vec();
711 kinds.extend(iter::repeat(chalk_ir::TyVariableKind::General).take(vars.len()));
712 let tys = Canonical { kinds: kinds.into(), value: (self_ty_with_vars, self_ty.value.clone()) };
713 let substs = super::infer::unify(&tys);
714 // We only want the substs for the vars we added, not the ones from self_ty.
715 // Also, if any of the vars we added are still in there, we replace them by
716 // Unknown. I think this can only really happen if self_ty contained
717 // Unknown, and in that case we want the result to contain Unknown in those
719 substs.map(|s| fallback_bound_vars(s.suffix(vars.len()), self_ty.kinds.len()))
722 /// This replaces any 'free' Bound vars in `s` (i.e. those with indices past
723 /// num_vars_to_keep) by `TyKind::Unknown`.
724 fn fallback_bound_vars(s: Substitution, num_vars_to_keep: usize) -> Substitution {
727 if let TyKind::BoundVar(bound) = ty.interned(&Interner) {
728 if bound.index >= num_vars_to_keep && bound.debruijn >= binders {
729 TyKind::Unknown.intern(&Interner)
737 DebruijnIndex::INNERMOST,
741 fn transform_receiver_ty(
742 db: &dyn HirDatabase,
743 function_id: FunctionId,
744 self_ty: &Canonical<Ty>,
746 let substs = match function_id.lookup(db.upcast()).container {
747 AssocContainerId::TraitId(_) => Substitution::build_for_def(db, function_id)
748 .push(self_ty.value.clone())
751 AssocContainerId::ImplId(impl_id) => {
752 let impl_substs = inherent_impl_substs(db, impl_id, &self_ty)?;
753 Substitution::build_for_def(db, function_id)
754 .use_parent_substs(&impl_substs)
758 AssocContainerId::ModuleId(_) => unreachable!(),
760 let sig = db.callable_item_signature(function_id.into());
761 Some(sig.value.params()[0].clone().subst_bound_vars(&substs))
764 pub fn implements_trait(
766 db: &dyn HirDatabase,
767 env: Arc<TraitEnvironment>,
771 let goal = generic_implements_goal(db, env, trait_, ty.clone());
772 let solution = db.trait_solve(krate, goal);
777 pub fn implements_trait_unique(
779 db: &dyn HirDatabase,
780 env: Arc<TraitEnvironment>,
784 let goal = generic_implements_goal(db, env, trait_, ty.clone());
785 let solution = db.trait_solve(krate, goal);
787 matches!(solution, Some(crate::traits::Solution::Unique(_)))
790 /// This creates Substs for a trait with the given Self type and type variables
791 /// for all other parameters, to query Chalk with it.
792 fn generic_implements_goal(
793 db: &dyn HirDatabase,
794 env: Arc<TraitEnvironment>,
796 self_ty: Canonical<Ty>,
797 ) -> Canonical<InEnvironment<super::DomainGoal>> {
798 let mut kinds = self_ty.kinds.to_vec();
799 let substs = super::Substitution::build_for_def(db, trait_)
801 .fill_with_bound_vars(DebruijnIndex::INNERMOST, kinds.len())
803 kinds.extend(iter::repeat(chalk_ir::TyVariableKind::General).take(substs.len() - 1));
804 let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_), substitution: substs };
805 let obligation = trait_ref.cast(&Interner);
806 Canonical { kinds: kinds.into(), value: InEnvironment::new(env, obligation) }
809 fn autoderef_method_receiver(
810 db: &dyn HirDatabase,
812 ty: InEnvironment<Canonical<Ty>>,
813 ) -> Vec<Canonical<Ty>> {
814 let mut deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty).collect();
815 // As a last step, we can do array unsizing (that's the only unsizing that rustc does for method receivers!)
816 if let Some(TyKind::Array(parameters)) =
817 deref_chain.last().map(|ty| ty.value.interned(&Interner))
819 let kinds = deref_chain.last().unwrap().kinds.clone();
820 let unsized_ty = TyKind::Slice(parameters.clone()).intern(&Interner);
821 deref_chain.push(Canonical { value: unsized_ty, kinds })