use crate::mir;
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
-use crate::ty::sty::{ClosureSubsts, GeneratorSubsts};
+use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt};
use rustc_hir::def_id::DefId;
/// An entity in the Rust type system, which can be one of
/// several kinds (types, lifetimes, and consts).
-/// To reduce memory usage, a `GenericArg` is a interned pointer,
+/// To reduce memory usage, a `GenericArg` is an interned pointer,
/// with the lowest 2 bits being reserved for a tag to
/// indicate the type (`Ty`, `Region`, or `Const`) it points to.
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
GeneratorSubsts { substs: self }
}
- /// Creates a `InternalSubsts` that maps each generic parameter to itself.
+ /// Interpret these substitutions as the substitutions of an inline const.
+ /// Inline const substitutions have a particular structure controlled by the
+ /// compiler that encodes information like the inferred type;
+ /// see `ty::InlineConstSubsts` struct for more comments.
+ pub fn as_inline_const(&'tcx self) -> InlineConstSubsts<'tcx> {
+ InlineConstSubsts { substs: self }
+ }
+
+ /// Creates an `InternalSubsts` that maps each generic parameter to itself.
pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
Self::for_item(tcx, def_id, |param, _| tcx.mk_param_from_def(param))
}
- /// Creates a `InternalSubsts` for generic parameter definitions,
+ /// Creates an `InternalSubsts` for generic parameter definitions,
/// by calling closures to obtain each kind.
/// The closures get to observe the `InternalSubsts` as they're
/// being built, which can be used to correctly
})
}
- fn fill_item<F>(
+ pub fn fill_item<F>(
substs: &mut SmallVec<[GenericArg<'tcx>; 8]>,
tcx: TyCtxt<'tcx>,
defs: &ty::Generics,
Self::fill_single(substs, defs, mk_kind)
}
- fn fill_single<F>(
+ pub fn fill_single<F>(
substs: &mut SmallVec<[GenericArg<'tcx>; 8]>,
defs: &ty::Generics,
mk_kind: &mut F,
}
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
- if !t.needs_subst() {
+ if !t.potentially_needs_subst() {
return t;
}
}
fn fold_const(&mut self, c: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
- if !c.needs_subst() {
- return c;
- }
-
if let ty::ConstKind::Param(p) = c.val {
self.const_for_param(p, c)
} else {