rustc_type_ir/lift.rs
1/// A trait implemented for all `X<'a>` types that can be safely and
2/// efficiently converted to `X<'tcx>` as long as they are part of the
3/// provided `TyCtxt<'tcx>`.
4/// This can be done, for example, for `Ty<'tcx>` or `GenericArgsRef<'tcx>`
5/// by looking them up in their respective interners.
6///
7/// However, this is still not the best implementation as it does
8/// need to compare the components, even for interned values.
9/// It would be more efficient if `TypedArena` provided a way to
10/// determine whether the address is in the allocated range.
11///
12/// `None` is returned if the value or one of the components is not part
13/// of the provided context.
14/// For `Ty`, `None` can be returned if either the type interner doesn't
15/// contain the `TyKind` key or if the address of the interned
16/// pointer differs. The latter case is possible if a primitive type,
17/// e.g., `()` or `u8`, was interned in a different context.
18pub trait Lift<I>: std::fmt::Debug {
19 type Lifted: std::fmt::Debug;
20 fn lift_to_interner(self, cx: I) -> Option<Self::Lifted>;
21}