summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/ty
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_middle/src/ty')
-rw-r--r--compiler/rustc_middle/src/ty/abstract_const.rs8
-rw-r--r--compiler/rustc_middle/src/ty/adt.rs18
-rw-r--r--compiler/rustc_middle/src/ty/assoc.rs12
-rw-r--r--compiler/rustc_middle/src/ty/binding.rs2
-rw-r--r--compiler/rustc_middle/src/ty/closure.rs31
-rw-r--r--compiler/rustc_middle/src/ty/codec.rs12
-rw-r--r--compiler/rustc_middle/src/ty/consts.rs30
-rw-r--r--compiler/rustc_middle/src/ty/consts/int.rs4
-rw-r--r--compiler/rustc_middle/src/ty/consts/kind.rs16
-rw-r--r--compiler/rustc_middle/src/ty/consts/valtree.rs2
-rw-r--r--compiler/rustc_middle/src/ty/context.rs254
-rw-r--r--compiler/rustc_middle/src/ty/diagnostics.rs39
-rw-r--r--compiler/rustc_middle/src/ty/error.rs17
-rw-r--r--compiler/rustc_middle/src/ty/fast_reject.rs133
-rw-r--r--compiler/rustc_middle/src/ty/flags.rs62
-rw-r--r--compiler/rustc_middle/src/ty/generic_args.rs (renamed from compiler/rustc_middle/src/ty/subst.rs)288
-rw-r--r--compiler/rustc_middle/src/ty/generics.rs44
-rw-r--r--compiler/rustc_middle/src/ty/impls_ty.rs2
-rw-r--r--compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs24
-rw-r--r--compiler/rustc_middle/src/ty/inhabitedness/mod.rs10
-rw-r--r--compiler/rustc_middle/src/ty/instance.rs174
-rw-r--r--compiler/rustc_middle/src/ty/layout.rs44
-rw-r--r--compiler/rustc_middle/src/ty/list.rs11
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs290
-rw-r--r--compiler/rustc_middle/src/ty/normalize_erasing_regions.rs22
-rw-r--r--compiler/rustc_middle/src/ty/opaque_types.rs44
-rw-r--r--compiler/rustc_middle/src/ty/parameterized.rs1
-rw-r--r--compiler/rustc_middle/src/ty/print/mod.rs46
-rw-r--r--compiler/rustc_middle/src/ty/print/pretty.rs216
-rw-r--r--compiler/rustc_middle/src/ty/relate.rs166
-rw-r--r--compiler/rustc_middle/src/ty/rvalue_scopes.rs4
-rw-r--r--compiler/rustc_middle/src/ty/structural_impls.rs244
-rw-r--r--compiler/rustc_middle/src/ty/sty.rs438
-rw-r--r--compiler/rustc_middle/src/ty/trait_def.rs2
-rw-r--r--compiler/rustc_middle/src/ty/typeck_results.rs43
-rw-r--r--compiler/rustc_middle/src/ty/util.rs113
-rw-r--r--compiler/rustc_middle/src/ty/visit.rs8
-rw-r--r--compiler/rustc_middle/src/ty/vtable.rs4
-rw-r--r--compiler/rustc_middle/src/ty/walk.rs28
39 files changed, 1530 insertions, 1376 deletions
diff --git a/compiler/rustc_middle/src/ty/abstract_const.rs b/compiler/rustc_middle/src/ty/abstract_const.rs
index ffee7ba28..cdd835149 100644
--- a/compiler/rustc_middle/src/ty/abstract_const.rs
+++ b/compiler/rustc_middle/src/ty/abstract_const.rs
@@ -27,9 +27,7 @@ impl From<ErrorGuaranteed> for NotConstEvaluatable {
}
}
-TrivialTypeTraversalAndLiftImpls! {
- NotConstEvaluatable,
-}
+TrivialTypeTraversalAndLiftImpls! { NotConstEvaluatable }
pub type BoundAbstractConst<'tcx> = Result<Option<EarlyBinder<ty::Const<'tcx>>>, ErrorGuaranteed>;
@@ -55,8 +53,8 @@ impl<'tcx> TyCtxt<'tcx> {
ty::ConstKind::Unevaluated(uv) => match self.tcx.thir_abstract_const(uv.def) {
Err(e) => ty::Const::new_error(self.tcx, e, c.ty()),
Ok(Some(bac)) => {
- let substs = self.tcx.erase_regions(uv.substs);
- let bac = bac.subst(self.tcx, substs);
+ let args = self.tcx.erase_regions(uv.args);
+ let bac = bac.instantiate(self.tcx, args);
return bac.fold_with(self);
}
Ok(None) => c,
diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs
index e067d2a98..b4c6e0d97 100644
--- a/compiler/rustc_middle/src/ty/adt.rs
+++ b/compiler/rustc_middle/src/ty/adt.rs
@@ -448,7 +448,7 @@ impl<'tcx> AdtDef<'tcx> {
Res::Def(DefKind::Ctor(..), cid) => self.variant_with_ctor_id(cid),
Res::Def(DefKind::Struct, _)
| Res::Def(DefKind::Union, _)
- | Res::Def(DefKind::TyAlias, _)
+ | Res::Def(DefKind::TyAlias { .. }, _)
| Res::Def(DefKind::AssocTy, _)
| Res::SelfTyParam { .. }
| Res::SelfTyAlias { .. }
@@ -562,18 +562,10 @@ impl<'tcx> AdtDef<'tcx> {
tcx.adt_destructor(self.did())
}
- /// Returns a list of types such that `Self: Sized` if and only
- /// if that type is `Sized`, or `TyErr` if this type is recursive.
- ///
- /// Oddly enough, checking that the sized-constraint is `Sized` is
- /// actually more expressive than checking all members:
- /// the `Sized` trait is inductive, so an associated type that references
- /// `Self` would prevent its containing ADT from being `Sized`.
- ///
- /// Due to normalization being eager, this applies even if
- /// the associated type is behind a pointer (e.g., issue #31299).
- pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> ty::EarlyBinder<&'tcx [Ty<'tcx>]> {
- ty::EarlyBinder::bind(tcx.adt_sized_constraint(self.did()))
+ /// Returns a list of types such that `Self: Sized` if and only if that
+ /// type is `Sized`, or `ty::Error` if this type has a recursive layout.
+ pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> ty::EarlyBinder<&'tcx ty::List<Ty<'tcx>>> {
+ tcx.adt_sized_constraint(self.did())
}
}
diff --git a/compiler/rustc_middle/src/ty/assoc.rs b/compiler/rustc_middle/src/ty/assoc.rs
index cce609c26..f77a8c671 100644
--- a/compiler/rustc_middle/src/ty/assoc.rs
+++ b/compiler/rustc_middle/src/ty/assoc.rs
@@ -84,14 +84,22 @@ impl AssocItem {
// late-bound regions, and we don't want method signatures to show up
// `as for<'r> fn(&'r MyType)`. Pretty-printing handles late-bound
// regions just fine, showing `fn(&MyType)`.
- tcx.fn_sig(self.def_id).subst_identity().skip_binder().to_string()
+ tcx.fn_sig(self.def_id).instantiate_identity().skip_binder().to_string()
}
ty::AssocKind::Type => format!("type {};", self.name),
ty::AssocKind::Const => {
- format!("const {}: {:?};", self.name, tcx.type_of(self.def_id).subst_identity())
+ format!(
+ "const {}: {:?};",
+ self.name,
+ tcx.type_of(self.def_id).instantiate_identity()
+ )
}
}
}
+
+ pub fn is_impl_trait_in_trait(&self) -> bool {
+ self.opt_rpitit_info.is_some()
+ }
}
#[derive(Copy, Clone, PartialEq, Debug, HashStable, Eq, Hash, Encodable, Decodable)]
diff --git a/compiler/rustc_middle/src/ty/binding.rs b/compiler/rustc_middle/src/ty/binding.rs
index a5b05a4f9..2fec8ac90 100644
--- a/compiler/rustc_middle/src/ty/binding.rs
+++ b/compiler/rustc_middle/src/ty/binding.rs
@@ -6,7 +6,7 @@ pub enum BindingMode {
BindByValue(Mutability),
}
-TrivialTypeTraversalAndLiftImpls! { BindingMode, }
+TrivialTypeTraversalAndLiftImpls! { BindingMode }
impl BindingMode {
pub fn convert(BindingAnnotation(by_ref, mutbl): BindingAnnotation) -> BindingMode {
diff --git a/compiler/rustc_middle/src/ty/closure.rs b/compiler/rustc_middle/src/ty/closure.rs
index bc9273745..74bdd07a1 100644
--- a/compiler/rustc_middle/src/ty/closure.rs
+++ b/compiler/rustc_middle/src/ty/closure.rs
@@ -6,9 +6,11 @@ use crate::{mir, ty};
use std::fmt::Write;
use crate::query::Providers;
-use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
+use rustc_data_structures::fx::FxIndexMap;
+use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{self as hir, LangItem};
+use rustc_span::def_id::LocalDefIdMap;
use rustc_span::symbol::Ident;
use rustc_span::{Span, Symbol};
@@ -56,12 +58,9 @@ pub enum UpvarCapture {
ByRef(BorrowKind),
}
-pub type UpvarListMap = FxHashMap<DefId, FxIndexMap<hir::HirId, UpvarId>>;
-pub type UpvarCaptureMap = FxHashMap<UpvarId, UpvarCapture>;
-
/// Given the closure DefId this map provides a map of root variables to minimum
/// set of `CapturedPlace`s that need to be tracked to support all captures of that closure.
-pub type MinCaptureInformationMap<'tcx> = FxHashMap<LocalDefId, RootVariableMinCaptureList<'tcx>>;
+pub type MinCaptureInformationMap<'tcx> = LocalDefIdMap<RootVariableMinCaptureList<'tcx>>;
/// Part of `MinCaptureInformationMap`; Maps a root variable to the list of `CapturedPlace`.
/// Used to track the minimum set of `Place`s that need to be captured to support all
@@ -91,10 +90,18 @@ pub enum ClosureKind {
FnOnce,
}
-impl<'tcx> ClosureKind {
+impl ClosureKind {
/// This is the initial value used when doing upvar inference.
pub const LATTICE_BOTTOM: ClosureKind = ClosureKind::Fn;
+ pub const fn as_str(self) -> &'static str {
+ match self {
+ ClosureKind::Fn => "Fn",
+ ClosureKind::FnMut => "FnMut",
+ ClosureKind::FnOnce => "FnOnce",
+ }
+ }
+
/// Returns `true` if a type that impls this closure kind
/// must also implement `other`.
pub fn extends(self, other: ty::ClosureKind) -> bool {
@@ -117,7 +124,7 @@ impl<'tcx> ClosureKind {
/// Returns the representative scalar type for this closure kind.
/// See `Ty::to_opt_closure_kind` for more details.
- pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
+ pub fn to_ty<'tcx>(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match self {
ClosureKind::Fn => tcx.types.i8,
ClosureKind::FnMut => tcx.types.i16,
@@ -126,6 +133,12 @@ impl<'tcx> ClosureKind {
}
}
+impl IntoDiagnosticArg for ClosureKind {
+ fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
+ DiagnosticArgValue::Str(self.as_str().into())
+ }
+}
+
/// A composite describing a `Place` that is captured by a closure.
#[derive(PartialEq, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
#[derive(TypeFoldable, TypeVisitable)]
@@ -176,6 +189,8 @@ impl<'tcx> CapturedPlace<'tcx> {
// Ignore derefs for now, as they are likely caused by
// autoderefs that don't appear in the original code.
HirProjectionKind::Deref => {}
+ // Just change the type to the hidden type, so we can actually project.
+ HirProjectionKind::OpaqueCast => {}
proj => bug!("Unexpected projection {:?} in captured place", proj),
}
ty = proj.ty;
@@ -350,7 +365,7 @@ pub fn place_to_string_for_capture<'tcx>(tcx: TyCtxt<'tcx>, place: &HirPlace<'tc
for (i, proj) in place.projections.iter().enumerate() {
match proj.kind {
HirProjectionKind::Deref => {
- curr_string = format!("*{}", curr_string);
+ curr_string = format!("*{curr_string}");
}
HirProjectionKind::Field(idx, variant) => match place.ty_before_projection(i).kind() {
ty::Adt(def, ..) => {
diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs
index 6adbb44a1..7c05deae9 100644
--- a/compiler/rustc_middle/src/ty/codec.rs
+++ b/compiler/rustc_middle/src/ty/codec.rs
@@ -13,7 +13,7 @@ use crate::mir::{
interpret::{AllocId, ConstAllocation},
};
use crate::traits;
-use crate::ty::subst::SubstsRef;
+use crate::ty::GenericArgsRef;
use crate::ty::{self, AdtDef, Ty};
use rustc_data_structures::fx::FxHashMap;
use rustc_middle::ty::TyCtxt;
@@ -168,7 +168,6 @@ impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::ParamEnv<'tcx> {
fn encode(&self, e: &mut E) {
self.caller_bounds().encode(e);
self.reveal().encode(e);
- self.constness().encode(e);
}
}
@@ -254,12 +253,12 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Clause<'tcx> {
}
}
-impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for SubstsRef<'tcx> {
+impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for GenericArgsRef<'tcx> {
fn decode(decoder: &mut D) -> Self {
let len = decoder.read_usize();
let tcx = decoder.interner();
- tcx.mk_substs_from_iter(
- (0..len).map::<ty::subst::GenericArg<'tcx>, _>(|_| Decodable::decode(decoder)),
+ tcx.mk_args_from_iter(
+ (0..len).map::<ty::GenericArg<'tcx>, _>(|_| Decodable::decode(decoder)),
)
}
}
@@ -306,8 +305,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::ParamEnv<'tcx> {
fn decode(d: &mut D) -> Self {
let caller_bounds = Decodable::decode(d);
let reveal = Decodable::decode(d);
- let constness = Decodable::decode(d);
- ty::ParamEnv::new(caller_bounds, reveal, constness)
+ ty::ParamEnv::new(caller_bounds, reveal)
}
}
diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs
index 1cbfe99f8..cce10417e 100644
--- a/compiler/rustc_middle/src/ty/consts.rs
+++ b/compiler/rustc_middle/src/ty/consts.rs
@@ -1,6 +1,6 @@
use crate::middle::resolve_bound_vars as rbv;
use crate::mir::interpret::{AllocId, ConstValue, LitToConstInput, Scalar};
-use crate::ty::{self, InternalSubsts, ParamEnv, ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt};
+use crate::ty::{self, GenericArgs, ParamEnv, ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt};
use rustc_data_structures::intern::Interned;
use rustc_error_messages::MultiSpan;
use rustc_hir as hir;
@@ -171,7 +171,7 @@ impl<'tcx> Const<'tcx> {
tcx,
ty::UnevaluatedConst {
def: def.to_def_id(),
- substs: InternalSubsts::identity_for_item(tcx, def.to_def_id()),
+ args: GenericArgs::identity_for_item(tcx, def.to_def_id()),
},
ty,
),
@@ -212,7 +212,7 @@ impl<'tcx> Const<'tcx> {
Err(e) => {
tcx.sess.delay_span_bug(
expr.span,
- format!("Const::from_anon_const: couldn't lit_to_const {:?}", e),
+ format!("Const::from_anon_const: couldn't lit_to_const {e:?}"),
);
}
}
@@ -225,7 +225,7 @@ impl<'tcx> Const<'tcx> {
)) => {
// Use the type from the param's definition, since we can resolve it,
// not the expected parameter type from WithOptConstParam.
- let param_ty = tcx.type_of(def_id).subst_identity();
+ let param_ty = tcx.type_of(def_id).instantiate_identity();
match tcx.named_bound_var(expr.hir_id) {
Some(rbv::ResolvedArg::EarlyBound(_)) => {
// Find the name and index of the const parameter by indexing the generics of
@@ -267,7 +267,7 @@ impl<'tcx> Const<'tcx> {
pub fn from_bits(tcx: TyCtxt<'tcx>, bits: u128, ty: ParamEnvAnd<'tcx, Ty<'tcx>>) -> Self {
let size = tcx
.layout_of(ty)
- .unwrap_or_else(|e| panic!("could not compute layout for {:?}: {:?}", ty, e))
+ .unwrap_or_else(|e| panic!("could not compute layout for {ty:?}: {e:?}"))
.size;
ty::Const::new_value(
tcx,
@@ -294,6 +294,14 @@ impl<'tcx> Const<'tcx> {
Self::from_bits(tcx, n as u128, ParamEnv::empty().and(tcx.types.usize))
}
+ /// Attempts to convert to a `ValTree`
+ pub fn try_to_valtree(self) -> Option<ty::ValTree<'tcx>> {
+ match self.kind() {
+ ty::ConstKind::Value(valtree) => Some(valtree),
+ _ => None,
+ }
+ }
+
#[inline]
/// Attempts to evaluate the given constant to bits. Can fail to evaluate in the presence of
/// generics (or erroneous code) or if the value can't be represented as bits (e.g. because it
@@ -406,14 +414,14 @@ impl<'tcx> Const<'tcx> {
// any region variables.
// HACK(eddyb) when the query key would contain inference variables,
- // attempt using identity substs and `ParamEnv` instead, that will succeed
+ // attempt using identity args and `ParamEnv` instead, that will succeed
// when the expression doesn't depend on any parameters.
// FIXME(eddyb, skinny121) pass `InferCtxt` into here when it's available, so that
// we can call `infcx.const_eval_resolve` which handles inference variables.
let param_env_and = if (param_env, unevaluated).has_non_region_infer() {
tcx.param_env(unevaluated.def).and(ty::UnevaluatedConst {
def: unevaluated.def,
- substs: InternalSubsts::identity_for_item(tcx, unevaluated.def),
+ args: GenericArgs::identity_for_item(tcx, unevaluated.def),
})
} else {
tcx.erase_regions(param_env)
@@ -430,8 +438,8 @@ impl<'tcx> Const<'tcx> {
EvalMode::Typeck => {
match tcx.const_eval_resolve_for_typeck(param_env, unevaluated, None) {
// NOTE(eddyb) `val` contains no lifetimes/types/consts,
- // and we use the original type, so nothing from `substs`
- // (which may be identity substs, see above),
+ // and we use the original type, so nothing from `args`
+ // (which may be identity args, see above),
// can leak through `val` into the const we return.
Ok(val) => Some(Ok(EvalResult::ValTree(val?))),
Err(ErrorHandled::TooGeneric) => None,
@@ -441,8 +449,8 @@ impl<'tcx> Const<'tcx> {
EvalMode::Mir => {
match tcx.const_eval_resolve(param_env, unevaluated.expand(), None) {
// NOTE(eddyb) `val` contains no lifetimes/types/consts,
- // and we use the original type, so nothing from `substs`
- // (which may be identity substs, see above),
+ // and we use the original type, so nothing from `args`
+ // (which may be identity args, see above),
// can leak through `val` into the const we return.
Ok(val) => Some(Ok(EvalResult::ConstVal(val))),
Err(ErrorHandled::TooGeneric) => None,
diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs
index 1e43fab45..b16163edf 100644
--- a/compiler/rustc_middle/src/ty/consts/int.rs
+++ b/compiler/rustc_middle/src/ty/consts/int.rs
@@ -418,7 +418,7 @@ impl TryFrom<ScalarInt> for char {
#[inline]
fn try_from(int: ScalarInt) -> Result<Self, Self::Error> {
- let Ok(bits) = int.to_bits(Size::from_bytes(std::mem::size_of::<char>())) else {
+ let Ok(bits) = int.to_bits(Size::from_bytes(std::mem::size_of::<char>())) else {
return Err(CharTryFromScalarInt);
};
match char::from_u32(bits.try_into().unwrap()) {
@@ -463,7 +463,7 @@ impl TryFrom<ScalarInt> for Double {
impl fmt::Debug for ScalarInt {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Dispatch to LowerHex below.
- write!(f, "0x{:x}", self)
+ write!(f, "0x{self:x}")
}
}
diff --git a/compiler/rustc_middle/src/ty/consts/kind.rs b/compiler/rustc_middle/src/ty/consts/kind.rs
index a6bf74911..db4a15fbe 100644
--- a/compiler/rustc_middle/src/ty/consts/kind.rs
+++ b/compiler/rustc_middle/src/ty/consts/kind.rs
@@ -1,41 +1,41 @@
use super::Const;
use crate::mir;
use crate::ty::abstract_const::CastKind;
-use crate::ty::subst::SubstsRef;
+use crate::ty::GenericArgsRef;
use crate::ty::{self, List, Ty};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::def_id::DefId;
use rustc_macros::HashStable;
/// An unevaluated (potentially generic) constant used in the type-system.
-#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
+#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Lift)]
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable)]
pub struct UnevaluatedConst<'tcx> {
pub def: DefId,
- pub substs: SubstsRef<'tcx>,
+ pub args: GenericArgsRef<'tcx>,
}
impl rustc_errors::IntoDiagnosticArg for UnevaluatedConst<'_> {
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
- format!("{:?}", self).into_diagnostic_arg()
+ format!("{self:?}").into_diagnostic_arg()
}
}
impl<'tcx> UnevaluatedConst<'tcx> {
#[inline]
pub fn expand(self) -> mir::UnevaluatedConst<'tcx> {
- mir::UnevaluatedConst { def: self.def, substs: self.substs, promoted: None }
+ mir::UnevaluatedConst { def: self.def, args: self.args, promoted: None }
}
}
impl<'tcx> UnevaluatedConst<'tcx> {
#[inline]
- pub fn new(def: DefId, substs: SubstsRef<'tcx>) -> UnevaluatedConst<'tcx> {
- UnevaluatedConst { def, substs }
+ pub fn new(def: DefId, args: GenericArgsRef<'tcx>) -> UnevaluatedConst<'tcx> {
+ UnevaluatedConst { def, args }
}
}
-#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
+#[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
#[derive(HashStable, TyEncodable, TyDecodable, TypeVisitable, TypeFoldable)]
pub enum Expr<'tcx> {
Binop(mir::BinOp, Const<'tcx>, Const<'tcx>),
diff --git a/compiler/rustc_middle/src/ty/consts/valtree.rs b/compiler/rustc_middle/src/ty/consts/valtree.rs
index 8b96864dd..fb7bf78ba 100644
--- a/compiler/rustc_middle/src/ty/consts/valtree.rs
+++ b/compiler/rustc_middle/src/ty/consts/valtree.rs
@@ -24,7 +24,7 @@ pub enum ValTree<'tcx> {
Leaf(ScalarInt),
//SliceOrStr(ValSlice<'tcx>),
- // dont use SliceOrStr for now
+ // don't use SliceOrStr for now
/// The fields of any kind of aggregate. Structs, tuples and arrays are represented by
/// listing their fields' values in order.
///
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index 035e978f6..be839e03c 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -30,7 +30,7 @@ use crate::ty::{
Predicate, PredicateKind, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind,
TyVid, TypeAndMut, Visibility,
};
-use crate::ty::{GenericArg, InternalSubsts, SubstsRef};
+use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
use rustc_ast::{self as ast, attr};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -50,9 +50,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::definitions::Definitions;
use rustc_hir::intravisit::Visitor;
use rustc_hir::lang_items::LangItem;
-use rustc_hir::{
- Constness, ExprKind, HirId, ImplItemKind, ItemKind, Node, TraitCandidate, TraitItemKind,
-};
+use rustc_hir::{Constness, HirId, Node, TraitCandidate};
use rustc_index::IndexVec;
use rustc_macros::HashStable;
use rustc_query_system::dep_graph::DepNodeIndex;
@@ -61,8 +59,7 @@ use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
use rustc_session::config::CrateType;
use rustc_session::cstore::{CrateStoreDyn, Untracked};
use rustc_session::lint::Lint;
-use rustc_session::Limit;
-use rustc_session::Session;
+use rustc_session::{Limit, MetadataKind, Session};
use rustc_span::def_id::{DefPathHash, StableCrateId};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
@@ -84,7 +81,7 @@ use std::ops::{Bound, Deref};
#[allow(rustc::usage_of_ty_tykind)]
impl<'tcx> Interner for TyCtxt<'tcx> {
type AdtDef = ty::AdtDef<'tcx>;
- type SubstsRef = ty::SubstsRef<'tcx>;
+ type GenericArgsRef = ty::GenericArgsRef<'tcx>;
type DefId = DefId;
type Binder<T> = Binder<'tcx, T>;
type Ty = Ty<'tcx>;
@@ -142,7 +139,7 @@ pub struct CtxtInterners<'tcx> {
// they're accessed quite often.
type_: InternedSet<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>,
const_lists: InternedSet<'tcx, List<ty::Const<'tcx>>>,
- substs: InternedSet<'tcx, InternalSubsts<'tcx>>,
+ args: InternedSet<'tcx, GenericArgs<'tcx>>,
type_lists: InternedSet<'tcx, List<Ty<'tcx>>>,
canonical_var_infos: InternedSet<'tcx, List<CanonicalVarInfo<'tcx>>>,
region: InternedSet<'tcx, RegionKind<'tcx>>,
@@ -167,7 +164,7 @@ impl<'tcx> CtxtInterners<'tcx> {
arena,
type_: Default::default(),
const_lists: Default::default(),
- substs: Default::default(),
+ args: Default::default(),
type_lists: Default::default(),
region: Default::default(),
poly_existential_predicates: Default::default(),
@@ -529,6 +526,13 @@ pub struct GlobalCtxt<'tcx> {
interners: CtxtInterners<'tcx>,
pub sess: &'tcx Session,
+ crate_types: Vec<CrateType>,
+ /// The `stable_crate_id` is constructed out of the crate name and all the
+ /// `-C metadata` arguments passed to the compiler. Its value forms a unique
+ /// global identifier for the crate. It is used to allow multiple crates
+ /// with the same name to coexist. See the
+ /// `rustc_symbol_mangling` crate for more information.
+ stable_crate_id: StableCrateId,
/// This only ever stores a `LintStore` but we don't want a dependency on that type here.
///
@@ -569,6 +573,7 @@ pub struct GlobalCtxt<'tcx> {
/// Caches the results of goal evaluation in the new solver.
pub new_solver_evaluation_cache: solve::EvaluationCache<'tcx>,
+ pub new_solver_coherence_evaluation_cache: solve::EvaluationCache<'tcx>,
/// Data layout specification for the current target.
pub data_layout: TargetDataLayout,
@@ -680,12 +685,16 @@ impl<'tcx> TyCtxt<'tcx> {
value.lift_to_tcx(self)
}
- /// Creates a type context and call the closure with a `TyCtxt` reference
- /// to the context. The closure enforces that the type context and any interned
- /// value (types, substs, etc.) can only be used while `ty::tls` has a valid
- /// reference to the context, to allow formatting values that need it.
+ /// Creates a type context. To use the context call `fn enter` which
+ /// provides a `TyCtxt`.
+ ///
+ /// By only providing the `TyCtxt` inside of the closure we enforce that the type
+ /// context and any interned alue (types, args, etc.) can only be used while `ty::tls`
+ /// has a valid reference to the context, to allow formatting values that need it.
pub fn create_global_ctxt(
s: &'tcx Session,
+ crate_types: Vec<CrateType>,
+ stable_crate_id: StableCrateId,
lint_store: Lrc<dyn Any + sync::DynSend + sync::DynSync>,
arena: &'tcx WorkerLocal<Arena<'tcx>>,
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
@@ -704,6 +713,8 @@ impl<'tcx> TyCtxt<'tcx> {
GlobalCtxt {
sess: s,
+ crate_types,
+ stable_crate_id,
lint_store,
arena,
hir_arena,
@@ -721,6 +732,7 @@ impl<'tcx> TyCtxt<'tcx> {
selection_cache: Default::default(),
evaluation_cache: Default::default(),
new_solver_evaluation_cache: Default::default(),
+ new_solver_coherence_evaluation_cache: Default::default(),
data_layout,
alloc_map: Lock::new(interpret::AllocMap::new()),
}
@@ -799,9 +811,46 @@ impl<'tcx> TyCtxt<'tcx> {
}
#[inline]
+ pub fn crate_types(self) -> &'tcx [CrateType] {
+ &self.crate_types
+ }
+
+ pub fn metadata_kind(self) -> MetadataKind {
+ self.crate_types()
+ .iter()
+ .map(|ty| match *ty {
+ CrateType::Executable | CrateType::Staticlib | CrateType::Cdylib => {
+ MetadataKind::None
+ }
+ CrateType::Rlib => MetadataKind::Uncompressed,
+ CrateType::Dylib | CrateType::ProcMacro => MetadataKind::Compressed,
+ })
+ .max()
+ .unwrap_or(MetadataKind::None)
+ }
+
+ pub fn needs_metadata(self) -> bool {
+ self.metadata_kind() != MetadataKind::None
+ }
+
+ pub fn needs_crate_hash(self) -> bool {
+ // Why is the crate hash needed for these configurations?
+ // - debug_assertions: for the "fingerprint the result" check in
+ // `rustc_query_system::query::plumbing::execute_job`.
+ // - incremental: for query lookups.
+ // - needs_metadata: for putting into crate metadata.
+ // - instrument_coverage: for putting into coverage data (see
+ // `hash_mir_source`).
+ cfg!(debug_assertions)
+ || self.sess.opts.incremental.is_some()
+ || self.needs_metadata()
+ || self.sess.instrument_coverage()
+ }
+
+ #[inline]
pub fn stable_crate_id(self, crate_num: CrateNum) -> StableCrateId {
if crate_num == LOCAL_CRATE {
- self.sess.local_stable_crate_id()
+ self.stable_crate_id
} else {
self.cstore_untracked().stable_crate_id(crate_num)
}
@@ -811,7 +860,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// that the crate in question has already been loaded by the CrateStore.
#[inline]
pub fn stable_crate_id_to_crate_num(self, stable_crate_id: StableCrateId) -> CrateNum {
- if stable_crate_id == self.sess.local_stable_crate_id() {
+ if stable_crate_id == self.stable_crate_id(LOCAL_CRATE) {
LOCAL_CRATE
} else {
self.cstore_untracked().stable_crate_id_to_crate_num(stable_crate_id)
@@ -828,7 +877,7 @@ impl<'tcx> TyCtxt<'tcx> {
// If this is a DefPathHash from the local crate, we can look up the
// DefId in the tcx's `Definitions`.
- if stable_crate_id == self.sess.local_stable_crate_id() {
+ if stable_crate_id == self.stable_crate_id(LOCAL_CRATE) {
self.untracked.definitions.read().local_def_path_hash_to_def_id(hash, err).to_def_id()
} else {
// If this is a DefPathHash from an upstream crate, let the CrateStore map
@@ -845,7 +894,7 @@ impl<'tcx> TyCtxt<'tcx> {
// statements within the query system and we'd run into endless
// recursion otherwise.
let (crate_name, stable_crate_id) = if def_id.is_local() {
- (self.crate_name(LOCAL_CRATE), self.sess.local_stable_crate_id())
+ (self.crate_name(LOCAL_CRATE), self.stable_crate_id(LOCAL_CRATE))
} else {
let cstore = &*self.cstore_untracked();
(cstore.crate_name(def_id.krate), cstore.stable_crate_id(def_id.krate))
@@ -984,7 +1033,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn local_crate_exports_generics(self) -> bool {
debug_assert!(self.sess.opts.share_generics());
- self.sess.crate_types().iter().any(|crate_type| {
+ self.crate_types().iter().any(|crate_type| {
match crate_type {
CrateType::Executable
| CrateType::Staticlib
@@ -1036,7 +1085,9 @@ impl<'tcx> TyCtxt<'tcx> {
scope_def_id: LocalDefId,
) -> Vec<&'tcx hir::Ty<'tcx>> {
let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id);
- let Some(hir::FnDecl { output: hir::FnRetTy::Return(hir_output), .. }) = self.hir().fn_decl_by_hir_id(hir_id) else {
+ let Some(hir::FnDecl { output: hir::FnRetTy::Return(hir_output), .. }) =
+ self.hir().fn_decl_by_hir_id(hir_id)
+ else {
return vec![];
};
@@ -1058,7 +1109,7 @@ impl<'tcx> TyCtxt<'tcx> {
if let Some(hir::FnDecl { output: hir::FnRetTy::Return(hir_output), .. }) = self.hir().fn_decl_by_hir_id(hir_id)
&& let hir::TyKind::Path(hir::QPath::Resolved(
None,
- hir::Path { res: hir::def::Res::Def(DefKind::TyAlias, def_id), .. }, )) = hir_output.kind
+ hir::Path { res: hir::def::Res::Def(DefKind::TyAlias { .. }, def_id), .. }, )) = hir_output.kind
&& let Some(local_id) = def_id.as_local()
&& let Some(alias_ty) = self.hir().get_by_def_id(local_id).alias_ty() // it is type alias
&& let Some(alias_generics) = self.hir().get_by_def_id(local_id).generics()
@@ -1071,31 +1122,6 @@ impl<'tcx> TyCtxt<'tcx> {
return None;
}
- pub fn return_type_impl_trait(self, scope_def_id: LocalDefId) -> Option<(Ty<'tcx>, Span)> {
- // `type_of()` will fail on these (#55796, #86483), so only allow `fn`s or closures.
- match self.hir().get_by_def_id(scope_def_id) {
- Node::Item(&hir::Item { kind: ItemKind::Fn(..), .. }) => {}
- Node::TraitItem(&hir::TraitItem { kind: TraitItemKind::Fn(..), .. }) => {}
- Node::ImplItem(&hir::ImplItem { kind: ImplItemKind::Fn(..), .. }) => {}
- Node::Expr(&hir::Expr { kind: ExprKind::Closure { .. }, .. }) => {}
- _ => return None,
- }
-
- let ret_ty = self.type_of(scope_def_id).subst_identity();
- match ret_ty.kind() {
- ty::FnDef(_, _) => {
- let sig = ret_ty.fn_sig(self);
- let output = self.erase_late_bound_regions(sig.output());
- output.is_impl_trait().then(|| {
- let hir_id = self.hir().local_def_id_to_hir_id(scope_def_id);
- let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap();
- (output, fn_decl.output.span())
- })
- }
- _ => None,
- }
- }
-
/// Checks if the bound region is in Impl Item.
pub fn is_bound_region_in_impl_item(self, suitable_region_binding_scope: LocalDefId) -> bool {
let container_id = self.parent(suitable_region_binding_scope.to_def_id());
@@ -1123,7 +1149,7 @@ impl<'tcx> TyCtxt<'tcx> {
self,
self.lifetimes.re_static,
self.type_of(self.require_lang_item(LangItem::PanicLocation, None))
- .subst(self, self.mk_substs(&[self.lifetimes.re_static.into()])),
+ .instantiate(self, self.mk_args(&[self.lifetimes.re_static.into()])),
)
}
@@ -1166,7 +1192,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// A trait implemented for all `X<'a>` types that can be safely and
/// efficiently converted to `X<'tcx>` as long as they are part of the
/// provided `TyCtxt<'tcx>`.
-/// This can be done, for example, for `Ty<'tcx>` or `SubstsRef<'tcx>`
+/// This can be done, for example, for `Ty<'tcx>` or `GenericArgsRef<'tcx>`
/// by looking them up in their respective interners.
///
/// However, this is still not the best implementation as it does
@@ -1232,8 +1258,8 @@ nop_list_lift! {canonical_var_infos; CanonicalVarInfo<'a> => CanonicalVarInfo<'t
nop_list_lift! {projs; ProjectionKind => ProjectionKind}
nop_list_lift! {bound_variable_kinds; ty::BoundVariableKind => ty::BoundVariableKind}
-// This is the impl for `&'a InternalSubsts<'a>`.
-nop_list_lift! {substs; GenericArg<'a> => GenericArg<'tcx>}
+// This is the impl for `&'a GenericArgs<'a>`.
+nop_list_lift! {args; GenericArg<'a> => GenericArg<'tcx>}
CloneLiftImpls! {
Constness,
@@ -1345,7 +1371,7 @@ impl<'tcx> TyCtxt<'tcx> {
Foreign
)?;
- writeln!(fmt, "InternalSubsts interner: #{}", self.0.interners.substs.len())?;
+ writeln!(fmt, "GenericArgs interner: #{}", self.0.interners.args.len())?;
writeln!(fmt, "Region interner: #{}", self.0.interners.region.len())?;
writeln!(
fmt,
@@ -1501,7 +1527,7 @@ macro_rules! slice_interners {
// should be used when possible, because it's faster.
slice_interners!(
const_lists: pub mk_const_list(Const<'tcx>),
- substs: pub mk_substs(GenericArg<'tcx>),
+ args: pub mk_args(GenericArg<'tcx>),
type_lists: pub mk_type_list(Ty<'tcx>),
canonical_var_infos: pub mk_canonical_var_infos(CanonicalVarInfo<'tcx>),
poly_existential_predicates: intern_poly_existential_predicates(PolyExistentialPredicate<'tcx>),
@@ -1615,12 +1641,12 @@ impl<'tcx> TyCtxt<'tcx> {
}
#[inline(always)]
- pub(crate) fn check_and_mk_substs(
+ pub(crate) fn check_and_mk_args(
self,
_def_id: DefId,
- substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
- ) -> SubstsRef<'tcx> {
- let substs = substs.into_iter().map(Into::into);
+ args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
+ ) -> GenericArgsRef<'tcx> {
+ let args = args.into_iter().map(Into::into);
#[cfg(debug_assertions)]
{
let generics = self.generics_of(_def_id);
@@ -1636,12 +1662,12 @@ impl<'tcx> TyCtxt<'tcx> {
};
assert_eq!(
(n, Some(n)),
- substs.size_hint(),
+ args.size_hint(),
"wrong number of generic parameters for {_def_id:?}: {:?}",
- substs.collect::<Vec<_>>(),
+ args.collect::<Vec<_>>(),
);
}
- self.mk_substs_from_iter(substs)
+ self.mk_args_from_iter(args)
}
#[inline]
@@ -1799,12 +1825,12 @@ impl<'tcx> TyCtxt<'tcx> {
T::collect_and_apply(iter, |xs| self.mk_type_list(xs))
}
- pub fn mk_substs_from_iter<I, T>(self, iter: I) -> T::Output
+ pub fn mk_args_from_iter<I, T>(self, iter: I) -> T::Output
where
I: Iterator<Item = T>,
T: CollectAndApply<GenericArg<'tcx>, &'tcx List<GenericArg<'tcx>>>,
{
- T::collect_and_apply(iter, |xs| self.mk_substs(xs))
+ T::collect_and_apply(iter, |xs| self.mk_args(xs))
}
pub fn mk_canonical_var_infos_from_iter<I, T>(self, iter: I) -> T::Output
@@ -1831,21 +1857,21 @@ impl<'tcx> TyCtxt<'tcx> {
T::collect_and_apply(iter, |xs| self.mk_fields(xs))
}
- pub fn mk_substs_trait(
+ pub fn mk_args_trait(
self,
self_ty: Ty<'tcx>,
rest: impl IntoIterator<Item = GenericArg<'tcx>>,
- ) -> SubstsRef<'tcx> {
- self.mk_substs_from_iter(iter::once(self_ty.into()).chain(rest))
+ ) -> GenericArgsRef<'tcx> {
+ self.mk_args_from_iter(iter::once(self_ty.into()).chain(rest))
}
pub fn mk_alias_ty(
self,
def_id: DefId,
- substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
+ args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
) -> ty::AliasTy<'tcx> {
- let substs = self.check_and_mk_substs(def_id, substs);
- ty::AliasTy { def_id, substs, _use_mk_alias_ty_instead: () }
+ let args = self.check_and_mk_args(def_id, args);
+ ty::AliasTy { def_id, args, _use_mk_alias_ty_instead: () }
}
pub fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output
@@ -1858,6 +1884,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
/// typically generated by `#[derive(LintDiagnostic)]`).
+ #[track_caller]
pub fn emit_spanned_lint(
self,
lint: &'static Lint,
@@ -1878,6 +1905,7 @@ impl<'tcx> TyCtxt<'tcx> {
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
#[rustc_lint_diagnostics]
+ #[track_caller]
pub fn struct_span_lint_hir(
self,
lint: &'static Lint,
@@ -1894,6 +1922,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically
/// generated by `#[derive(LintDiagnostic)]`).
+ #[track_caller]
pub fn emit_lint(
self,
lint: &'static Lint,
@@ -1909,6 +1938,7 @@ impl<'tcx> TyCtxt<'tcx> {
///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
#[rustc_lint_diagnostics]
+ #[track_caller]
pub fn struct_lint_node(
self,
lint: &'static Lint,
@@ -1948,6 +1978,84 @@ impl<'tcx> TyCtxt<'tcx> {
)
}
+ /// Given the def-id of an early-bound lifetime on an RPIT corresponding to
+ /// a duplicated captured lifetime, map it back to the early- or late-bound
+ /// lifetime of the function from which it originally as captured. If it is
+ /// a late-bound lifetime, this will represent the liberated (`ReFree`) lifetime
+ /// of the signature.
+ // FIXME(RPITIT): if we ever synthesize new lifetimes for RPITITs and not just
+ // re-use the generics of the opaque, this function will need to be tweaked slightly.
+ pub fn map_rpit_lifetime_to_fn_lifetime(
+ self,
+ mut rpit_lifetime_param_def_id: LocalDefId,
+ ) -> ty::Region<'tcx> {
+ debug_assert!(
+ matches!(self.def_kind(rpit_lifetime_param_def_id), DefKind::LifetimeParam),
+ "{rpit_lifetime_param_def_id:?} is a {}",
+ self.def_descr(rpit_lifetime_param_def_id.to_def_id())
+ );
+
+ loop {
+ let parent = self.local_parent(rpit_lifetime_param_def_id);
+ let hir::OpaqueTy { lifetime_mapping, .. } =
+ self.hir().get_by_def_id(parent).expect_item().expect_opaque_ty();
+
+ let Some((lifetime, _)) = lifetime_mapping
+ .iter()
+ .find(|(_, duplicated_param)| *duplicated_param == rpit_lifetime_param_def_id)
+ else {
+ bug!("duplicated lifetime param should be present");
+ };
+
+ match self.named_bound_var(lifetime.hir_id) {
+ Some(resolve_bound_vars::ResolvedArg::EarlyBound(ebv)) => {
+ let new_parent = self.parent(ebv);
+
+ // If we map to another opaque, then it should be a parent
+ // of the opaque we mapped from. Continue mapping.
+ if matches!(self.def_kind(new_parent), DefKind::OpaqueTy) {
+ debug_assert_eq!(self.parent(parent.to_def_id()), new_parent);
+ rpit_lifetime_param_def_id = ebv.expect_local();
+ continue;
+ }
+
+ let generics = self.generics_of(new_parent);
+ return ty::Region::new_early_bound(
+ self,
+ ty::EarlyBoundRegion {
+ def_id: ebv,
+ index: generics
+ .param_def_id_to_index(self, ebv)
+ .expect("early-bound var should be present in fn generics"),
+ name: self.hir().name(self.local_def_id_to_hir_id(ebv.expect_local())),
+ },
+ );
+ }
+ Some(resolve_bound_vars::ResolvedArg::LateBound(_, _, lbv)) => {
+ let new_parent = self.parent(lbv);
+ return ty::Region::new_free(
+ self,
+ new_parent,
+ ty::BoundRegionKind::BrNamed(
+ lbv,
+ self.hir().name(self.local_def_id_to_hir_id(lbv.expect_local())),
+ ),
+ );
+ }
+ Some(resolve_bound_vars::ResolvedArg::Error(guar)) => {
+ return ty::Region::new_error(self, guar);
+ }
+ _ => {
+ return ty::Region::new_error_with_message(
+ self,
+ lifetime.ident.span,
+ "cannot resolve lifetime",
+ );
+ }
+ }
+ }
+ }
+
/// Whether the `def_id` counts as const fn in the current crate, considering all active
/// feature gates
pub fn is_const_fn(self, def_id: DefId) -> bool {
@@ -1980,9 +2088,9 @@ impl<'tcx> TyCtxt<'tcx> {
matches!(
node,
hir::Node::Item(hir::Item {
- kind: hir::ItemKind::Impl(hir::Impl { constness: hir::Constness::Const, .. }),
+ kind: hir::ItemKind::Impl(hir::Impl { generics, .. }),
..
- })
+ }) if generics.params.iter().any(|p| self.has_attr(p.def_id, sym::rustc_host))
)
}
@@ -2002,16 +2110,8 @@ impl<'tcx> TyCtxt<'tcx> {
)
}
- pub fn lower_impl_trait_in_trait_to_assoc_ty(self) -> bool {
- self.sess.opts.unstable_opts.lower_impl_trait_in_trait_to_assoc_ty
- }
-
pub fn is_impl_trait_in_trait(self, def_id: DefId) -> bool {
- if self.lower_impl_trait_in_trait_to_assoc_ty() {
- self.opt_rpitit_info(def_id).is_some()
- } else {
- self.def_kind(def_id) == DefKind::ImplTraitPlaceholder
- }
+ self.opt_rpitit_info(def_id).is_some()
}
/// Named module children from all kinds of items, including imports.
diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs
index a0b17c374..5db9b775a 100644
--- a/compiler/rustc_middle/src/ty/diagnostics.rs
+++ b/compiler/rustc_middle/src/ty/diagnostics.rs
@@ -1,6 +1,7 @@
//! Diagnostics related methods for `Ty`.
use std::borrow::Cow;
+use std::fmt::Write;
use std::ops::ControlFlow;
use crate::ty::{
@@ -71,7 +72,7 @@ impl<'tcx> Ty<'tcx> {
/// ADTs with no type arguments.
pub fn is_simple_text(self) -> bool {
match self.kind() {
- Adt(_, substs) => substs.non_erasable_generics().next().is_none(),
+ Adt(_, args) => args.non_erasable_generics().next().is_none(),
Ref(_, ty, _) => ty.is_simple_text(),
_ => self.is_simple_ty(),
}
@@ -126,7 +127,7 @@ pub fn suggest_arbitrary_trait_bound<'tcx>(
if constraint.ends_with('>') {
constraint = format!("{}, {} = {}>", &constraint[..constraint.len() - 1], name, term);
} else {
- constraint.push_str(&format!("<{} = {}>", name, term));
+ constraint.push_str(&format!("<{name} = {term}>"));
}
}
@@ -274,9 +275,9 @@ pub fn suggest_constraining_type_params<'a>(
if span_to_replace.is_some() {
constraint.clone()
} else if bound_list_non_empty {
- format!(" + {}", constraint)
+ format!(" + {constraint}")
} else {
- format!(" {}", constraint)
+ format!(" {constraint}")
},
SuggestChangingConstraintsMessage::RestrictBoundFurther,
))
@@ -335,10 +336,10 @@ pub fn suggest_constraining_type_params<'a>(
// - insert: `, X: Bar`
suggestions.push((
generics.tail_span_for_predicate_suggestion(),
- constraints
- .iter()
- .map(|&(constraint, _)| format!(", {}: {}", param_name, constraint))
- .collect::<String>(),
+ constraints.iter().fold(String::new(), |mut string, &(constraint, _)| {
+ write!(string, ", {param_name}: {constraint}").unwrap();
+ string
+ }),
SuggestChangingConstraintsMessage::RestrictTypeFurther { ty: param_name },
));
continue;
@@ -358,7 +359,7 @@ pub fn suggest_constraining_type_params<'a>(
// default (`<T=Foo>`), so we suggest adding `where T: Bar`.
suggestions.push((
generics.tail_span_for_predicate_suggestion(),
- format!(" where {}: {}", param_name, constraint),
+ format!(" where {param_name}: {constraint}"),
SuggestChangingConstraintsMessage::RestrictTypeFurther { ty: param_name },
));
continue;
@@ -371,7 +372,7 @@ pub fn suggest_constraining_type_params<'a>(
if let Some(colon_span) = param.colon_span {
suggestions.push((
colon_span.shrink_to_hi(),
- format!(" {}", constraint),
+ format!(" {constraint}"),
SuggestChangingConstraintsMessage::RestrictType { ty: param_name },
));
continue;
@@ -383,7 +384,7 @@ pub fn suggest_constraining_type_params<'a>(
// - help: consider restricting this type parameter with `T: Foo`
suggestions.push((
param.span.shrink_to_hi(),
- format!(": {}", constraint),
+ format!(": {constraint}"),
SuggestChangingConstraintsMessage::RestrictType { ty: param_name },
));
}
@@ -401,10 +402,10 @@ pub fn suggest_constraining_type_params<'a>(
Cow::from("consider further restricting this bound")
}
SuggestChangingConstraintsMessage::RestrictType { ty } => {
- Cow::from(format!("consider restricting type parameter `{}`", ty))
+ Cow::from(format!("consider restricting type parameter `{ty}`"))
}
SuggestChangingConstraintsMessage::RestrictTypeFurther { ty } => {
- Cow::from(format!("consider further restricting type parameter `{}`", ty))
+ Cow::from(format!("consider further restricting type parameter `{ty}`"))
}
SuggestChangingConstraintsMessage::RemoveMaybeUnsized => {
Cow::from("consider removing the `?Sized` bound to make the type parameter `Sized`")
@@ -491,8 +492,8 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
Alias(Opaque, AliasTy { def_id, .. }) => {
let parent = self.tcx.parent(def_id);
- let parent_ty = self.tcx.type_of(parent).subst_identity();
- if let DefKind::TyAlias | DefKind::AssocTy = self.tcx.def_kind(parent)
+ let parent_ty = self.tcx.type_of(parent).instantiate_identity();
+ if let DefKind::TyAlias { .. } | DefKind::AssocTy = self.tcx.def_kind(parent)
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind()
&& parent_opaque_def_id == def_id
{
@@ -558,8 +559,8 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
let t = match *t.kind() {
Infer(InferTy::TyVar(_)) if self.infer_suggestable => t,
- FnDef(def_id, substs) => {
- Ty::new_fn_ptr(self.tcx, self.tcx.fn_sig(def_id).subst(self.tcx, substs))
+ FnDef(def_id, args) => {
+ Ty::new_fn_ptr(self.tcx, self.tcx.fn_sig(def_id).instantiate(self.tcx, args))
}
// FIXME(compiler-errors): We could replace these with infer, I guess.
@@ -575,8 +576,8 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
Alias(Opaque, AliasTy { def_id, .. }) => {
let parent = self.tcx.parent(def_id);
- let parent_ty = self.tcx.type_of(parent).subst_identity();
- if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent)
+ let parent_ty = self.tcx.type_of(parent).instantiate_identity();
+ if let hir::def::DefKind::TyAlias { .. } | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent)
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = *parent_ty.kind()
&& parent_opaque_def_id == def_id
{
diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs
index c794c3fad..bf6f082c2 100644
--- a/compiler/rustc_middle/src/ty/error.rs
+++ b/compiler/rustc_middle/src/ty/error.rs
@@ -90,9 +90,9 @@ impl<'tcx> TypeError<'tcx> {
// A naive approach to making sure that we're not reporting silly errors such as:
// (expected closure, found closure).
if expected == found {
- format!("expected {}, found a different {}", expected, found)
+ format!("expected {expected}, found a different {found}")
} else {
- format!("expected {}, found {}", expected, found)
+ format!("expected {expected}, found {found}")
}
}
@@ -131,7 +131,7 @@ impl<'tcx> TypeError<'tcx> {
)
.into(),
ArgCount => "incorrect number of function parameters".into(),
- FieldMisMatch(adt, field) => format!("field type mismatch: {}.{}", adt, field).into(),
+ FieldMisMatch(adt, field) => format!("field type mismatch: {adt}.{field}").into(),
RegionsDoesNotOutlive(..) => "lifetime mismatch".into(),
// Actually naming the region here is a bit confusing because context is lacking
RegionsInsufficientlyPolymorphic(..) => {
@@ -164,7 +164,7 @@ impl<'tcx> TypeError<'tcx> {
ty::IntVarValue::IntType(ty) => ty.name_str(),
ty::IntVarValue::UintType(ty) => ty.name_str(),
};
- format!("expected `{}`, found `{}`", expected, found).into()
+ format!("expected `{expected}`, found `{found}`").into()
}
FloatMismatch(ref values) => format!(
"expected `{}`, found `{}`",
@@ -339,12 +339,17 @@ impl<'tcx> TyCtxt<'tcx> {
}
pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option<PathBuf>) {
- let width = self.sess.diagnostic_width();
- let length_limit = width.saturating_sub(30);
let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS)
.pretty_print_type(ty)
.expect("could not write to `String`")
.into_buffer();
+
+ if !self.sess.opts.unstable_opts.write_long_types_to_disk {
+ return (regular, None);
+ }
+
+ let width = self.sess.diagnostic_width();
+ let length_limit = width.saturating_sub(30);
if regular.len() <= width {
return (regular, None);
}
diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs
index 76f61d9ac..668aa4521 100644
--- a/compiler/rustc_middle/src/ty/fast_reject.rs
+++ b/compiler/rustc_middle/src/ty/fast_reject.rs
@@ -1,40 +1,38 @@
use crate::mir::Mutability;
-use crate::ty::subst::GenericArgKind;
-use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeVisitableExt};
+use crate::ty::GenericArgKind;
+use crate::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt};
use rustc_hir::def_id::DefId;
use std::fmt::Debug;
use std::hash::Hash;
use std::iter;
-use self::SimplifiedType::*;
-
/// See `simplify_type`.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
pub enum SimplifiedType {
- BoolSimplifiedType,
- CharSimplifiedType,
- IntSimplifiedType(ty::IntTy),
- UintSimplifiedType(ty::UintTy),
- FloatSimplifiedType(ty::FloatTy),
- AdtSimplifiedType(DefId),
- ForeignSimplifiedType(DefId),
- StrSimplifiedType,
- ArraySimplifiedType,
- SliceSimplifiedType,
- RefSimplifiedType(Mutability),
- PtrSimplifiedType(Mutability),
- NeverSimplifiedType,
- TupleSimplifiedType(usize),
+ Bool,
+ Char,
+ Int(ty::IntTy),
+ Uint(ty::UintTy),
+ Float(ty::FloatTy),
+ Adt(DefId),
+ Foreign(DefId),
+ Str,
+ Array,
+ Slice,
+ Ref(Mutability),
+ Ptr(Mutability),
+ Never,
+ Tuple(usize),
/// A trait object, all of whose components are markers
/// (e.g., `dyn Send + Sync`).
- MarkerTraitObjectSimplifiedType,
- TraitSimplifiedType(DefId),
- ClosureSimplifiedType(DefId),
- GeneratorSimplifiedType(DefId),
- GeneratorWitnessSimplifiedType(usize),
- GeneratorWitnessMIRSimplifiedType(DefId),
- FunctionSimplifiedType(usize),
- PlaceholderSimplifiedType,
+ MarkerTraitObject,
+ Trait(DefId),
+ Closure(DefId),
+ Generator(DefId),
+ GeneratorWitness(usize),
+ GeneratorWitnessMIR(DefId),
+ Function(usize),
+ Placeholder,
}
/// Generic parameters are pretty much just bound variables, e.g.
@@ -64,6 +62,9 @@ pub enum TreatParams {
/// correct mode for *lookup*, as during candidate selection.
///
/// N.B. during deep rejection, this acts identically to `ForLookup`.
+ ///
+ /// FIXME(-Ztrait-solver=next): Remove this variant and cleanup
+ /// the code.
NextSolverLookup,
}
@@ -110,34 +111,36 @@ pub fn simplify_type<'tcx>(
treat_params: TreatParams,
) -> Option<SimplifiedType> {
match *ty.kind() {
- ty::Bool => Some(BoolSimplifiedType),
- ty::Char => Some(CharSimplifiedType),
- ty::Int(int_type) => Some(IntSimplifiedType(int_type)),
- ty::Uint(uint_type) => Some(UintSimplifiedType(uint_type)),
- ty::Float(float_type) => Some(FloatSimplifiedType(float_type)),
- ty::Adt(def, _) => Some(AdtSimplifiedType(def.did())),
- ty::Str => Some(StrSimplifiedType),
- ty::Array(..) => Some(ArraySimplifiedType),
- ty::Slice(..) => Some(SliceSimplifiedType),
- ty::RawPtr(ptr) => Some(PtrSimplifiedType(ptr.mutbl)),
+ ty::Bool => Some(SimplifiedType::Bool),
+ ty::Char => Some(SimplifiedType::Char),
+ ty::Int(int_type) => Some(SimplifiedType::Int(int_type)),
+ ty::Uint(uint_type) => Some(SimplifiedType::Uint(uint_type)),
+ ty::Float(float_type) => Some(SimplifiedType::Float(float_type)),
+ ty::Adt(def, _) => Some(SimplifiedType::Adt(def.did())),
+ ty::Str => Some(SimplifiedType::Str),
+ ty::Array(..) => Some(SimplifiedType::Array),
+ ty::Slice(..) => Some(SimplifiedType::Slice),
+ ty::RawPtr(ptr) => Some(SimplifiedType::Ptr(ptr.mutbl)),
ty::Dynamic(trait_info, ..) => match trait_info.principal_def_id() {
Some(principal_def_id) if !tcx.trait_is_auto(principal_def_id) => {
- Some(TraitSimplifiedType(principal_def_id))
+ Some(SimplifiedType::Trait(principal_def_id))
}
- _ => Some(MarkerTraitObjectSimplifiedType),
+ _ => Some(SimplifiedType::MarkerTraitObject),
},
- ty::Ref(_, _, mutbl) => Some(RefSimplifiedType(mutbl)),
- ty::FnDef(def_id, _) | ty::Closure(def_id, _) => Some(ClosureSimplifiedType(def_id)),
- ty::Generator(def_id, _, _) => Some(GeneratorSimplifiedType(def_id)),
- ty::GeneratorWitness(tys) => Some(GeneratorWitnessSimplifiedType(tys.skip_binder().len())),
- ty::GeneratorWitnessMIR(def_id, _) => Some(GeneratorWitnessMIRSimplifiedType(def_id)),
- ty::Never => Some(NeverSimplifiedType),
- ty::Tuple(tys) => Some(TupleSimplifiedType(tys.len())),
- ty::FnPtr(f) => Some(FunctionSimplifiedType(f.skip_binder().inputs().len())),
- ty::Placeholder(..) => Some(PlaceholderSimplifiedType),
+ ty::Ref(_, _, mutbl) => Some(SimplifiedType::Ref(mutbl)),
+ ty::FnDef(def_id, _) | ty::Closure(def_id, _) => Some(SimplifiedType::Closure(def_id)),
+ ty::Generator(def_id, _, _) => Some(SimplifiedType::Generator(def_id)),
+ ty::GeneratorWitness(tys) => {
+ Some(SimplifiedType::GeneratorWitness(tys.skip_binder().len()))
+ }
+ ty::GeneratorWitnessMIR(def_id, _) => Some(SimplifiedType::GeneratorWitnessMIR(def_id)),
+ ty::Never => Some(SimplifiedType::Never),
+ ty::Tuple(tys) => Some(SimplifiedType::Tuple(tys.len())),
+ ty::FnPtr(f) => Some(SimplifiedType::Function(f.skip_binder().inputs().len())),
+ ty::Placeholder(..) => Some(SimplifiedType::Placeholder),
ty::Param(_) => match treat_params {
TreatParams::ForLookup | TreatParams::NextSolverLookup => {
- Some(PlaceholderSimplifiedType)
+ Some(SimplifiedType::Placeholder)
}
TreatParams::AsCandidateKey => None,
},
@@ -147,11 +150,13 @@ pub fn simplify_type<'tcx>(
//
// We will have to be careful with lazy normalization here.
// FIXME(lazy_normalization): This is probably not right...
- TreatParams::ForLookup if !ty.has_non_region_infer() => Some(PlaceholderSimplifiedType),
- TreatParams::NextSolverLookup => Some(PlaceholderSimplifiedType),
+ TreatParams::ForLookup if !ty.has_non_region_infer() => {
+ Some(SimplifiedType::Placeholder)
+ }
+ TreatParams::NextSolverLookup => Some(SimplifiedType::Placeholder),
TreatParams::ForLookup | TreatParams::AsCandidateKey => None,
},
- ty::Foreign(def_id) => Some(ForeignSimplifiedType(def_id)),
+ ty::Foreign(def_id) => Some(SimplifiedType::Foreign(def_id)),
ty::Bound(..) | ty::Infer(_) | ty::Error(_) => None,
}
}
@@ -159,12 +164,12 @@ pub fn simplify_type<'tcx>(
impl SimplifiedType {
pub fn def(self) -> Option<DefId> {
match self {
- AdtSimplifiedType(d)
- | ForeignSimplifiedType(d)
- | TraitSimplifiedType(d)
- | ClosureSimplifiedType(d)
- | GeneratorSimplifiedType(d)
- | GeneratorWitnessMIRSimplifiedType(d) => Some(d),
+ SimplifiedType::Adt(d)
+ | SimplifiedType::Foreign(d)
+ | SimplifiedType::Trait(d)
+ | SimplifiedType::Closure(d)
+ | SimplifiedType::Generator(d)
+ | SimplifiedType::GeneratorWitnessMIR(d) => Some(d),
_ => None,
}
}
@@ -188,12 +193,12 @@ pub struct DeepRejectCtxt {
}
impl DeepRejectCtxt {
- pub fn substs_refs_may_unify<'tcx>(
+ pub fn args_refs_may_unify<'tcx>(
self,
- obligation_substs: SubstsRef<'tcx>,
- impl_substs: SubstsRef<'tcx>,
+ obligation_args: GenericArgsRef<'tcx>,
+ impl_args: GenericArgsRef<'tcx>,
) -> bool {
- iter::zip(obligation_substs, impl_substs).all(|(obl, imp)| {
+ iter::zip(obligation_args, impl_args).all(|(obl, imp)| {
match (obl.unpack(), imp.unpack()) {
// We don't fast reject based on regions for now.
(GenericArgKind::Lifetime(_), GenericArgKind::Lifetime(_)) => true,
@@ -258,9 +263,9 @@ impl DeepRejectCtxt {
}
_ => false,
},
- ty::Adt(obl_def, obl_substs) => match k {
- &ty::Adt(impl_def, impl_substs) => {
- obl_def == impl_def && self.substs_refs_may_unify(obl_substs, impl_substs)
+ ty::Adt(obl_def, obl_args) => match k {
+ &ty::Adt(impl_def, impl_args) => {
+ obl_def == impl_def && self.args_refs_may_unify(obl_args, impl_args)
}
_ => false,
},
diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs
index ff3917947..bbd4a6233 100644
--- a/compiler/rustc_middle/src/ty/flags.rs
+++ b/compiler/rustc_middle/src/ty/flags.rs
@@ -1,5 +1,5 @@
-use crate::ty::subst::{GenericArg, GenericArgKind};
use crate::ty::{self, InferConst, Ty, TypeFlags};
+use crate::ty::{GenericArg, GenericArgKind};
use std::slice;
#[derive(Debug)]
@@ -105,48 +105,48 @@ impl FlagComputation {
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
}
- ty::Generator(_, substs, _) => {
- let substs = substs.as_generator();
+ ty::Generator(_, args, _) => {
+ let args = args.as_generator();
let should_remove_further_specializable =
!self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
- self.add_substs(substs.parent_substs());
+ self.add_args(args.parent_args());
if should_remove_further_specializable {
self.flags -= TypeFlags::STILL_FURTHER_SPECIALIZABLE;
}
- self.add_ty(substs.resume_ty());
- self.add_ty(substs.return_ty());
- self.add_ty(substs.witness());
- self.add_ty(substs.yield_ty());
- self.add_ty(substs.tupled_upvars_ty());
+ self.add_ty(args.resume_ty());
+ self.add_ty(args.return_ty());
+ self.add_ty(args.witness());
+ self.add_ty(args.yield_ty());
+ self.add_ty(args.tupled_upvars_ty());
}
&ty::GeneratorWitness(ts) => {
self.bound_computation(ts, |flags, ts| flags.add_tys(ts));
}
- ty::GeneratorWitnessMIR(_, substs) => {
+ ty::GeneratorWitnessMIR(_, args) => {
let should_remove_further_specializable =
!self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
- self.add_substs(substs);
+ self.add_args(args);
if should_remove_further_specializable {
self.flags -= TypeFlags::STILL_FURTHER_SPECIALIZABLE;
}
self.add_flags(TypeFlags::HAS_TY_GENERATOR);
}
- &ty::Closure(_, substs) => {
- let substs = substs.as_closure();
+ &ty::Closure(_, args) => {
+ let args = args.as_closure();
let should_remove_further_specializable =
!self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
- self.add_substs(substs.parent_substs());
+ self.add_args(args.parent_args());
if should_remove_further_specializable {
self.flags -= TypeFlags::STILL_FURTHER_SPECIALIZABLE;
}
- self.add_ty(substs.sig_as_fn_ptr_ty());
- self.add_ty(substs.kind_ty());
- self.add_ty(substs.tupled_upvars_ty());
+ self.add_ty(args.sig_as_fn_ptr_ty());
+ self.add_ty(args.kind_ty());
+ self.add_ty(args.tupled_upvars_ty());
}
&ty::Bound(debruijn, _) => {
@@ -172,8 +172,8 @@ impl FlagComputation {
}
}
- &ty::Adt(_, substs) => {
- self.add_substs(substs);
+ &ty::Adt(_, args) => {
+ self.add_args(args);
}
&ty::Alias(kind, data) => {
@@ -189,7 +189,7 @@ impl FlagComputation {
&ty::Dynamic(obj, r, _) => {
for predicate in obj.iter() {
self.bound_computation(predicate, |computation, predicate| match predicate {
- ty::ExistentialPredicate::Trait(tr) => computation.add_substs(tr.substs),
+ ty::ExistentialPredicate::Trait(tr) => computation.add_args(tr.args),
ty::ExistentialPredicate::Projection(p) => {
computation.add_existential_projection(&p);
}
@@ -220,8 +220,8 @@ impl FlagComputation {
self.add_tys(types);
}
- &ty::FnDef(_, substs) => {
- self.add_substs(substs);
+ &ty::FnDef(_, args) => {
+ self.add_args(args);
}
&ty::FnPtr(fn_sig) => self.bound_computation(fn_sig, |computation, fn_sig| {
@@ -238,7 +238,7 @@ impl FlagComputation {
fn add_predicate_atom(&mut self, atom: ty::PredicateKind<'_>) {
match atom {
ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred)) => {
- self.add_substs(trait_pred.trait_ref.substs);
+ self.add_args(trait_pred.trait_ref.args);
}
ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(
a,
@@ -274,11 +274,11 @@ impl FlagComputation {
self.add_term(term);
}
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(arg)) => {
- self.add_substs(slice::from_ref(&arg));
+ self.add_args(slice::from_ref(&arg));
}
ty::PredicateKind::ObjectSafe(_def_id) => {}
- ty::PredicateKind::ClosureKind(_def_id, substs, _kind) => {
- self.add_substs(substs);
+ ty::PredicateKind::ClosureKind(_def_id, args, _kind) => {
+ self.add_args(args);
}
ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(uv)) => {
self.add_const(uv);
@@ -317,7 +317,7 @@ impl FlagComputation {
self.add_ty(c.ty());
match c.kind() {
ty::ConstKind::Unevaluated(uv) => {
- self.add_substs(uv.substs);
+ self.add_args(uv.args);
self.add_flags(TypeFlags::HAS_CT_PROJECTION);
}
ty::ConstKind::Infer(infer) => {
@@ -365,7 +365,7 @@ impl FlagComputation {
}
fn add_existential_projection(&mut self, projection: &ty::ExistentialProjection<'_>) {
- self.add_substs(projection.substs);
+ self.add_args(projection.args);
match projection.term.unpack() {
ty::TermKind::Ty(ty) => self.add_ty(ty),
ty::TermKind::Const(ct) => self.add_const(ct),
@@ -373,11 +373,11 @@ impl FlagComputation {
}
fn add_alias_ty(&mut self, alias_ty: ty::AliasTy<'_>) {
- self.add_substs(alias_ty.substs);
+ self.add_args(alias_ty.args);
}
- fn add_substs(&mut self, substs: &[GenericArg<'_>]) {
- for kind in substs {
+ fn add_args(&mut self, args: &[GenericArg<'_>]) {
+ for kind in args {
match kind.unpack() {
GenericArgKind::Type(ty) => self.add_ty(ty),
GenericArgKind::Lifetime(lt) => self.add_region(lt),
diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/generic_args.rs
index 4d5f5b865..97dab5cb4 100644
--- a/compiler/rustc_middle/src/ty/subst.rs
+++ b/compiler/rustc_middle/src/ty/generic_args.rs
@@ -1,8 +1,8 @@
-// Type substitutions.
+// Generic arguments.
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable};
-use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
+use crate::ty::sty::{ClosureArgs, GeneratorArgs, InlineConstArgs};
use crate::ty::visit::{TypeVisitable, TypeVisitableExt, TypeVisitor};
use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt};
@@ -17,7 +17,6 @@ use smallvec::SmallVec;
use core::intrinsics;
use std::cmp::Ordering;
-use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::num::NonZeroUsize;
@@ -80,16 +79,6 @@ impl<'tcx> GenericArgKind<'tcx> {
}
}
-impl<'tcx> fmt::Debug for GenericArg<'tcx> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- match self.unpack() {
- GenericArgKind::Lifetime(lt) => lt.fmt(f),
- GenericArgKind::Type(ty) => ty.fmt(f),
- GenericArgKind::Const(ct) => ct.fmt(f),
- }
- }
-}
-
impl<'tcx> Ord for GenericArg<'tcx> {
fn cmp(&self, other: &GenericArg<'tcx>) -> Ordering {
self.unpack().cmp(&other.unpack())
@@ -185,7 +174,7 @@ impl<'tcx> GenericArg<'tcx> {
}
/// Unpack the `GenericArg` as a type when it is known certainly to be a type.
- /// This is true in cases where `Substs` is used in places where the kinds are known
+ /// This is true in cases where `GenericArgs` is used in places where the kinds are known
/// to be limited (e.g. in tuples, where the only parameters are type parameters).
pub fn expect_ty(self) -> Ty<'tcx> {
self.as_type().unwrap_or_else(|| bug!("expected a type, but found another kind"))
@@ -252,13 +241,13 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for GenericArg<'tcx> {
}
}
-/// List of generic arguments that are gonna be used to substitute generic parameters.
-pub type InternalSubsts<'tcx> = List<GenericArg<'tcx>>;
+/// List of generic arguments that are gonna be used to replace generic parameters.
+pub type GenericArgs<'tcx> = List<GenericArg<'tcx>>;
-pub type SubstsRef<'tcx> = &'tcx InternalSubsts<'tcx>;
+pub type GenericArgsRef<'tcx> = &'tcx GenericArgs<'tcx>;
-impl<'tcx> InternalSubsts<'tcx> {
- /// Converts substs to a type list.
+impl<'tcx> GenericArgs<'tcx> {
+ /// Converts generic args to a type list.
///
/// # Panics
///
@@ -266,66 +255,71 @@ impl<'tcx> InternalSubsts<'tcx> {
pub fn into_type_list(&self, tcx: TyCtxt<'tcx>) -> &'tcx List<Ty<'tcx>> {
tcx.mk_type_list_from_iter(self.iter().map(|arg| match arg.unpack() {
GenericArgKind::Type(ty) => ty,
- _ => bug!("`into_type_list` called on substs with non-types"),
+ _ => bug!("`into_type_list` called on generic arg with non-types"),
}))
}
- /// Interpret these substitutions as the substitutions of a closure type.
- /// Closure substitutions have a particular structure controlled by the
+ /// Interpret these generic args as the args of a closure type.
+ /// Closure args have a particular structure controlled by the
/// compiler that encodes information like the signature and closure kind;
- /// see `ty::ClosureSubsts` struct for more comments.
- pub fn as_closure(&'tcx self) -> ClosureSubsts<'tcx> {
- ClosureSubsts { substs: self }
+ /// see `ty::ClosureArgs` struct for more comments.
+ pub fn as_closure(&'tcx self) -> ClosureArgs<'tcx> {
+ ClosureArgs { args: self }
}
- /// Interpret these substitutions as the substitutions of a generator type.
- /// Generator substitutions have a particular structure controlled by the
+ /// Interpret these generic args as the args of a generator type.
+ /// Generator args have a particular structure controlled by the
/// compiler that encodes information like the signature and generator kind;
- /// see `ty::GeneratorSubsts` struct for more comments.
- pub fn as_generator(&'tcx self) -> GeneratorSubsts<'tcx> {
- GeneratorSubsts { substs: self }
+ /// see `ty::GeneratorArgs` struct for more comments.
+ pub fn as_generator(&'tcx self) -> GeneratorArgs<'tcx> {
+ GeneratorArgs { args: self }
}
- /// Interpret these substitutions as the substitutions of an inline const.
- /// Inline const substitutions have a particular structure controlled by the
+ /// Interpret these generic args as the args of an inline const.
+ /// Inline const args 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 }
+ /// see `ty::InlineConstArgs` struct for more comments.
+ pub fn as_inline_const(&'tcx self) -> InlineConstArgs<'tcx> {
+ InlineConstArgs { args: self }
}
- /// Creates an `InternalSubsts` that maps each generic parameter to itself.
- pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: impl Into<DefId>) -> SubstsRef<'tcx> {
+ /// Creates an `GenericArgs` that maps each generic parameter to itself.
+ pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: impl Into<DefId>) -> GenericArgsRef<'tcx> {
Self::for_item(tcx, def_id.into(), |param, _| tcx.mk_param_from_def(param))
}
- /// Creates an `InternalSubsts` for generic parameter definitions,
+ /// Creates an `GenericArgs` for generic parameter definitions,
/// by calling closures to obtain each kind.
- /// The closures get to observe the `InternalSubsts` as they're
+ /// The closures get to observe the `GenericArgs` as they're
/// being built, which can be used to correctly
- /// substitute defaults of generic parameters.
- pub fn for_item<F>(tcx: TyCtxt<'tcx>, def_id: DefId, mut mk_kind: F) -> SubstsRef<'tcx>
+ /// replace defaults of generic parameters.
+ pub fn for_item<F>(tcx: TyCtxt<'tcx>, def_id: DefId, mut mk_kind: F) -> GenericArgsRef<'tcx>
where
F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
{
let defs = tcx.generics_of(def_id);
let count = defs.count();
- let mut substs = SmallVec::with_capacity(count);
- Self::fill_item(&mut substs, tcx, defs, &mut mk_kind);
- tcx.mk_substs(&substs)
+ let mut args = SmallVec::with_capacity(count);
+ Self::fill_item(&mut args, tcx, defs, &mut mk_kind);
+ tcx.mk_args(&args)
}
- pub fn extend_to<F>(&self, tcx: TyCtxt<'tcx>, def_id: DefId, mut mk_kind: F) -> SubstsRef<'tcx>
+ pub fn extend_to<F>(
+ &self,
+ tcx: TyCtxt<'tcx>,
+ def_id: DefId,
+ mut mk_kind: F,
+ ) -> GenericArgsRef<'tcx>
where
F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
{
- Self::for_item(tcx, def_id, |param, substs| {
- self.get(param.index as usize).cloned().unwrap_or_else(|| mk_kind(param, substs))
+ Self::for_item(tcx, def_id, |param, args| {
+ self.get(param.index as usize).cloned().unwrap_or_else(|| mk_kind(param, args))
})
}
pub fn fill_item<F>(
- substs: &mut SmallVec<[GenericArg<'tcx>; 8]>,
+ args: &mut SmallVec<[GenericArg<'tcx>; 8]>,
tcx: TyCtxt<'tcx>,
defs: &ty::Generics,
mk_kind: &mut F,
@@ -334,38 +328,38 @@ impl<'tcx> InternalSubsts<'tcx> {
{
if let Some(def_id) = defs.parent {
let parent_defs = tcx.generics_of(def_id);
- Self::fill_item(substs, tcx, parent_defs, mk_kind);
+ Self::fill_item(args, tcx, parent_defs, mk_kind);
}
- Self::fill_single(substs, defs, mk_kind)
+ Self::fill_single(args, defs, mk_kind)
}
pub fn fill_single<F>(
- substs: &mut SmallVec<[GenericArg<'tcx>; 8]>,
+ args: &mut SmallVec<[GenericArg<'tcx>; 8]>,
defs: &ty::Generics,
mk_kind: &mut F,
) where
F: FnMut(&ty::GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,
{
- substs.reserve(defs.params.len());
+ args.reserve(defs.params.len());
for param in &defs.params {
- let kind = mk_kind(param, substs);
- assert_eq!(param.index as usize, substs.len(), "{substs:#?}, {defs:#?}");
- substs.push(kind);
+ let kind = mk_kind(param, args);
+ assert_eq!(param.index as usize, args.len(), "{args:#?}, {defs:#?}");
+ args.push(kind);
}
}
- // Extend an `original_substs` list to the full number of substs expected by `def_id`,
+ // Extend an `original_args` list to the full number of args expected by `def_id`,
// filling in the missing parameters with error ty/ct or 'static regions.
pub fn extend_with_error(
tcx: TyCtxt<'tcx>,
def_id: DefId,
- original_substs: &[GenericArg<'tcx>],
- ) -> SubstsRef<'tcx> {
- ty::InternalSubsts::for_item(tcx, def_id, |def, substs| {
- if let Some(subst) = original_substs.get(def.index as usize) {
- *subst
+ original_args: &[GenericArg<'tcx>],
+ ) -> GenericArgsRef<'tcx> {
+ ty::GenericArgs::for_item(tcx, def_id, |def, args| {
+ if let Some(arg) = original_args.get(def.index as usize) {
+ *arg
} else {
- def.to_error(tcx, substs)
+ def.to_error(tcx, args)
}
})
}
@@ -421,9 +415,9 @@ impl<'tcx> InternalSubsts<'tcx> {
self.type_at(def.index as usize).into()
}
- /// Transform from substitutions for a child of `source_ancestor`
- /// (e.g., a trait or impl) to substitutions for the same child
- /// in a different item, with `target_substs` as the base for
+ /// Transform from generic args for a child of `source_ancestor`
+ /// (e.g., a trait or impl) to args for the same child
+ /// in a different item, with `target_args` as the base for
/// the target impl/trait, with the source child-specific
/// parameters (e.g., method parameters) on top of that base.
///
@@ -434,23 +428,23 @@ impl<'tcx> InternalSubsts<'tcx> {
/// impl<U> X<U> for U { fn f<V>() {} }
/// ```
///
- /// * If `self` is `[Self, S, T]`: the identity substs of `f` in the trait.
+ /// * If `self` is `[Self, S, T]`: the identity args of `f` in the trait.
/// * If `source_ancestor` is the def_id of the trait.
- /// * If `target_substs` is `[U]`, the substs for the impl.
- /// * Then we will return `[U, T]`, the subst for `f` in the impl that
+ /// * If `target_args` is `[U]`, the args for the impl.
+ /// * Then we will return `[U, T]`, the arg for `f` in the impl that
/// are needed for it to match the trait.
pub fn rebase_onto(
&self,
tcx: TyCtxt<'tcx>,
source_ancestor: DefId,
- target_substs: SubstsRef<'tcx>,
- ) -> SubstsRef<'tcx> {
+ target_args: GenericArgsRef<'tcx>,
+ ) -> GenericArgsRef<'tcx> {
let defs = tcx.generics_of(source_ancestor);
- tcx.mk_substs_from_iter(target_substs.iter().chain(self.iter().skip(defs.params.len())))
+ tcx.mk_args_from_iter(target_args.iter().chain(self.iter().skip(defs.params.len())))
}
- pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> SubstsRef<'tcx> {
- tcx.mk_substs_from_iter(self.iter().take(generics.count()))
+ pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> GenericArgsRef<'tcx> {
+ tcx.mk_args_from_iter(self.iter().take(generics.count()))
}
pub fn host_effect_param(&'tcx self) -> Option<ty::Const<'tcx>> {
@@ -458,7 +452,7 @@ impl<'tcx> InternalSubsts<'tcx> {
}
}
-impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for SubstsRef<'tcx> {
+impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for GenericArgsRef<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
self,
folder: &mut F,
@@ -467,16 +461,12 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for SubstsRef<'tcx> {
// common length lists, to avoid the overhead of `SmallVec` creation.
// The match arms are in order of frequency. The 1, 2, and 0 cases are
// typically hit in 90--99.99% of cases. When folding doesn't change
- // the substs, it's faster to reuse the existing substs rather than
- // calling `mk_substs`.
+ // the args, it's faster to reuse the existing args rather than
+ // calling `mk_args`.
match self.len() {
1 => {
let param0 = self[0].try_fold_with(folder)?;
- if param0 == self[0] {
- Ok(self)
- } else {
- Ok(folder.interner().mk_substs(&[param0]))
- }
+ if param0 == self[0] { Ok(self) } else { Ok(folder.interner().mk_args(&[param0])) }
}
2 => {
let param0 = self[0].try_fold_with(folder)?;
@@ -484,11 +474,11 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for SubstsRef<'tcx> {
if param0 == self[0] && param1 == self[1] {
Ok(self)
} else {
- Ok(folder.interner().mk_substs(&[param0, param1]))
+ Ok(folder.interner().mk_args(&[param0, param1]))
}
}
0 => Ok(self),
- _ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk_substs(v)),
+ _ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk_args(v)),
}
}
}
@@ -498,7 +488,7 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx>> {
self,
folder: &mut F,
) -> Result<Self, F::Error> {
- // This code is fairly hot, though not as hot as `SubstsRef`.
+ // This code is fairly hot, though not as hot as `GenericArgsRef`.
//
// When compiling stage 2, I get the following results:
//
@@ -536,18 +526,18 @@ impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> for &'tcx
}
/// Similar to [`super::Binder`] except that it tracks early bound generics, i.e. `struct Foo<T>(T)`
-/// needs `T` substituted immediately. This type primarily exists to avoid forgetting to call
-/// `subst`.
+/// needs `T` instantiated immediately. This type primarily exists to avoid forgetting to call
+/// `instantiate`.
///
-/// If you don't have anything to `subst`, you may be looking for
-/// [`subst_identity`](EarlyBinder::subst_identity) or [`skip_binder`](EarlyBinder::skip_binder).
+/// If you don't have anything to `instantiate`, you may be looking for
+/// [`instantiate_identity`](EarlyBinder::instantiate_identity) or [`skip_binder`](EarlyBinder::skip_binder).
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Encodable, Decodable, HashStable)]
pub struct EarlyBinder<T> {
value: T,
}
-/// For early binders, you should first call `subst` before using any visitors.
+/// For early binders, you should first call `instantiate` before using any visitors.
impl<'tcx, T> !TypeFoldable<TyCtxt<'tcx>> for ty::EarlyBinder<T> {}
impl<'tcx, T> !TypeVisitable<TyCtxt<'tcx>> for ty::EarlyBinder<T> {}
@@ -591,7 +581,7 @@ impl<T> EarlyBinder<T> {
/// This can be used to extract data that does not depend on generic parameters
/// (e.g., getting the `DefId` of the inner value or getting the number of
/// arguments of an `FnSig`). Otherwise, consider using
- /// [`subst_identity`](EarlyBinder::subst_identity).
+ /// [`instantiate_identity`](EarlyBinder::instantiate_identity).
///
/// To skip the binder on `x: &EarlyBinder<T>` to obtain `&T`, leverage
/// [`EarlyBinder::as_ref`](EarlyBinder::as_ref): `x.as_ref().skip_binder()`.
@@ -620,35 +610,35 @@ impl<'tcx, 's, I: IntoIterator> EarlyBinder<I>
where
I::Item: TypeFoldable<TyCtxt<'tcx>>,
{
- pub fn subst_iter(
+ pub fn iter_instantiated(
self,
tcx: TyCtxt<'tcx>,
- substs: &'s [GenericArg<'tcx>],
- ) -> SubstIter<'s, 'tcx, I> {
- SubstIter { it: self.value.into_iter(), tcx, substs }
+ args: &'s [GenericArg<'tcx>],
+ ) -> IterInstantiated<'s, 'tcx, I> {
+ IterInstantiated { it: self.value.into_iter(), tcx, args }
}
- /// Similar to [`subst_identity`](EarlyBinder::subst_identity),
+ /// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
/// but on an iterator of `TypeFoldable` values.
- pub fn subst_identity_iter(self) -> I::IntoIter {
+ pub fn instantiate_identity_iter(self) -> I::IntoIter {
self.value.into_iter()
}
}
-pub struct SubstIter<'s, 'tcx, I: IntoIterator> {
+pub struct IterInstantiated<'s, 'tcx, I: IntoIterator> {
it: I::IntoIter,
tcx: TyCtxt<'tcx>,
- substs: &'s [GenericArg<'tcx>],
+ args: &'s [GenericArg<'tcx>],
}
-impl<'tcx, I: IntoIterator> Iterator for SubstIter<'_, 'tcx, I>
+impl<'tcx, I: IntoIterator> Iterator for IterInstantiated<'_, 'tcx, I>
where
I::Item: TypeFoldable<TyCtxt<'tcx>>,
{
type Item = I::Item;
fn next(&mut self) -> Option<Self::Item> {
- Some(EarlyBinder { value: self.it.next()? }.subst(self.tcx, self.substs))
+ Some(EarlyBinder { value: self.it.next()? }.instantiate(self.tcx, self.args))
}
fn size_hint(&self) -> (usize, Option<usize>) {
@@ -656,17 +646,17 @@ where
}
}
-impl<'tcx, I: IntoIterator> DoubleEndedIterator for SubstIter<'_, 'tcx, I>
+impl<'tcx, I: IntoIterator> DoubleEndedIterator for IterInstantiated<'_, 'tcx, I>
where
I::IntoIter: DoubleEndedIterator,
I::Item: TypeFoldable<TyCtxt<'tcx>>,
{
fn next_back(&mut self) -> Option<Self::Item> {
- Some(EarlyBinder { value: self.it.next_back()? }.subst(self.tcx, self.substs))
+ Some(EarlyBinder { value: self.it.next_back()? }.instantiate(self.tcx, self.args))
}
}
-impl<'tcx, I: IntoIterator> ExactSizeIterator for SubstIter<'_, 'tcx, I>
+impl<'tcx, I: IntoIterator> ExactSizeIterator for IterInstantiated<'_, 'tcx, I>
where
I::IntoIter: ExactSizeIterator,
I::Item: TypeFoldable<TyCtxt<'tcx>>,
@@ -678,28 +668,30 @@ where
I::Item: Deref,
<I::Item as Deref>::Target: Copy + TypeFoldable<TyCtxt<'tcx>>,
{
- pub fn subst_iter_copied(
+ pub fn iter_instantiated_copied(
self,
tcx: TyCtxt<'tcx>,
- substs: &'s [GenericArg<'tcx>],
- ) -> SubstIterCopied<'s, 'tcx, I> {
- SubstIterCopied { it: self.value.into_iter(), tcx, substs }
+ args: &'s [GenericArg<'tcx>],
+ ) -> IterInstantiatedCopied<'s, 'tcx, I> {
+ IterInstantiatedCopied { it: self.value.into_iter(), tcx, args }
}
- /// Similar to [`subst_identity`](EarlyBinder::subst_identity),
+ /// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
/// but on an iterator of values that deref to a `TypeFoldable`.
- pub fn subst_identity_iter_copied(self) -> impl Iterator<Item = <I::Item as Deref>::Target> {
+ pub fn instantiate_identity_iter_copied(
+ self,
+ ) -> impl Iterator<Item = <I::Item as Deref>::Target> {
self.value.into_iter().map(|v| *v)
}
}
-pub struct SubstIterCopied<'a, 'tcx, I: IntoIterator> {
+pub struct IterInstantiatedCopied<'a, 'tcx, I: IntoIterator> {
it: I::IntoIter,
tcx: TyCtxt<'tcx>,
- substs: &'a [GenericArg<'tcx>],
+ args: &'a [GenericArg<'tcx>],
}
-impl<'tcx, I: IntoIterator> Iterator for SubstIterCopied<'_, 'tcx, I>
+impl<'tcx, I: IntoIterator> Iterator for IterInstantiatedCopied<'_, 'tcx, I>
where
I::Item: Deref,
<I::Item as Deref>::Target: Copy + TypeFoldable<TyCtxt<'tcx>>,
@@ -707,7 +699,7 @@ where
type Item = <I::Item as Deref>::Target;
fn next(&mut self) -> Option<Self::Item> {
- self.it.next().map(|value| EarlyBinder { value: *value }.subst(self.tcx, self.substs))
+ self.it.next().map(|value| EarlyBinder { value: *value }.instantiate(self.tcx, self.args))
}
fn size_hint(&self) -> (usize, Option<usize>) {
@@ -715,18 +707,20 @@ where
}
}
-impl<'tcx, I: IntoIterator> DoubleEndedIterator for SubstIterCopied<'_, 'tcx, I>
+impl<'tcx, I: IntoIterator> DoubleEndedIterator for IterInstantiatedCopied<'_, 'tcx, I>
where
I::IntoIter: DoubleEndedIterator,
I::Item: Deref,
<I::Item as Deref>::Target: Copy + TypeFoldable<TyCtxt<'tcx>>,
{
fn next_back(&mut self) -> Option<Self::Item> {
- self.it.next_back().map(|value| EarlyBinder { value: *value }.subst(self.tcx, self.substs))
+ self.it
+ .next_back()
+ .map(|value| EarlyBinder { value: *value }.instantiate(self.tcx, self.args))
}
}
-impl<'tcx, I: IntoIterator> ExactSizeIterator for SubstIterCopied<'_, 'tcx, I>
+impl<'tcx, I: IntoIterator> ExactSizeIterator for IterInstantiatedCopied<'_, 'tcx, I>
where
I::IntoIter: ExactSizeIterator,
I::Item: Deref,
@@ -757,20 +751,20 @@ impl<T: Iterator> Iterator for EarlyBinderIter<T> {
}
impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>>> ty::EarlyBinder<T> {
- pub fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> T {
- let mut folder = SubstFolder { tcx, substs, binders_passed: 0 };
+ pub fn instantiate(self, tcx: TyCtxt<'tcx>, args: &[GenericArg<'tcx>]) -> T {
+ let mut folder = ArgFolder { tcx, args, binders_passed: 0 };
self.value.fold_with(&mut folder)
}
- /// Makes the identity substitution `T0 => T0, ..., TN => TN`.
+ /// Makes the identity replacement `T0 => T0, ..., TN => TN`.
/// Conceptually, this converts universally bound variables into placeholders
/// when inside of a given item.
///
/// For example, consider `for<T> fn foo<T>(){ .. }`:
/// - Outside of `foo`, `T` is bound (represented by the presence of `EarlyBinder`).
/// - Inside of the body of `foo`, we treat `T` as a placeholder by calling
- /// `subst_identity` to discharge the `EarlyBinder`.
- pub fn subst_identity(self) -> T {
+ /// `instantiate_identity` to discharge the `EarlyBinder`.
+ pub fn instantiate_identity(self) -> T {
self.value
}
@@ -783,15 +777,15 @@ impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>>> ty::EarlyBinder<T> {
///////////////////////////////////////////////////////////////////////////
// The actual substitution engine itself is a type folder.
-struct SubstFolder<'a, 'tcx> {
+struct ArgFolder<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
- substs: &'a [GenericArg<'tcx>],
+ args: &'a [GenericArg<'tcx>],
/// Number of region binders we have passed through while doing the substitution
binders_passed: u32,
}
-impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for SubstFolder<'a, 'tcx> {
+impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for ArgFolder<'a, 'tcx> {
#[inline]
fn interner(&self) -> TyCtxt<'tcx> {
self.tcx
@@ -810,12 +804,12 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for SubstFolder<'a, 'tcx> {
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
#[cold]
#[inline(never)]
- fn region_param_out_of_range(data: ty::EarlyBoundRegion, substs: &[GenericArg<'_>]) -> ! {
+ fn region_param_out_of_range(data: ty::EarlyBoundRegion, args: &[GenericArg<'_>]) -> ! {
bug!(
- "Region parameter out of range when substituting in region {} (index={}, substs = {:?})",
+ "Region parameter out of range when substituting in region {} (index={}, args = {:?})",
data.name,
data.index,
- substs,
+ args,
)
}
@@ -837,11 +831,11 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for SubstFolder<'a, 'tcx> {
// the specialized routine `ty::replace_late_regions()`.
match *r {
ty::ReEarlyBound(data) => {
- let rk = self.substs.get(data.index as usize).map(|k| k.unpack());
+ let rk = self.args.get(data.index as usize).map(|k| k.unpack());
match rk {
Some(GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
Some(other) => region_param_invalid(data, other),
- None => region_param_out_of_range(data, self.substs),
+ None => region_param_out_of_range(data, self.args),
}
}
ty::ReLateBound(..)
@@ -874,10 +868,10 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for SubstFolder<'a, 'tcx> {
}
}
-impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
+impl<'a, 'tcx> ArgFolder<'a, 'tcx> {
fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> {
- // Look up the type in the substitutions. It really should be in there.
- let opt_ty = self.substs.get(p.index as usize).map(|k| k.unpack());
+ // Look up the type in the args. It really should be in there.
+ let opt_ty = self.args.get(p.index as usize).map(|k| k.unpack());
let ty = match opt_ty {
Some(GenericArgKind::Type(ty)) => ty,
Some(kind) => self.type_param_expected(p, source_ty, kind),
@@ -891,12 +885,12 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
#[inline(never)]
fn type_param_expected(&self, p: ty::ParamTy, ty: Ty<'tcx>, kind: GenericArgKind<'tcx>) -> ! {
bug!(
- "expected type for `{:?}` ({:?}/{}) but found {:?} when substituting, substs={:?}",
+ "expected type for `{:?}` ({:?}/{}) but found {:?} when substituting, args={:?}",
p,
ty,
p.index,
kind,
- self.substs,
+ self.args,
)
}
@@ -904,17 +898,17 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
#[inline(never)]
fn type_param_out_of_range(&self, p: ty::ParamTy, ty: Ty<'tcx>) -> ! {
bug!(
- "type parameter `{:?}` ({:?}/{}) out of range when substituting, substs={:?}",
+ "type parameter `{:?}` ({:?}/{}) out of range when substituting, args={:?}",
p,
ty,
p.index,
- self.substs,
+ self.args,
)
}
fn const_for_param(&self, p: ParamConst, source_ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
- // Look up the const in the substitutions. It really should be in there.
- let opt_ct = self.substs.get(p.index as usize).map(|k| k.unpack());
+ // Look up the const in the args. It really should be in there.
+ let opt_ct = self.args.get(p.index as usize).map(|k| k.unpack());
let ct = match opt_ct {
Some(GenericArgKind::Const(ct)) => ct,
Some(kind) => self.const_param_expected(p, source_ct, kind),
@@ -933,12 +927,12 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
kind: GenericArgKind<'tcx>,
) -> ! {
bug!(
- "expected const for `{:?}` ({:?}/{}) but found {:?} when substituting substs={:?}",
+ "expected const for `{:?}` ({:?}/{}) but found {:?} when substituting args={:?}",
p,
ct,
p.index,
kind,
- self.substs,
+ self.args,
)
}
@@ -946,11 +940,11 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
#[inline(never)]
fn const_param_out_of_range(&self, p: ty::ParamConst, ct: ty::Const<'tcx>) -> ! {
bug!(
- "const parameter `{:?}` ({:?}/{}) out of range when substituting substs={:?}",
+ "const parameter `{:?}` ({:?}/{}) out of range when substituting args={:?}",
p,
ct,
p.index,
- self.substs,
+ self.args,
)
}
@@ -1022,13 +1016,13 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
}
}
-/// Stores the user-given substs to reach some fully qualified path
+/// Stores the user-given args to reach some fully qualified path
/// (e.g., `<T>::Item` or `<T as Trait>::Item`).
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
-pub struct UserSubsts<'tcx> {
- /// The substitutions for the item as given by the user.
- pub substs: SubstsRef<'tcx>,
+pub struct UserArgs<'tcx> {
+ /// The args for the item as given by the user.
+ pub args: GenericArgsRef<'tcx>,
/// The self type, in the case of a `<T>::Item` path (when applied
/// to an inherent impl). See `UserSelfTy` below.
@@ -1048,7 +1042,7 @@ pub struct UserSubsts<'tcx> {
/// when you then have a path like `<Foo<&'static u32>>::method`,
/// this struct would carry the `DefId` of the impl along with the
/// self type `Foo<u32>`. Then we can instantiate the parameters of
-/// the impl (with the substs from `UserSubsts`) and apply those to
+/// the impl (with the args from `UserArgs`) and apply those to
/// the self type, giving `Foo<?A>`. Finally, we unify that with
/// the self type here, which contains `?A` to be `&'static u32`
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs
index 6c7125c4c..70a35f137 100644
--- a/compiler/rustc_middle/src/ty/generics.rs
+++ b/compiler/rustc_middle/src/ty/generics.rs
@@ -1,5 +1,5 @@
use crate::ty;
-use crate::ty::{EarlyBinder, SubstsRef};
+use crate::ty::{EarlyBinder, GenericArgsRef};
use rustc_ast as ast;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefId;
@@ -97,14 +97,14 @@ impl GenericParamDef {
pub fn to_error<'tcx>(
&self,
tcx: TyCtxt<'tcx>,
- preceding_substs: &[ty::GenericArg<'tcx>],
+ preceding_args: &[ty::GenericArg<'tcx>],
) -> ty::GenericArg<'tcx> {
match &self.kind {
ty::GenericParamDefKind::Lifetime => ty::Region::new_error_misc(tcx).into(),
ty::GenericParamDefKind::Type { .. } => Ty::new_misc_error(tcx).into(),
ty::GenericParamDefKind::Const { .. } => ty::Const::new_misc_error(
tcx,
- tcx.type_of(self.def_id).subst(tcx, preceding_substs),
+ tcx.type_of(self.def_id).instantiate(tcx, preceding_args),
)
.into(),
}
@@ -136,7 +136,7 @@ pub struct Generics {
pub has_self: bool,
pub has_late_bound_regions: Option<Span>,
- // The index of the host effect when substituted. (i.e. might be index to parent substs)
+ // The index of the host effect when substituted. (i.e. might be index to parent args)
pub host_effect_index: Option<usize>,
}
@@ -278,14 +278,14 @@ impl<'tcx> Generics {
})
}
- /// Returns the substs corresponding to the generic parameters
+ /// Returns the args corresponding to the generic parameters
/// of this item, excluding `Self`.
///
/// **This should only be used for diagnostics purposes.**
- pub fn own_substs_no_defaults(
+ pub fn own_args_no_defaults(
&'tcx self,
tcx: TyCtxt<'tcx>,
- substs: &'tcx [ty::GenericArg<'tcx>],
+ args: &'tcx [ty::GenericArg<'tcx>],
) -> &'tcx [ty::GenericArg<'tcx>] {
let mut own_params = self.parent_count..self.count();
if self.has_self && self.parent.is_none() {
@@ -304,22 +304,22 @@ impl<'tcx> Generics {
.rev()
.take_while(|param| {
param.default_value(tcx).is_some_and(|default| {
- default.subst(tcx, substs) == substs[param.index as usize]
+ default.instantiate(tcx, args) == args[param.index as usize]
})
})
.count();
- &substs[own_params]
+ &args[own_params]
}
- /// Returns the substs corresponding to the generic parameters of this item, excluding `Self`.
+ /// Returns the args corresponding to the generic parameters of this item, excluding `Self`.
///
/// **This should only be used for diagnostics purposes.**
- pub fn own_substs(
+ pub fn own_args(
&'tcx self,
- substs: &'tcx [ty::GenericArg<'tcx>],
+ args: &'tcx [ty::GenericArg<'tcx>],
) -> &'tcx [ty::GenericArg<'tcx>] {
- let own = &substs[self.parent_count..][..self.params.len()];
+ let own = &args[self.parent_count..][..self.params.len()];
if self.has_self && self.parent.is_none() { &own[1..] } else { &own }
}
}
@@ -335,19 +335,19 @@ impl<'tcx> GenericPredicates<'tcx> {
pub fn instantiate(
&self,
tcx: TyCtxt<'tcx>,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
) -> InstantiatedPredicates<'tcx> {
let mut instantiated = InstantiatedPredicates::empty();
- self.instantiate_into(tcx, &mut instantiated, substs);
+ self.instantiate_into(tcx, &mut instantiated, args);
instantiated
}
pub fn instantiate_own(
&self,
tcx: TyCtxt<'tcx>,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
) -> impl Iterator<Item = (Clause<'tcx>, Span)> + DoubleEndedIterator + ExactSizeIterator {
- EarlyBinder::bind(self.predicates).subst_iter_copied(tcx, substs)
+ EarlyBinder::bind(self.predicates).iter_instantiated_copied(tcx, args)
}
#[instrument(level = "debug", skip(self, tcx))]
@@ -355,14 +355,14 @@ impl<'tcx> GenericPredicates<'tcx> {
&self,
tcx: TyCtxt<'tcx>,
instantiated: &mut InstantiatedPredicates<'tcx>,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
) {
if let Some(def_id) = self.parent {
- tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs);
+ tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, args);
}
- instantiated
- .predicates
- .extend(self.predicates.iter().map(|(p, _)| EarlyBinder::bind(*p).subst(tcx, substs)));
+ instantiated.predicates.extend(
+ self.predicates.iter().map(|(p, _)| EarlyBinder::bind(*p).instantiate(tcx, args)),
+ );
instantiated.spans.extend(self.predicates.iter().map(|(_, sp)| *sp));
}
diff --git a/compiler/rustc_middle/src/ty/impls_ty.rs b/compiler/rustc_middle/src/ty/impls_ty.rs
index 02baa395c..b03874a90 100644
--- a/compiler/rustc_middle/src/ty/impls_ty.rs
+++ b/compiler/rustc_middle/src/ty/impls_ty.rs
@@ -67,7 +67,7 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for SimplifiedType {
}
}
-impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::subst::GenericArg<'tcx> {
+impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ty::GenericArg<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
self.unpack().hash_stable(hcx, hasher);
}
diff --git a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs
index 295cb1464..f278cace9 100644
--- a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs
+++ b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs
@@ -19,7 +19,7 @@ pub enum InhabitedPredicate<'tcx> {
/// type has restricted visibility.
NotInModule(DefId),
/// Inhabited if some generic type is inhabited.
- /// These are replaced by calling [`Self::subst`].
+ /// These are replaced by calling [`Self::instantiate`].
GenericType(Ty<'tcx>),
/// A AND B
And(&'tcx [InhabitedPredicate<'tcx>; 2]),
@@ -162,14 +162,14 @@ impl<'tcx> InhabitedPredicate<'tcx> {
}
/// Replaces generic types with its corresponding predicate
- pub fn subst(self, tcx: TyCtxt<'tcx>, substs: ty::SubstsRef<'tcx>) -> Self {
- self.subst_opt(tcx, substs).unwrap_or(self)
+ pub fn instantiate(self, tcx: TyCtxt<'tcx>, args: ty::GenericArgsRef<'tcx>) -> Self {
+ self.instantiate_opt(tcx, args).unwrap_or(self)
}
- fn subst_opt(self, tcx: TyCtxt<'tcx>, substs: ty::SubstsRef<'tcx>) -> Option<Self> {
+ fn instantiate_opt(self, tcx: TyCtxt<'tcx>, args: ty::GenericArgsRef<'tcx>) -> Option<Self> {
match self {
Self::ConstIsZero(c) => {
- let c = ty::EarlyBinder::bind(c).subst(tcx, substs);
+ let c = ty::EarlyBinder::bind(c).instantiate(tcx, args);
let pred = match c.try_to_target_usize(tcx) {
Some(0) => Self::True,
Some(1..) => Self::False,
@@ -178,17 +178,17 @@ impl<'tcx> InhabitedPredicate<'tcx> {
Some(pred)
}
Self::GenericType(t) => {
- Some(ty::EarlyBinder::bind(t).subst(tcx, substs).inhabited_predicate(tcx))
+ Some(ty::EarlyBinder::bind(t).instantiate(tcx, args).inhabited_predicate(tcx))
}
- Self::And(&[a, b]) => match a.subst_opt(tcx, substs) {
- None => b.subst_opt(tcx, substs).map(|b| a.and(tcx, b)),
+ Self::And(&[a, b]) => match a.instantiate_opt(tcx, args) {
+ None => b.instantiate_opt(tcx, args).map(|b| a.and(tcx, b)),
Some(InhabitedPredicate::False) => Some(InhabitedPredicate::False),
- Some(a) => Some(a.and(tcx, b.subst_opt(tcx, substs).unwrap_or(b))),
+ Some(a) => Some(a.and(tcx, b.instantiate_opt(tcx, args).unwrap_or(b))),
},
- Self::Or(&[a, b]) => match a.subst_opt(tcx, substs) {
- None => b.subst_opt(tcx, substs).map(|b| a.or(tcx, b)),
+ Self::Or(&[a, b]) => match a.instantiate_opt(tcx, args) {
+ None => b.instantiate_opt(tcx, args).map(|b| a.or(tcx, b)),
Some(InhabitedPredicate::True) => Some(InhabitedPredicate::True),
- Some(a) => Some(a.or(tcx, b.subst_opt(tcx, substs).unwrap_or(b))),
+ Some(a) => Some(a.or(tcx, b.instantiate_opt(tcx, args).unwrap_or(b))),
},
_ => None,
}
diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs
index b92d84152..4dac6891b 100644
--- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs
+++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs
@@ -58,7 +58,7 @@ pub(crate) fn provide(providers: &mut Providers) {
}
/// Returns an `InhabitedPredicate` that is generic over type parameters and
-/// requires calling [`InhabitedPredicate::subst`]
+/// requires calling [`InhabitedPredicate::instantiate`]
fn inhabited_predicate_adt(tcx: TyCtxt<'_>, def_id: DefId) -> InhabitedPredicate<'_> {
if let Some(def_id) = def_id.as_local() {
if matches!(tcx.representability(def_id), ty::Representability::Infinite) {
@@ -87,7 +87,7 @@ impl<'tcx> VariantDef {
InhabitedPredicate::all(
tcx,
self.fields.iter().map(|field| {
- let pred = tcx.type_of(field.did).subst_identity().inhabited_predicate(tcx);
+ let pred = tcx.type_of(field.did).instantiate_identity().inhabited_predicate(tcx);
if adt.is_enum() {
return pred;
}
@@ -114,8 +114,8 @@ impl<'tcx> Ty<'tcx> {
Never => InhabitedPredicate::False,
Param(_) | Alias(ty::Projection, _) => InhabitedPredicate::GenericType(self),
// FIXME(inherent_associated_types): Most likely we can just map to `GenericType` like above.
- // However it's unclear if the substs passed to `InhabitedPredicate::subst` are of the correct
- // format, i.e. don't contain parent substs. If you hit this case, please verify this beforehand.
+ // However it's unclear if the args passed to `InhabitedPredicate::instantiate` are of the correct
+ // format, i.e. don't contain parent args. If you hit this case, please verify this beforehand.
Alias(ty::Inherent, _) => {
bug!("unimplemented: inhabitedness checking for inherent projections")
}
@@ -189,7 +189,7 @@ impl<'tcx> Ty<'tcx> {
/// N.B. this query should only be called through `Ty::inhabited_predicate`
fn inhabited_predicate_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> InhabitedPredicate<'tcx> {
match *ty.kind() {
- Adt(adt, substs) => tcx.inhabited_predicate_adt(adt.did()).subst(tcx, substs),
+ Adt(adt, args) => tcx.inhabited_predicate_adt(adt.did()).instantiate(tcx, args),
Tuple(tys) => {
InhabitedPredicate::all(tcx, tys.iter().map(|ty| ty.inhabited_predicate(tcx)))
diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs
index ae57e954f..8913bf76d 100644
--- a/compiler/rustc_middle/src/ty/instance.rs
+++ b/compiler/rustc_middle/src/ty/instance.rs
@@ -1,7 +1,7 @@
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable};
-use crate::ty::{EarlyBinder, InternalSubsts, SubstsRef, TypeVisitableExt};
+use crate::ty::{EarlyBinder, GenericArgs, GenericArgsRef, TypeVisitableExt};
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::Namespace;
use rustc_hir::def_id::{CrateNum, DefId};
@@ -16,13 +16,13 @@ use std::fmt;
/// A monomorphized `InstanceDef`.
///
/// Monomorphization happens on-the-fly and no monomorphized MIR is ever created. Instead, this type
-/// simply couples a potentially generic `InstanceDef` with some substs, and codegen and const eval
+/// simply couples a potentially generic `InstanceDef` with some args, and codegen and const eval
/// will do all required substitution as they run.
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)]
#[derive(HashStable, Lift, TypeFoldable, TypeVisitable)]
pub struct Instance<'tcx> {
pub def: InstanceDef<'tcx>,
- pub substs: SubstsRef<'tcx>,
+ pub args: GenericArgsRef<'tcx>,
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
@@ -115,7 +115,7 @@ impl<'tcx> Instance<'tcx> {
/// lifetimes erased, allowing a `ParamEnv` to be specified for use during normalization.
pub fn ty(&self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Ty<'tcx> {
let ty = tcx.type_of(self.def.def_id());
- tcx.subst_and_normalize_erasing_regions(self.substs, param_env, ty)
+ tcx.subst_and_normalize_erasing_regions(self.args, param_env, ty)
}
/// Finds a crate that contains a monomorphization of this instance that
@@ -139,13 +139,13 @@ impl<'tcx> Instance<'tcx> {
}
// If this a non-generic instance, it cannot be a shared monomorphization.
- self.substs.non_erasable_generics().next()?;
+ self.args.non_erasable_generics().next()?;
match self.def {
InstanceDef::Item(def) => tcx
.upstream_monomorphizations_for(def)
- .and_then(|monos| monos.get(&self.substs).cloned()),
- InstanceDef::DropGlue(_, Some(_)) => tcx.upstream_drop_glue_for(self.substs),
+ .and_then(|monos| monos.get(&self.args).cloned()),
+ InstanceDef::DropGlue(_, Some(_)) => tcx.upstream_drop_glue_for(self.args),
_ => None,
}
}
@@ -265,8 +265,8 @@ impl<'tcx> InstanceDef<'tcx> {
}
/// Returns `true` when the MIR body associated with this instance should be monomorphized
- /// by its users (e.g. codegen or miri) by substituting the `substs` from `Instance` (see
- /// `Instance::substs_for_mir_body`).
+ /// by its users (e.g. codegen or miri) by substituting the `args` from `Instance` (see
+ /// `Instance::args_for_mir_body`).
///
/// Otherwise, returns `false` only for some kinds of shims where the construction of the MIR
/// body should perform necessary substitutions.
@@ -294,10 +294,10 @@ fn fmt_instance(
type_length: rustc_session::Limit,
) -> fmt::Result {
ty::tls::with(|tcx| {
- let substs = tcx.lift(instance.substs).expect("could not lift for printing");
+ let args = tcx.lift(instance.args).expect("could not lift for printing");
let s = FmtPrinter::new_with_limit(tcx, Namespace::ValueNS, type_length)
- .print_def_path(instance.def_id(), substs)?
+ .print_def_path(instance.def_id(), args)?
.into_buffer();
f.write_str(&s)
})?;
@@ -308,13 +308,13 @@ fn fmt_instance(
InstanceDef::ReifyShim(_) => write!(f, " - shim(reify)"),
InstanceDef::ThreadLocalShim(_) => write!(f, " - shim(tls)"),
InstanceDef::Intrinsic(_) => write!(f, " - intrinsic"),
- InstanceDef::Virtual(_, num) => write!(f, " - virtual#{}", num),
- InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({})", ty),
+ InstanceDef::Virtual(_, num) => write!(f, " - virtual#{num}"),
+ InstanceDef::FnPtrShim(_, ty) => write!(f, " - shim({ty})"),
InstanceDef::ClosureOnceShim { .. } => write!(f, " - shim"),
InstanceDef::DropGlue(_, None) => write!(f, " - shim(None)"),
- InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({}))", ty),
- InstanceDef::CloneShim(_, ty) => write!(f, " - shim({})", ty),
- InstanceDef::FnPtrAddrShim(_, ty) => write!(f, " - shim({})", ty),
+ InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({ty}))"),
+ InstanceDef::CloneShim(_, ty) => write!(f, " - shim({ty})"),
+ InstanceDef::FnPtrAddrShim(_, ty) => write!(f, " - shim({ty})"),
}
}
@@ -333,18 +333,16 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
}
impl<'tcx> Instance<'tcx> {
- pub fn new(def_id: DefId, substs: SubstsRef<'tcx>) -> Instance<'tcx> {
+ pub fn new(def_id: DefId, args: GenericArgsRef<'tcx>) -> Instance<'tcx> {
assert!(
- !substs.has_escaping_bound_vars(),
- "substs of instance {:?} not normalized for codegen: {:?}",
- def_id,
- substs
+ !args.has_escaping_bound_vars(),
+ "args of instance {def_id:?} not normalized for codegen: {args:?}"
);
- Instance { def: InstanceDef::Item(def_id), substs }
+ Instance { def: InstanceDef::Item(def_id), args }
}
pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {
- let substs = InternalSubsts::for_item(tcx, def_id, |param, _| match param.kind {
+ let args = GenericArgs::for_item(tcx, def_id, |param, _| match param.kind {
ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
ty::GenericParamDefKind::Type { .. } => {
bug!("Instance::mono: {:?} has type parameters", def_id)
@@ -354,7 +352,7 @@ impl<'tcx> Instance<'tcx> {
}
});
- Instance::new(def_id, substs)
+ Instance::new(def_id, args)
}
#[inline]
@@ -362,7 +360,7 @@ impl<'tcx> Instance<'tcx> {
self.def.def_id()
}
- /// Resolves a `(def_id, substs)` pair to an (optional) instance -- most commonly,
+ /// Resolves a `(def_id, args)` pair to an (optional) instance -- most commonly,
/// this is used to find the precise code that will run for a trait method invocation,
/// if known.
///
@@ -390,29 +388,29 @@ impl<'tcx> Instance<'tcx> {
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
def_id: DefId,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
// All regions in the result of this query are erased, so it's
// fine to erase all of the input regions.
- // HACK(eddyb) erase regions in `substs` first, so that `param_env.and(...)`
+ // HACK(eddyb) erase regions in `args` first, so that `param_env.and(...)`
// below is more likely to ignore the bounds in scope (e.g. if the only
- // generic parameters mentioned by `substs` were lifetime ones).
- let substs = tcx.erase_regions(substs);
- tcx.resolve_instance(tcx.erase_regions(param_env.and((def_id, substs))))
+ // generic parameters mentioned by `args` were lifetime ones).
+ let args = tcx.erase_regions(args);
+ tcx.resolve_instance(tcx.erase_regions(param_env.and((def_id, args))))
}
pub fn expect_resolve(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
def_id: DefId,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
) -> Instance<'tcx> {
- match ty::Instance::resolve(tcx, param_env, def_id, substs) {
+ match ty::Instance::resolve(tcx, param_env, def_id, args) {
Ok(Some(instance)) => instance,
instance => bug!(
"failed to resolve instance for {}: {instance:#?}",
- tcx.def_path_str_with_substs(def_id, substs)
+ tcx.def_path_str_with_args(def_id, args)
),
}
}
@@ -421,12 +419,12 @@ impl<'tcx> Instance<'tcx> {
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
def_id: DefId,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
) -> Option<Instance<'tcx>> {
- debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
+ debug!("resolve(def_id={:?}, args={:?})", def_id, args);
// Use either `resolve_closure` or `resolve_for_vtable`
- assert!(!tcx.is_closure(def_id), "Called `resolve_for_fn_ptr` on closure: {:?}", def_id);
- Instance::resolve(tcx, param_env, def_id, substs).ok().flatten().map(|mut resolved| {
+ assert!(!tcx.is_closure(def_id), "Called `resolve_for_fn_ptr` on closure: {def_id:?}");
+ Instance::resolve(tcx, param_env, def_id, args).ok().flatten().map(|mut resolved| {
match resolved.def {
InstanceDef::Item(def) if resolved.def.requires_caller_location(tcx) => {
debug!(" => fn pointer created for function with #[track_caller]");
@@ -447,18 +445,18 @@ impl<'tcx> Instance<'tcx> {
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
def_id: DefId,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
) -> Option<Instance<'tcx>> {
- debug!("resolve_for_vtable(def_id={:?}, substs={:?})", def_id, substs);
- let fn_sig = tcx.fn_sig(def_id).subst_identity();
+ debug!("resolve_for_vtable(def_id={:?}, args={:?})", def_id, args);
+ let fn_sig = tcx.fn_sig(def_id).instantiate_identity();
let is_vtable_shim = !fn_sig.inputs().skip_binder().is_empty()
&& fn_sig.input(0).skip_binder().is_param(0)
&& tcx.generics_of(def_id).has_self;
if is_vtable_shim {
debug!(" => associated item with unsizeable self: Self");
- Some(Instance { def: InstanceDef::VTableShim(def_id), substs })
+ Some(Instance { def: InstanceDef::VTableShim(def_id), args })
} else {
- Instance::resolve(tcx, param_env, def_id, substs).ok().flatten().map(|mut resolved| {
+ Instance::resolve(tcx, param_env, def_id, args).ok().flatten().map(|mut resolved| {
match resolved.def {
InstanceDef::Item(def) => {
// We need to generate a shim when we cannot guarantee that
@@ -489,12 +487,12 @@ impl<'tcx> Instance<'tcx> {
{
if tcx.is_closure(def) {
debug!(" => vtable fn pointer created for closure with #[track_caller]: {:?} for method {:?} {:?}",
- def, def_id, substs);
+ def, def_id, args);
// Create a shim for the `FnOnce/FnMut/Fn` method we are calling
// - unlike functions, invoking a closure always goes through a
// trait.
- resolved = Instance { def: InstanceDef::ReifyShim(def_id), substs };
+ resolved = Instance { def: InstanceDef::ReifyShim(def_id), args };
} else {
debug!(
" => vtable fn pointer created for function with #[track_caller]: {:?}", def
@@ -518,28 +516,28 @@ impl<'tcx> Instance<'tcx> {
pub fn resolve_closure(
tcx: TyCtxt<'tcx>,
def_id: DefId,
- substs: ty::SubstsRef<'tcx>,
+ args: ty::GenericArgsRef<'tcx>,
requested_kind: ty::ClosureKind,
) -> Option<Instance<'tcx>> {
- let actual_kind = substs.as_closure().kind();
+ let actual_kind = args.as_closure().kind();
match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
- Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs),
- _ => Some(Instance::new(def_id, substs)),
+ Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, args),
+ _ => Some(Instance::new(def_id, args)),
}
}
pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
let def_id = tcx.require_lang_item(LangItem::DropInPlace, None);
- let substs = tcx.mk_substs(&[ty.into()]);
- Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs)
+ let args = tcx.mk_args(&[ty.into()]);
+ Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args)
}
#[instrument(level = "debug", skip(tcx), ret)]
pub fn fn_once_adapter_instance(
tcx: TyCtxt<'tcx>,
closure_did: DefId,
- substs: ty::SubstsRef<'tcx>,
+ args: ty::GenericArgsRef<'tcx>,
) -> Option<Instance<'tcx>> {
let fn_once = tcx.require_lang_item(LangItem::FnOnce, None);
let call_once = tcx
@@ -552,30 +550,30 @@ impl<'tcx> Instance<'tcx> {
tcx.codegen_fn_attrs(closure_did).flags.contains(CodegenFnAttrFlags::TRACK_CALLER);
let def = ty::InstanceDef::ClosureOnceShim { call_once, track_caller };
- let self_ty = Ty::new_closure(tcx, closure_did, substs);
+ let self_ty = Ty::new_closure(tcx, closure_did, args);
- let sig = substs.as_closure().sig();
+ let sig = args.as_closure().sig();
let sig =
tcx.try_normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig).ok()?;
assert_eq!(sig.inputs().len(), 1);
- let substs = tcx.mk_substs_trait(self_ty, [sig.inputs()[0].into()]);
+ let args = tcx.mk_args_trait(self_ty, [sig.inputs()[0].into()]);
debug!(?self_ty, ?sig);
- Some(Instance { def, substs })
+ Some(Instance { def, args })
}
/// Depending on the kind of `InstanceDef`, the MIR body associated with an
/// instance is expressed in terms of the generic parameters of `self.def_id()`, and in other
/// cases the MIR body is expressed in terms of the types found in the substitution array.
/// In the former case, we want to substitute those generic types and replace them with the
- /// values from the substs when monomorphizing the function body. But in the latter case, we
+ /// values from the args when monomorphizing the function body. But in the latter case, we
/// don't want to do that substitution, since it has already been done effectively.
///
- /// This function returns `Some(substs)` in the former case and `None` otherwise -- i.e., if
+ /// This function returns `Some(args)` in the former case and `None` otherwise -- i.e., if
/// this function returns `None`, then the MIR body does not require substitution during
/// codegen.
- fn substs_for_mir_body(&self) -> Option<SubstsRef<'tcx>> {
- self.def.has_polymorphic_mir_body().then_some(self.substs)
+ fn args_for_mir_body(&self) -> Option<GenericArgsRef<'tcx>> {
+ self.def.has_polymorphic_mir_body().then_some(self.args)
}
pub fn subst_mir<T>(&self, tcx: TyCtxt<'tcx>, v: EarlyBinder<&T>) -> T
@@ -583,10 +581,10 @@ impl<'tcx> Instance<'tcx> {
T: TypeFoldable<TyCtxt<'tcx>> + Copy,
{
let v = v.map_bound(|v| *v);
- if let Some(substs) = self.substs_for_mir_body() {
- v.subst(tcx, substs)
+ if let Some(args) = self.args_for_mir_body() {
+ v.instantiate(tcx, args)
} else {
- v.subst_identity()
+ v.instantiate_identity()
}
}
@@ -600,8 +598,8 @@ impl<'tcx> Instance<'tcx> {
where
T: TypeFoldable<TyCtxt<'tcx>> + Clone,
{
- if let Some(substs) = self.substs_for_mir_body() {
- tcx.subst_and_normalize_erasing_regions(substs, param_env, v)
+ if let Some(args) = self.args_for_mir_body() {
+ tcx.subst_and_normalize_erasing_regions(args, param_env, v)
} else {
tcx.normalize_erasing_regions(param_env, v.skip_binder())
}
@@ -617,14 +615,14 @@ impl<'tcx> Instance<'tcx> {
where
T: TypeFoldable<TyCtxt<'tcx>> + Clone,
{
- if let Some(substs) = self.substs_for_mir_body() {
- tcx.try_subst_and_normalize_erasing_regions(substs, param_env, v)
+ if let Some(args) = self.args_for_mir_body() {
+ tcx.try_subst_and_normalize_erasing_regions(args, param_env, v)
} else {
tcx.try_normalize_erasing_regions(param_env, v.skip_binder())
}
}
- /// Returns a new `Instance` where generic parameters in `instance.substs` are replaced by
+ /// Returns a new `Instance` where generic parameters in `instance.args` are replaced by
/// identity parameters if they are determined to be unused in `instance.def`.
pub fn polymorphize(self, tcx: TyCtxt<'tcx>) -> Self {
debug!("polymorphize: running polymorphization analysis");
@@ -632,18 +630,18 @@ impl<'tcx> Instance<'tcx> {
return self;
}
- let polymorphized_substs = polymorphize(tcx, self.def, self.substs);
- debug!("polymorphize: self={:?} polymorphized_substs={:?}", self, polymorphized_substs);
- Self { def: self.def, substs: polymorphized_substs }
+ let polymorphized_args = polymorphize(tcx, self.def, self.args);
+ debug!("polymorphize: self={:?} polymorphized_args={:?}", self, polymorphized_args);
+ Self { def: self.def, args: polymorphized_args }
}
}
fn polymorphize<'tcx>(
tcx: TyCtxt<'tcx>,
instance: ty::InstanceDef<'tcx>,
- substs: SubstsRef<'tcx>,
-) -> SubstsRef<'tcx> {
- debug!("polymorphize({:?}, {:?})", instance, substs);
+ args: GenericArgsRef<'tcx>,
+) -> GenericArgsRef<'tcx> {
+ debug!("polymorphize({:?}, {:?})", instance, args);
let unused = tcx.unused_generic_params(instance);
debug!("polymorphize: unused={:?}", unused);
@@ -653,9 +651,9 @@ fn polymorphize<'tcx>(
// multiple mono items (and eventually symbol clashes).
let def_id = instance.def_id();
let upvars_ty = if tcx.is_closure(def_id) {
- Some(substs.as_closure().tupled_upvars_ty())
+ Some(args.as_closure().tupled_upvars_ty())
} else if tcx.type_of(def_id).skip_binder().is_generator() {
- Some(substs.as_generator().tupled_upvars_ty())
+ Some(args.as_generator().tupled_upvars_ty())
} else {
None
};
@@ -674,22 +672,22 @@ fn polymorphize<'tcx>(
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
debug!("fold_ty: ty={:?}", ty);
match *ty.kind() {
- ty::Closure(def_id, substs) => {
- let polymorphized_substs =
- polymorphize(self.tcx, ty::InstanceDef::Item(def_id), substs);
- if substs == polymorphized_substs {
+ ty::Closure(def_id, args) => {
+ let polymorphized_args =
+ polymorphize(self.tcx, ty::InstanceDef::Item(def_id), args);
+ if args == polymorphized_args {
ty
} else {
- Ty::new_closure(self.tcx, def_id, polymorphized_substs)
+ Ty::new_closure(self.tcx, def_id, polymorphized_args)
}
}
- ty::Generator(def_id, substs, movability) => {
- let polymorphized_substs =
- polymorphize(self.tcx, ty::InstanceDef::Item(def_id), substs);
- if substs == polymorphized_substs {
+ ty::Generator(def_id, args, movability) => {
+ let polymorphized_args =
+ polymorphize(self.tcx, ty::InstanceDef::Item(def_id), args);
+ if args == polymorphized_args {
ty
} else {
- Ty::new_generator(self.tcx, def_id, polymorphized_substs, movability)
+ Ty::new_generator(self.tcx, def_id, polymorphized_args, movability)
}
}
_ => ty.super_fold_with(self),
@@ -697,7 +695,7 @@ fn polymorphize<'tcx>(
}
}
- InternalSubsts::for_item(tcx, def_id, |param, _| {
+ GenericArgs::for_item(tcx, def_id, |param, _| {
let is_unused = unused.is_unused(param.index);
debug!("polymorphize: param={:?} is_unused={:?}", param, is_unused);
match param.kind {
@@ -706,7 +704,7 @@ fn polymorphize<'tcx>(
// ..and has upvars..
has_upvars &&
// ..and this param has the same type as the tupled upvars..
- upvars_ty == Some(substs[param.index as usize].expect_ty()) => {
+ upvars_ty == Some(args[param.index as usize].expect_ty()) => {
// ..then double-check that polymorphization marked it used..
debug_assert!(!is_unused);
// ..and polymorphize any closures/generators captured as upvars.
@@ -725,7 +723,7 @@ fn polymorphize<'tcx>(
tcx.mk_param_from_def(param),
// Otherwise, use the parameter as before.
- _ => substs[param.index as usize],
+ _ => args[param.index as usize],
}
})
}
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs
index d95b05ef7..e362b3477 100644
--- a/compiler/rustc_middle/src/ty/layout.rs
+++ b/compiler/rustc_middle/src/ty/layout.rs
@@ -10,7 +10,7 @@ use rustc_hir::def_id::DefId;
use rustc_index::IndexVec;
use rustc_session::config::OptLevel;
use rustc_span::symbol::{sym, Symbol};
-use rustc_span::{Span, DUMMY_SP};
+use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
use rustc_target::abi::call::FnAbi;
use rustc_target::abi::*;
use rustc_target::spec::{abi::Abi as SpecAbi, HasTargetSpec, PanicStrategy, Target};
@@ -212,6 +212,7 @@ pub enum LayoutError<'tcx> {
Unknown(Ty<'tcx>),
SizeOverflow(Ty<'tcx>),
NormalizationFailure(Ty<'tcx>, NormalizationError<'tcx>),
+ ReferencesError(ErrorGuaranteed),
Cycle,
}
@@ -224,6 +225,7 @@ impl<'tcx> LayoutError<'tcx> {
SizeOverflow(_) => middle_values_too_big,
NormalizationFailure(_, _) => middle_cannot_be_normalized,
Cycle => middle_cycle,
+ ReferencesError(_) => middle_layout_references_error,
}
}
@@ -237,6 +239,7 @@ impl<'tcx> LayoutError<'tcx> {
E::NormalizationFailure { ty, failure_ty: e.get_type_for_failure() }
}
Cycle => E::Cycle,
+ ReferencesError(_) => E::ReferencesError,
}
}
}
@@ -246,9 +249,9 @@ impl<'tcx> LayoutError<'tcx> {
impl<'tcx> fmt::Display for LayoutError<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
- LayoutError::Unknown(ty) => write!(f, "the type `{}` has an unknown layout", ty),
+ LayoutError::Unknown(ty) => write!(f, "the type `{ty}` has an unknown layout"),
LayoutError::SizeOverflow(ty) => {
- write!(f, "values of the type `{}` are too big for the current architecture", ty)
+ write!(f, "values of the type `{ty}` are too big for the current architecture")
}
LayoutError::NormalizationFailure(t, e) => write!(
f,
@@ -257,6 +260,7 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
e.get_type_for_failure()
),
LayoutError::Cycle => write!(f, "a cycle occurred during layout computation"),
+ LayoutError::ReferencesError(_) => write!(f, "the type has an unknown layout"),
}
}
}
@@ -323,7 +327,8 @@ impl<'tcx> SizeSkeleton<'tcx> {
Err(
e @ LayoutError::Cycle
| e @ LayoutError::SizeOverflow(_)
- | e @ LayoutError::NormalizationFailure(..),
+ | e @ LayoutError::NormalizationFailure(..)
+ | e @ LayoutError::ReferencesError(_),
) => return Err(e),
};
@@ -374,7 +379,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
}
}
- ty::Adt(def, substs) => {
+ ty::Adt(def, args) => {
// Only newtypes and enums w/ nullable pointer optimization.
if def.is_union() || def.variants().is_empty() || def.variants().len() > 2 {
return Err(err);
@@ -385,7 +390,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
let i = VariantIdx::from_usize(i);
let fields =
def.variant(i).fields.iter().map(|field| {
- SizeSkeleton::compute(field.ty(tcx, substs), tcx, param_env)
+ SizeSkeleton::compute(field.ty(tcx, args), tcx, param_env)
});
let mut ptr = None;
for field in fields {
@@ -741,9 +746,9 @@ where
let fields = match this.ty.kind() {
ty::Adt(def, _) if def.variants().is_empty() =>
- bug!("for_variant called on zero-variant enum"),
+ bug!("for_variant called on zero-variant enum {}", this.ty),
ty::Adt(def, _) => def.variant(variant_index).fields.len(),
- _ => bug!(),
+ _ => bug!("`ty_and_layout_for_variant` on unexpected type {}", this.ty),
};
tcx.mk_layout(LayoutS {
variants: Variants::Single { index: variant_index },
@@ -755,6 +760,8 @@ where
largest_niche: None,
align: tcx.data_layout.i8_align,
size: Size::ZERO,
+ max_repr_align: None,
+ unadjusted_abi_align: tcx.data_layout.i8_align.abi,
})
}
@@ -861,9 +868,9 @@ where
// offers better information than `std::ptr::metadata::VTable`,
// and we rely on this layout information to trigger a panic in
// `std::mem::uninitialized::<&dyn Trait>()`, for example.
- if let ty::Adt(def, substs) = metadata.kind()
+ if let ty::Adt(def, args) = metadata.kind()
&& Some(def.did()) == tcx.lang_items().dyn_metadata()
- && substs.type_at(0).is_trait()
+ && args.type_at(0).is_trait()
{
mk_dyn_vtable()
} else {
@@ -885,16 +892,15 @@ where
ty::Str => TyMaybeWithLayout::Ty(tcx.types.u8),
// Tuples, generators and closures.
- ty::Closure(_, ref substs) => field_ty_or_layout(
- TyAndLayout { ty: substs.as_closure().tupled_upvars_ty(), ..this },
+ ty::Closure(_, ref args) => field_ty_or_layout(
+ TyAndLayout { ty: args.as_closure().tupled_upvars_ty(), ..this },
cx,
i,
),
- ty::Generator(def_id, ref substs, _) => match this.variants {
+ ty::Generator(def_id, ref args, _) => match this.variants {
Variants::Single { index } => TyMaybeWithLayout::Ty(
- substs
- .as_generator()
+ args.as_generator()
.state_tys(def_id, tcx)
.nth(index.as_usize())
.unwrap()
@@ -905,18 +911,18 @@ where
if i == tag_field {
return TyMaybeWithLayout::TyAndLayout(tag_layout(tag));
}
- TyMaybeWithLayout::Ty(substs.as_generator().prefix_tys().nth(i).unwrap())
+ TyMaybeWithLayout::Ty(args.as_generator().prefix_tys()[i])
}
},
ty::Tuple(tys) => TyMaybeWithLayout::Ty(tys[i]),
// ADTs.
- ty::Adt(def, substs) => {
+ ty::Adt(def, args) => {
match this.variants {
Variants::Single { index } => {
let field = &def.variant(index).fields[FieldIdx::from_usize(i)];
- TyMaybeWithLayout::Ty(field.ty(tcx, substs))
+ TyMaybeWithLayout::Ty(field.ty(tcx, args))
}
// Discriminant field for enums (where applicable).
@@ -1233,6 +1239,8 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) ->
| EfiApi
| AvrInterrupt
| AvrNonBlockingInterrupt
+ | RiscvInterruptM
+ | RiscvInterruptS
| CCmseNonSecureCall
| Wasm
| PlatformIntrinsic
diff --git a/compiler/rustc_middle/src/ty/list.rs b/compiler/rustc_middle/src/ty/list.rs
index 71911a5a6..7a32cfb10 100644
--- a/compiler/rustc_middle/src/ty/list.rs
+++ b/compiler/rustc_middle/src/ty/list.rs
@@ -1,6 +1,7 @@
use crate::arena::Arena;
use rustc_data_structures::aligned::{align_of, Aligned};
use rustc_serialize::{Encodable, Encoder};
+use rustc_type_ir::{InferCtxtLike, OptWithInfcx};
use std::alloc::Layout;
use std::cmp::Ordering;
use std::fmt;
@@ -119,6 +120,14 @@ impl<T: fmt::Debug> fmt::Debug for List<T> {
(**self).fmt(f)
}
}
+impl<'tcx, T: super::DebugWithInfcx<TyCtxt<'tcx>>> super::DebugWithInfcx<TyCtxt<'tcx>> for List<T> {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
+ fmt::Debug::fmt(&this.map(|this| this.as_slice()), f)
+ }
+}
impl<S: Encoder, T: Encodable<S>> Encodable<S> for List<T> {
#[inline]
@@ -202,6 +211,8 @@ unsafe impl<T: Sync> Sync for List<T> {}
// We need this since `List` uses extern type `OpaqueListContents`.
#[cfg(parallel_compiler)]
use rustc_data_structures::sync::DynSync;
+
+use super::TyCtxt;
#[cfg(parallel_compiler)]
unsafe impl<T: DynSync> DynSync for List<T> {}
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index aa8bfd317..1274f427e 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -28,6 +28,7 @@ use crate::ty::fast_reject::SimplifiedType;
use crate::ty::util::Discr;
pub use adt::*;
pub use assoc::*;
+pub use generic_args::*;
pub use generics::*;
use rustc_ast as ast;
use rustc_ast::node_id::NodeMap;
@@ -53,7 +54,7 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{ExpnId, ExpnKind, Span};
use rustc_target::abi::{Align, FieldIdx, Integer, IntegerType, VariantIdx};
pub use rustc_target::abi::{ReprFlags, ReprOptions};
-pub use subst::*;
+pub use rustc_type_ir::{DebugWithInfcx, InferCtxtLike, OptWithInfcx};
pub use vtable::*;
use std::fmt::Debug;
@@ -81,8 +82,7 @@ pub use self::binding::BindingMode::*;
pub use self::closure::{
is_ancestor_or_same_capture, place_to_string_for_capture, BorrowKind, CaptureInfo,
CapturedPlace, ClosureKind, ClosureTypeInfo, MinCaptureInformationMap, MinCaptureList,
- RootVariableMinCaptureList, UpvarCapture, UpvarCaptureMap, UpvarId, UpvarListMap, UpvarPath,
- CAPTURE_STRUCT_LOCAL,
+ RootVariableMinCaptureList, UpvarCapture, UpvarId, UpvarPath, CAPTURE_STRUCT_LOCAL,
};
pub use self::consts::{
Const, ConstData, ConstInt, Expr, InferConst, ScalarInt, UnevaluatedConst, ValTree,
@@ -97,12 +97,12 @@ pub use self::rvalue_scopes::RvalueScopes;
pub use self::sty::BoundRegionKind::*;
pub use self::sty::{
AliasTy, Article, Binder, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, BoundVar,
- BoundVariableKind, CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstKind, ConstVid,
+ BoundVariableKind, CanonicalPolyFnSig, ClosureArgs, ClosureArgsParts, ConstKind, ConstVid,
EarlyBoundRegion, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig,
- FreeRegion, GenSig, GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts,
- InlineConstSubstsParts, ParamConst, ParamTy, PolyExistentialPredicate,
- PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef,
- Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarSubsts, VarianceDiagInfo,
+ FreeRegion, GenSig, GeneratorArgs, GeneratorArgsParts, InlineConstArgs, InlineConstArgsParts,
+ ParamConst, ParamTy, PolyExistentialPredicate, PolyExistentialProjection,
+ PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef, Region, RegionKind, RegionVid,
+ TraitRef, TyKind, TypeAndMut, UpvarArgs, VarianceDiagInfo,
};
pub use self::trait_def::TraitDef;
pub use self::typeck_results::{
@@ -126,7 +126,6 @@ pub mod layout;
pub mod normalize_erasing_regions;
pub mod print;
pub mod relate;
-pub mod subst;
pub mod trait_def;
pub mod util;
pub mod visit;
@@ -140,6 +139,7 @@ mod consts;
mod context;
mod diagnostics;
mod erase_regions;
+mod generic_args;
mod generics;
mod impls_ty;
mod instance;
@@ -148,7 +148,7 @@ mod opaque_types;
mod parameterized;
mod rvalue_scopes;
mod structural_impls;
-#[cfg_attr(not(bootstrap), allow(hidden_glob_reexports))]
+#[allow(hidden_glob_reexports)]
mod sty;
mod typeck_results;
@@ -238,7 +238,7 @@ pub struct ImplHeader<'tcx> {
pub impl_def_id: DefId,
pub self_ty: Ty<'tcx>,
pub trait_ref: Option<TraitRef<'tcx>>,
- pub predicates: Vec<Predicate<'tcx>>,
+ pub predicates: Vec<(Predicate<'tcx>, Span)>,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable)]
@@ -355,8 +355,8 @@ impl TyCtxt<'_> {
#[inline]
#[track_caller]
- pub fn local_parent(self, id: LocalDefId) -> LocalDefId {
- self.parent(id.to_def_id()).expect_local()
+ pub fn local_parent(self, id: impl Into<LocalDefId>) -> LocalDefId {
+ self.parent(id.into().to_def_id()).expect_local()
}
pub fn is_descendant_of(self, mut descendant: DefId, ancestor: DefId) -> bool {
@@ -498,11 +498,9 @@ impl<'tcx> Predicate<'tcx> {
.map_bound(|kind| match kind {
PredicateKind::Clause(ClauseKind::Trait(TraitPredicate {
trait_ref,
- constness,
polarity,
})) => Some(PredicateKind::Clause(ClauseKind::Trait(TraitPredicate {
trait_ref,
- constness,
polarity: polarity.flip()?,
}))),
@@ -513,19 +511,6 @@ impl<'tcx> Predicate<'tcx> {
Some(tcx.mk_predicate(kind))
}
- pub fn without_const(mut self, tcx: TyCtxt<'tcx>) -> Self {
- if let PredicateKind::Clause(ClauseKind::Trait(TraitPredicate { trait_ref, constness, polarity })) = self.kind().skip_binder()
- && constness != BoundConstness::NotConst
- {
- self = tcx.mk_predicate(self.kind().rebind(PredicateKind::Clause(ClauseKind::Trait(TraitPredicate {
- trait_ref,
- constness: BoundConstness::NotConst,
- polarity,
- }))));
- }
- self
- }
-
#[instrument(level = "debug", skip(tcx), ret)]
pub fn is_coinductive(self, tcx: TyCtxt<'tcx>) -> bool {
match self.kind().skip_binder() {
@@ -629,10 +614,6 @@ impl<'tcx> Clause<'tcx> {
None
}
}
-
- pub fn without_const(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
- self.as_predicate().without_const(tcx).expect_clause()
- }
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
@@ -676,9 +657,9 @@ pub enum PredicateKind<'tcx> {
ObjectSafe(DefId),
/// No direct syntax. May be thought of as `where T: FnFoo<...>`
- /// for some substitutions `...` and `T` being a closure type.
+ /// for some generic args `...` and `T` being a closure type.
/// Satisfied (or refuted) once we know the closure's kind.
- ClosureKind(DefId, SubstsRef<'tcx>, ClosureKind),
+ ClosureKind(DefId, GenericArgsRef<'tcx>, ClosureKind),
/// `T1 <: T2`
///
@@ -813,15 +794,15 @@ impl<'tcx> Clause<'tcx> {
// this trick achieves that).
// Working through the second example:
- // trait_ref: for<'x> T: Foo1<'^0.0>; substs: [T, '^0.0]
- // predicate: for<'b> Self: Bar1<'a, '^0.0>; substs: [Self, 'a, '^0.0]
+ // trait_ref: for<'x> T: Foo1<'^0.0>; args: [T, '^0.0]
+ // predicate: for<'b> Self: Bar1<'a, '^0.0>; args: [Self, 'a, '^0.0]
// We want to end up with:
// for<'x, 'b> T: Bar1<'^0.0, '^0.1>
// To do this:
// 1) We must shift all bound vars in predicate by the length
// of trait ref's bound vars. So, we would end up with predicate like
// Self: Bar1<'a, '^0.1>
- // 2) We can then apply the trait substs to this, ending up with
+ // 2) We can then apply the trait args to this, ending up with
// T: Bar1<'^0.0, '^0.1>
// 3) Finally, to create the final bound vars, we concatenate the bound
// vars of the trait ref with those of the predicate:
@@ -833,7 +814,7 @@ impl<'tcx> Clause<'tcx> {
let shifted_pred =
tcx.shift_bound_var_indices(trait_bound_vars.len(), bound_pred.skip_binder());
// 2) Self: Bar1<'a, '^0.1> -> T: Bar1<'^0.0, '^0.1>
- let new = EarlyBinder::bind(shifted_pred).subst(tcx, trait_ref.skip_binder().substs);
+ let new = EarlyBinder::bind(shifted_pred).instantiate(tcx, trait_ref.skip_binder().args);
// 3) ['x] + ['b] -> ['x, 'b]
let bound_vars =
tcx.mk_bound_variable_kinds_from_iter(trait_bound_vars.iter().chain(pred_bound_vars));
@@ -852,8 +833,6 @@ impl<'tcx> Clause<'tcx> {
pub struct TraitPredicate<'tcx> {
pub trait_ref: TraitRef<'tcx>,
- pub constness: BoundConstness,
-
/// If polarity is Positive: we are proving that the trait is implemented.
///
/// If polarity is Negative: we are proving that a negative impl of this trait
@@ -867,20 +846,6 @@ pub struct TraitPredicate<'tcx> {
pub type PolyTraitPredicate<'tcx> = ty::Binder<'tcx, TraitPredicate<'tcx>>;
impl<'tcx> TraitPredicate<'tcx> {
- pub fn remap_constness(&mut self, param_env: &mut ParamEnv<'tcx>) {
- *param_env = param_env.with_constness(self.constness.and(param_env.constness()))
- }
-
- /// Remap the constness of this predicate before emitting it for diagnostics.
- pub fn remap_constness_diag(&mut self, param_env: ParamEnv<'tcx>) {
- // this is different to `remap_constness` that callees want to print this predicate
- // in case of selection errors. `T: ~const Drop` bounds cannot end up here when the
- // param_env is not const because it is always satisfied in non-const contexts.
- if let hir::Constness::NotConst = param_env.constness() {
- self.constness = ty::BoundConstness::NotConst;
- }
- }
-
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
Self { trait_ref: self.trait_ref.with_self_ty(tcx, self_ty), ..self }
}
@@ -892,24 +857,6 @@ impl<'tcx> TraitPredicate<'tcx> {
pub fn self_ty(self) -> Ty<'tcx> {
self.trait_ref.self_ty()
}
-
- #[inline]
- pub fn is_const_if_const(self) -> bool {
- self.constness == BoundConstness::ConstIfConst
- }
-
- pub fn is_constness_satisfied_by(self, constness: hir::Constness) -> bool {
- match (self.constness, constness) {
- (BoundConstness::NotConst, _)
- | (BoundConstness::ConstIfConst, hir::Constness::Const) => true,
- (BoundConstness::ConstIfConst, hir::Constness::NotConst) => false,
- }
- }
-
- pub fn without_const(mut self) -> Self {
- self.constness = BoundConstness::NotConst;
- self
- }
}
impl<'tcx> PolyTraitPredicate<'tcx> {
@@ -922,19 +869,6 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
self.map_bound(|trait_ref| trait_ref.self_ty())
}
- /// Remap the constness of this predicate before emitting it for diagnostics.
- pub fn remap_constness_diag(&mut self, param_env: ParamEnv<'tcx>) {
- *self = self.map_bound(|mut p| {
- p.remap_constness_diag(param_env);
- p
- });
- }
-
- #[inline]
- pub fn is_const_if_const(self) -> bool {
- self.skip_binder().is_const_if_const()
- }
-
#[inline]
pub fn polarity(self) -> ImplPolarity {
self.skip_binder().polarity
@@ -980,9 +914,9 @@ pub struct Term<'tcx> {
impl Debug for Term<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let data = if let Some(ty) = self.ty() {
- format!("Term::Ty({:?})", ty)
+ format!("Term::Ty({ty:?})")
} else if let Some(ct) = self.ct() {
- format!("Term::Ct({:?})", ct)
+ format!("Term::Ct({ct:?})")
} else {
unreachable!()
};
@@ -1079,7 +1013,7 @@ impl<'tcx> Term<'tcx> {
_ => None,
},
TermKind::Const(ct) => match ct.kind() {
- ConstKind::Unevaluated(uv) => Some(tcx.mk_alias_ty(uv.def, uv.substs)),
+ ConstKind::Unevaluated(uv) => Some(tcx.mk_alias_ty(uv.def, uv.args)),
_ => None,
},
}
@@ -1309,7 +1243,7 @@ impl<'tcx> ToPredicate<'tcx> for TraitRef<'tcx> {
impl<'tcx> ToPredicate<'tcx, TraitPredicate<'tcx>> for TraitRef<'tcx> {
#[inline(always)]
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> TraitPredicate<'tcx> {
- self.without_const()
+ TraitPredicate { trait_ref: self, polarity: ImplPolarity::Positive }
}
}
@@ -1350,7 +1284,6 @@ impl<'tcx> ToPredicate<'tcx, PolyTraitPredicate<'tcx>> for Binder<'tcx, TraitRef
fn to_predicate(self, _: TyCtxt<'tcx>) -> PolyTraitPredicate<'tcx> {
self.map_bound(|trait_ref| TraitPredicate {
trait_ref,
- constness: ty::BoundConstness::NotConst,
polarity: ty::ImplPolarity::Positive,
})
}
@@ -1381,24 +1314,49 @@ impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyTraitPredicate<'tcx> {
}
}
+impl<'tcx> ToPredicate<'tcx> for OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>> {
+ fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
+ ty::Binder::dummy(PredicateKind::Clause(ClauseKind::RegionOutlives(self))).to_predicate(tcx)
+ }
+}
+
impl<'tcx> ToPredicate<'tcx> for PolyRegionOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(|p| PredicateKind::Clause(ClauseKind::RegionOutlives(p))).to_predicate(tcx)
}
}
+impl<'tcx> ToPredicate<'tcx> for OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>> {
+ fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
+ ty::Binder::dummy(PredicateKind::Clause(ClauseKind::TypeOutlives(self))).to_predicate(tcx)
+ }
+}
+
impl<'tcx> ToPredicate<'tcx> for PolyTypeOutlivesPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(|p| PredicateKind::Clause(ClauseKind::TypeOutlives(p))).to_predicate(tcx)
}
}
+impl<'tcx> ToPredicate<'tcx> for ProjectionPredicate<'tcx> {
+ fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
+ ty::Binder::dummy(PredicateKind::Clause(ClauseKind::Projection(self))).to_predicate(tcx)
+ }
+}
+
impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
self.map_bound(|p| PredicateKind::Clause(ClauseKind::Projection(p))).to_predicate(tcx)
}
}
+impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for ProjectionPredicate<'tcx> {
+ fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
+ let p: Predicate<'tcx> = self.to_predicate(tcx);
+ p.expect_clause()
+ }
+}
+
impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for PolyProjectionPredicate<'tcx> {
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Clause<'tcx> {
let p: Predicate<'tcx> = self.to_predicate(tcx);
@@ -1558,7 +1516,7 @@ impl<'a, 'tcx> IntoIterator for &'a InstantiatedPredicates<'tcx> {
#[derive(TypeFoldable, TypeVisitable)]
pub struct OpaqueTypeKey<'tcx> {
pub def_id: LocalDefId,
- pub substs: SubstsRef<'tcx>,
+ pub args: GenericArgsRef<'tcx>,
}
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, HashStable, TyEncodable, TyDecodable)]
@@ -1629,21 +1587,21 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
// typeck errors have subpar spans for opaque types, so delay error reporting until borrowck.
ignore_errors: bool,
) -> Self {
- let OpaqueTypeKey { def_id, substs } = opaque_type_key;
+ let OpaqueTypeKey { def_id, args } = opaque_type_key;
- // Use substs to build up a reverse map from regions to their
+ // Use args to build up a reverse map from regions to their
// identity mappings. This is necessary because of `impl
// Trait` lifetimes are computed by replacing existing
// lifetimes with 'static and remapping only those used in the
// `impl Trait` return type, resulting in the parameters
// shifting.
- let id_substs = InternalSubsts::identity_for_item(tcx, def_id);
- debug!(?id_substs);
+ let id_args = GenericArgs::identity_for_item(tcx, def_id);
+ debug!(?id_args);
- // This zip may have several times the same lifetime in `substs` paired with a different
- // lifetime from `id_substs`. Simply `collect`ing the iterator is the correct behaviour:
+ // This zip may have several times the same lifetime in `args` paired with a different
+ // lifetime from `id_args`. Simply `collect`ing the iterator is the correct behaviour:
// it will pick the last one, which is the one we introduced in the impl-trait desugaring.
- let map = substs.iter().zip(id_substs).collect();
+ let map = args.iter().zip(id_args).collect();
debug!("map = {:#?}", map);
// Convert the type from the function into a type valid outside
@@ -1700,15 +1658,12 @@ pub struct ParamEnv<'tcx> {
#[derive(Copy, Clone)]
struct ParamTag {
reveal: traits::Reveal,
- constness: hir::Constness,
}
impl_tag! {
impl Tag for ParamTag;
- ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::NotConst },
- ParamTag { reveal: traits::Reveal::All, constness: hir::Constness::NotConst },
- ParamTag { reveal: traits::Reveal::UserFacing, constness: hir::Constness::Const },
- ParamTag { reveal: traits::Reveal::All, constness: hir::Constness::Const },
+ ParamTag { reveal: traits::Reveal::UserFacing },
+ ParamTag { reveal: traits::Reveal::All },
}
impl<'tcx> fmt::Debug for ParamEnv<'tcx> {
@@ -1716,7 +1671,6 @@ impl<'tcx> fmt::Debug for ParamEnv<'tcx> {
f.debug_struct("ParamEnv")
.field("caller_bounds", &self.caller_bounds())
.field("reveal", &self.reveal())
- .field("constness", &self.constness())
.finish()
}
}
@@ -1725,7 +1679,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ParamEnv<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
self.caller_bounds().hash_stable(hcx, hasher);
self.reveal().hash_stable(hcx, hasher);
- self.constness().hash_stable(hcx, hasher);
}
}
@@ -1737,7 +1690,6 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ParamEnv<'tcx> {
Ok(ParamEnv::new(
self.caller_bounds().try_fold_with(folder)?,
self.reveal().try_fold_with(folder)?,
- self.constness(),
))
}
}
@@ -1756,7 +1708,7 @@ impl<'tcx> ParamEnv<'tcx> {
/// type-checking.
#[inline]
pub fn empty() -> Self {
- Self::new(List::empty(), Reveal::UserFacing, hir::Constness::NotConst)
+ Self::new(List::empty(), Reveal::UserFacing)
}
#[inline]
@@ -1769,16 +1721,6 @@ impl<'tcx> ParamEnv<'tcx> {
self.packed.tag().reveal
}
- #[inline]
- pub fn constness(self) -> hir::Constness {
- self.packed.tag().constness
- }
-
- #[inline]
- pub fn is_const(self) -> bool {
- self.packed.tag().constness == hir::Constness::Const
- }
-
/// Construct a trait environment with no where-clauses in scope
/// where the values of all `impl Trait` and other hidden types
/// are revealed. This is suitable for monomorphized, post-typeck
@@ -1788,17 +1730,13 @@ impl<'tcx> ParamEnv<'tcx> {
/// or invoke `param_env.with_reveal_all()`.
#[inline]
pub fn reveal_all() -> Self {
- Self::new(List::empty(), Reveal::All, hir::Constness::NotConst)
+ Self::new(List::empty(), Reveal::All)
}
/// Construct a trait environment with the given set of predicates.
#[inline]
- pub fn new(
- caller_bounds: &'tcx List<Clause<'tcx>>,
- reveal: Reveal,
- constness: hir::Constness,
- ) -> Self {
- ty::ParamEnv { packed: CopyTaggedPtr::new(caller_bounds, ParamTag { reveal, constness }) }
+ pub fn new(caller_bounds: &'tcx List<Clause<'tcx>>, reveal: Reveal) -> Self {
+ ty::ParamEnv { packed: CopyTaggedPtr::new(caller_bounds, ParamTag { reveal }) }
}
pub fn with_user_facing(mut self) -> Self {
@@ -1806,29 +1744,6 @@ impl<'tcx> ParamEnv<'tcx> {
self
}
- #[inline]
- pub fn with_constness(mut self, constness: hir::Constness) -> Self {
- self.packed.set_tag(ParamTag { constness, ..self.packed.tag() });
- self
- }
-
- #[inline]
- pub fn with_const(mut self) -> Self {
- self.packed.set_tag(ParamTag { constness: hir::Constness::Const, ..self.packed.tag() });
- self
- }
-
- #[inline]
- pub fn without_const(mut self) -> Self {
- self.packed.set_tag(ParamTag { constness: hir::Constness::NotConst, ..self.packed.tag() });
- self
- }
-
- #[inline]
- pub fn remap_constness_with(&mut self, mut constness: ty::BoundConstness) {
- *self = self.with_constness(constness.and(self.constness()))
- }
-
/// Returns a new parameter environment with the same clauses, but
/// which "reveals" the true results of projections in all cases
/// (even for associated types that are specializable). This is
@@ -1843,17 +1758,13 @@ impl<'tcx> ParamEnv<'tcx> {
return self;
}
- ParamEnv::new(
- tcx.reveal_opaque_types_in_bounds(self.caller_bounds()),
- Reveal::All,
- self.constness(),
- )
+ ParamEnv::new(tcx.reveal_opaque_types_in_bounds(self.caller_bounds()), Reveal::All)
}
/// Returns this same environment but with no caller bounds.
#[inline]
pub fn without_caller_bounds(self) -> Self {
- Self::new(List::empty(), self.reveal(), self.constness())
+ Self::new(List::empty(), self.reveal())
}
/// Creates a suitable environment in which to perform trait
@@ -1883,24 +1794,6 @@ impl<'tcx> ParamEnv<'tcx> {
}
}
-// FIXME(ecstaticmorse): Audit all occurrences of `without_const().to_predicate(tcx)` to ensure that
-// the constness of trait bounds is being propagated correctly.
-impl<'tcx> PolyTraitRef<'tcx> {
- #[inline]
- pub fn with_constness(self, constness: BoundConstness) -> PolyTraitPredicate<'tcx> {
- self.map_bound(|trait_ref| ty::TraitPredicate {
- trait_ref,
- constness,
- polarity: ty::ImplPolarity::Positive,
- })
- }
-
- #[inline]
- pub fn without_const(self) -> PolyTraitPredicate<'tcx> {
- self.with_constness(BoundConstness::NotConst)
- }
-}
-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)]
#[derive(HashStable, Lift)]
pub struct ParamEnvAnd<'tcx, T> {
@@ -2164,10 +2057,10 @@ impl Hash for FieldDef {
}
impl<'tcx> FieldDef {
- /// Returns the type of this field. The resulting type is not normalized. The `subst` is
+ /// Returns the type of this field. The resulting type is not normalized. The `arg` is
/// typically obtained via the second field of [`TyKind::Adt`].
- pub fn ty(&self, tcx: TyCtxt<'tcx>, subst: SubstsRef<'tcx>) -> Ty<'tcx> {
- tcx.type_of(self.did).subst(tcx, subst)
+ pub fn ty(&self, tcx: TyCtxt<'tcx>, arg: GenericArgsRef<'tcx>) -> Ty<'tcx> {
+ tcx.type_of(self.did).instantiate(tcx, arg)
}
/// Computes the `Ident` of this variant by looking up the `Span`
@@ -2391,8 +2284,8 @@ impl<'tcx> TyCtxt<'tcx> {
let impl_trait_ref2 = self.impl_trait_ref(def_id2);
// If either trait impl references an error, they're allowed to overlap,
// as one of them essentially doesn't exist.
- if impl_trait_ref1.is_some_and(|tr| tr.subst_identity().references_error())
- || impl_trait_ref2.is_some_and(|tr| tr.subst_identity().references_error())
+ if impl_trait_ref1.is_some_and(|tr| tr.instantiate_identity().references_error())
+ || impl_trait_ref2.is_some_and(|tr| tr.instantiate_identity().references_error())
{
return Some(ImplOverlapKind::Permitted { marker: false });
}
@@ -2682,20 +2575,6 @@ impl<'tcx> TyCtxt<'tcx> {
matches!(self.trait_of_item(def_id), Some(trait_id) if self.has_attr(trait_id, sym::const_trait))
}
- pub fn impl_trait_in_trait_parent_fn(self, mut def_id: DefId) -> DefId {
- match self.opt_rpitit_info(def_id) {
- Some(ImplTraitInTraitData::Trait { fn_def_id, .. })
- | Some(ImplTraitInTraitData::Impl { fn_def_id, .. }) => fn_def_id,
- None => {
- while let def_kind = self.def_kind(def_id) && def_kind != DefKind::AssocFn {
- debug_assert_eq!(def_kind, DefKind::ImplTraitPlaceholder);
- def_id = self.parent(def_id);
- }
- def_id
- }
- }
- }
-
/// Returns the `DefId` of the item within which the `impl Trait` is declared.
/// For type-alias-impl-trait this is the `type` alias.
/// For impl-trait-in-assoc-type this is the assoc type.
@@ -2713,33 +2592,20 @@ impl<'tcx> TyCtxt<'tcx> {
return false;
}
- let Some(item) = self.opt_associated_item(def_id) else { return false; };
+ let Some(item) = self.opt_associated_item(def_id) else {
+ return false;
+ };
if item.container != ty::AssocItemContainer::ImplContainer {
return false;
}
- let Some(trait_item_def_id) = item.trait_item_def_id else { return false; };
-
- if self.lower_impl_trait_in_trait_to_assoc_ty() {
- return !self
- .associated_types_for_impl_traits_in_associated_fn(trait_item_def_id)
- .is_empty();
- }
+ let Some(trait_item_def_id) = item.trait_item_def_id else {
+ return false;
+ };
- // FIXME(RPITIT): This does a somewhat manual walk through the signature
- // of the trait fn to look for any RPITITs, but that's kinda doing a lot
- // of work. We can probably remove this when we refactor RPITITs to be
- // associated types.
- self.fn_sig(trait_item_def_id).subst_identity().skip_binder().output().walk().any(|arg| {
- if let ty::GenericArgKind::Type(ty) = arg.unpack()
- && let ty::Alias(ty::Projection, data) = ty.kind()
- && self.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder
- {
- true
- } else {
- false
- }
- })
+ return !self
+ .associated_types_for_impl_traits_in_associated_fn(trait_item_def_id)
+ .is_empty();
}
}
diff --git a/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs b/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs
index a0c8d299f..2415d50b2 100644
--- a/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs
+++ b/compiler/rustc_middle/src/ty/normalize_erasing_regions.rs
@@ -9,7 +9,7 @@
use crate::traits::query::NoSolution;
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder};
-use crate::ty::{self, EarlyBinder, SubstsRef, Ty, TyCtxt, TypeVisitableExt};
+use crate::ty::{self, EarlyBinder, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt};
#[derive(Debug, Copy, Clone, HashStable, TyEncodable, TyDecodable)]
pub enum NormalizationError<'tcx> {
@@ -20,8 +20,8 @@ pub enum NormalizationError<'tcx> {
impl<'tcx> NormalizationError<'tcx> {
pub fn get_type_for_failure(&self) -> String {
match self {
- NormalizationError::Type(t) => format!("{}", t),
- NormalizationError::Const(c) => format!("{}", c),
+ NormalizationError::Type(t) => format!("{t}"),
+ NormalizationError::Const(c) => format!("{c}"),
}
}
}
@@ -137,7 +137,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// use `try_subst_and_normalize_erasing_regions` instead.
pub fn subst_and_normalize_erasing_regions<T>(
self,
- param_substs: SubstsRef<'tcx>,
+ param_args: GenericArgsRef<'tcx>,
param_env: ty::ParamEnv<'tcx>,
value: EarlyBinder<T>,
) -> T
@@ -146,12 +146,12 @@ impl<'tcx> TyCtxt<'tcx> {
{
debug!(
"subst_and_normalize_erasing_regions(\
- param_substs={:?}, \
+ param_args={:?}, \
value={:?}, \
param_env={:?})",
- param_substs, value, param_env,
+ param_args, value, param_env,
);
- let substituted = value.subst(self, param_substs);
+ let substituted = value.instantiate(self, param_args);
self.normalize_erasing_regions(param_env, substituted)
}
@@ -161,7 +161,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// not assume that normalization succeeds.
pub fn try_subst_and_normalize_erasing_regions<T>(
self,
- param_substs: SubstsRef<'tcx>,
+ param_args: GenericArgsRef<'tcx>,
param_env: ty::ParamEnv<'tcx>,
value: EarlyBinder<T>,
) -> Result<T, NormalizationError<'tcx>>
@@ -170,12 +170,12 @@ impl<'tcx> TyCtxt<'tcx> {
{
debug!(
"subst_and_normalize_erasing_regions(\
- param_substs={:?}, \
+ param_args={:?}, \
value={:?}, \
param_env={:?})",
- param_substs, value, param_env,
+ param_args, value, param_env,
);
- let substituted = value.subst(self, param_substs);
+ let substituted = value.instantiate(self, param_args);
self.try_normalize_erasing_regions(param_env, substituted)
}
}
diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs
index b10921eff..0ff5ac903 100644
--- a/compiler/rustc_middle/src/ty/opaque_types.rs
+++ b/compiler/rustc_middle/src/ty/opaque_types.rs
@@ -1,7 +1,7 @@
use crate::error::ConstNotUsedTraitAlias;
use crate::ty::fold::{TypeFolder, TypeSuperFoldable};
-use crate::ty::subst::{GenericArg, GenericArgKind};
use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
+use crate::ty::{GenericArg, GenericArgKind};
use rustc_data_structures::fx::FxHashMap;
use rustc_span::def_id::DefId;
use rustc_span::Span;
@@ -49,11 +49,11 @@ impl<'tcx> ReverseMapper<'tcx> {
kind.fold_with(self)
}
- fn fold_closure_substs(
+ fn fold_closure_args(
&mut self,
def_id: DefId,
- substs: ty::SubstsRef<'tcx>,
- ) -> ty::SubstsRef<'tcx> {
+ args: ty::GenericArgsRef<'tcx>,
+ ) -> ty::GenericArgsRef<'tcx> {
// I am a horrible monster and I pray for death. When
// we encounter a closure here, it is always a closure
// from within the function that we are currently
@@ -79,7 +79,7 @@ impl<'tcx> ReverseMapper<'tcx> {
// during codegen.
let generics = self.tcx.generics_of(def_id);
- self.tcx.mk_substs_from_iter(substs.iter().enumerate().map(|(index, kind)| {
+ self.tcx.mk_args_from_iter(args.iter().enumerate().map(|(index, kind)| {
if index < generics.parent_count {
// Accommodate missing regions in the parent kinds...
self.fold_kind_no_missing_regions_error(kind)
@@ -124,7 +124,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
match self.map.get(&r.into()).map(|k| k.unpack()) {
Some(GenericArgKind::Lifetime(r1)) => r1,
- Some(u) => panic!("region mapped to unexpected kind: {:?}", u),
+ Some(u) => panic!("region mapped to unexpected kind: {u:?}"),
None if self.do_not_error => self.tcx.lifetimes.re_static,
None => {
let e = self
@@ -134,9 +134,8 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
.span_label(
self.span,
format!(
- "lifetime `{}` is part of concrete type but not used in \
- parameter list of the `impl Trait` type alias",
- r
+ "lifetime `{r}` is part of concrete type but not used in \
+ parameter list of the `impl Trait` type alias"
),
)
.emit();
@@ -148,19 +147,19 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
match *ty.kind() {
- ty::Closure(def_id, substs) => {
- let substs = self.fold_closure_substs(def_id, substs);
- Ty::new_closure(self.tcx, def_id, substs)
+ ty::Closure(def_id, args) => {
+ let args = self.fold_closure_args(def_id, args);
+ Ty::new_closure(self.tcx, def_id, args)
}
- ty::Generator(def_id, substs, movability) => {
- let substs = self.fold_closure_substs(def_id, substs);
- Ty::new_generator(self.tcx, def_id, substs, movability)
+ ty::Generator(def_id, args, movability) => {
+ let args = self.fold_closure_args(def_id, args);
+ Ty::new_generator(self.tcx, def_id, args, movability)
}
- ty::GeneratorWitnessMIR(def_id, substs) => {
- let substs = self.fold_closure_substs(def_id, substs);
- Ty::new_generator_witness_mir(self.tcx, def_id, substs)
+ ty::GeneratorWitnessMIR(def_id, args) => {
+ let args = self.fold_closure_args(def_id, args);
+ Ty::new_generator_witness_mir(self.tcx, def_id, args)
}
ty::Param(param) => {
@@ -169,7 +168,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
// Found it in the substitution list; replace with the parameter from the
// opaque type.
Some(GenericArgKind::Type(t1)) => t1,
- Some(u) => panic!("type mapped to unexpected kind: {:?}", u),
+ Some(u) => panic!("type mapped to unexpected kind: {u:?}"),
None => {
debug!(?param, ?self.map);
if !self.ignore_errors {
@@ -178,9 +177,8 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
.struct_span_err(
self.span,
format!(
- "type parameter `{}` is part of concrete type but not \
- used in parameter list for the `impl Trait` type alias",
- ty
+ "type parameter `{ty}` is part of concrete type but not \
+ used in parameter list for the `impl Trait` type alias"
),
)
.emit();
@@ -205,7 +203,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
// Found it in the substitution list, replace with the parameter from the
// opaque type.
Some(GenericArgKind::Const(c1)) => c1,
- Some(u) => panic!("const mapped to unexpected kind: {:?}", u),
+ Some(u) => panic!("const mapped to unexpected kind: {u:?}"),
None => {
let guar = self
.tcx
diff --git a/compiler/rustc_middle/src/ty/parameterized.rs b/compiler/rustc_middle/src/ty/parameterized.rs
index cc2b26a5e..f1c389842 100644
--- a/compiler/rustc_middle/src/ty/parameterized.rs
+++ b/compiler/rustc_middle/src/ty/parameterized.rs
@@ -52,6 +52,7 @@ trivially_parameterized_over_tcx! {
usize,
(),
u32,
+ u64,
bool,
std::string::String,
crate::metadata::ModChild,
diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs
index 2de0a3f75..05871d0bc 100644
--- a/compiler/rustc_middle/src/ty/print/mod.rs
+++ b/compiler/rustc_middle/src/ty/print/mod.rs
@@ -42,19 +42,19 @@ pub trait Printer<'tcx>: Sized {
fn print_def_path(
self,
def_id: DefId,
- substs: &'tcx [GenericArg<'tcx>],
+ args: &'tcx [GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
- self.default_print_def_path(def_id, substs)
+ self.default_print_def_path(def_id, args)
}
fn print_impl_path(
self,
impl_def_id: DefId,
- substs: &'tcx [GenericArg<'tcx>],
+ args: &'tcx [GenericArg<'tcx>],
self_ty: Ty<'tcx>,
trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<Self::Path, Self::Error> {
- self.default_print_impl_path(impl_def_id, substs, self_ty, trait_ref)
+ self.default_print_impl_path(impl_def_id, args, self_ty, trait_ref)
}
fn print_region(self, region: ty::Region<'tcx>) -> Result<Self::Region, Self::Error>;
@@ -102,7 +102,7 @@ pub trait Printer<'tcx>: Sized {
fn default_print_def_path(
self,
def_id: DefId,
- substs: &'tcx [GenericArg<'tcx>],
+ args: &'tcx [GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
let key = self.tcx().def_key(def_id);
debug!(?key);
@@ -117,25 +117,28 @@ pub trait Printer<'tcx>: Sized {
let generics = self.tcx().generics_of(def_id);
let self_ty = self.tcx().type_of(def_id);
let impl_trait_ref = self.tcx().impl_trait_ref(def_id);
- let (self_ty, impl_trait_ref) = if substs.len() >= generics.count() {
+ let (self_ty, impl_trait_ref) = if args.len() >= generics.count() {
(
- self_ty.subst(self.tcx(), substs),
- impl_trait_ref.map(|i| i.subst(self.tcx(), substs)),
+ self_ty.instantiate(self.tcx(), args),
+ impl_trait_ref.map(|i| i.instantiate(self.tcx(), args)),
)
} else {
- (self_ty.subst_identity(), impl_trait_ref.map(|i| i.subst_identity()))
+ (
+ self_ty.instantiate_identity(),
+ impl_trait_ref.map(|i| i.instantiate_identity()),
+ )
};
- self.print_impl_path(def_id, substs, self_ty, impl_trait_ref)
+ self.print_impl_path(def_id, args, self_ty, impl_trait_ref)
}
_ => {
let parent_def_id = DefId { index: key.parent.unwrap(), ..def_id };
- let mut parent_substs = substs;
+ let mut parent_args = args;
let mut trait_qualify_parent = false;
- if !substs.is_empty() {
+ if !args.is_empty() {
let generics = self.tcx().generics_of(def_id);
- parent_substs = &substs[..generics.parent_count.min(substs.len())];
+ parent_args = &args[..generics.parent_count.min(args.len())];
match key.disambiguated_data.data {
// Closures' own generics are only captures, don't print them.
@@ -148,10 +151,10 @@ pub trait Printer<'tcx>: Sized {
// If we have any generic arguments to print, we do that
// on top of the same path, but without its own generics.
_ => {
- if !generics.params.is_empty() && substs.len() >= generics.count() {
- let args = generics.own_substs_no_defaults(self.tcx(), substs);
+ if !generics.params.is_empty() && args.len() >= generics.count() {
+ let args = generics.own_args_no_defaults(self.tcx(), args);
return self.path_generic_args(
- |cx| cx.print_def_path(def_id, parent_substs),
+ |cx| cx.print_def_path(def_id, parent_args),
args,
);
}
@@ -162,7 +165,7 @@ pub trait Printer<'tcx>: Sized {
// logic, instead of doing it when printing the child.
trait_qualify_parent = generics.has_self
&& generics.parent == Some(parent_def_id)
- && parent_substs.len() == generics.parent_count
+ && parent_args.len() == generics.parent_count
&& self.tcx().generics_of(parent_def_id).parent_count == 0;
}
@@ -172,11 +175,11 @@ pub trait Printer<'tcx>: Sized {
let trait_ref = ty::TraitRef::new(
cx.tcx(),
parent_def_id,
- parent_substs.iter().copied(),
+ parent_args.iter().copied(),
);
cx.path_qualified(trait_ref.self_ty(), Some(trait_ref))
} else {
- cx.print_def_path(parent_def_id, parent_substs)
+ cx.print_def_path(parent_def_id, parent_args)
}
},
&key.disambiguated_data,
@@ -188,7 +191,7 @@ pub trait Printer<'tcx>: Sized {
fn default_print_impl_path(
self,
impl_def_id: DefId,
- _substs: &'tcx [GenericArg<'tcx>],
+ _args: &'tcx [GenericArg<'tcx>],
self_ty: Ty<'tcx>,
impl_trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<Self::Path, Self::Error> {
@@ -326,7 +329,8 @@ impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::Const<'tcx> {
}
// This is only used by query descriptions
-pub fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
+pub fn describe_as_module(def_id: impl Into<LocalDefId>, tcx: TyCtxt<'_>) -> String {
+ let def_id = def_id.into();
if def_id.is_top_level_module() {
"top-level module".to_string()
} else {
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs
index 96cf36eb9..ac0c88468 100644
--- a/compiler/rustc_middle/src/ty/print/pretty.rs
+++ b/compiler/rustc_middle/src/ty/print/pretty.rs
@@ -11,12 +11,13 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_data_structures::sso::SsoHashSet;
use rustc_hir as hir;
use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
-use rustc_hir::def_id::{DefId, DefIdSet, CRATE_DEF_ID, LOCAL_CRATE};
+use rustc_hir::def_id::{DefId, DefIdSet, ModDefId, CRATE_DEF_ID, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPathData, DefPathDataName, DisambiguatedDefPathData};
use rustc_hir::LangItem;
use rustc_session::config::TrimmedDefPaths;
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
use rustc_session::Limit;
+use rustc_span::sym;
use rustc_span::symbol::{kw, Ident, Symbol};
use rustc_span::FileNameDisplayPreference;
use rustc_target::abi::Size;
@@ -224,9 +225,9 @@ pub trait PrettyPrinter<'tcx>:
fn print_value_path(
self,
def_id: DefId,
- substs: &'tcx [GenericArg<'tcx>],
+ args: &'tcx [GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
- self.print_def_path(def_id, substs)
+ self.print_def_path(def_id, args)
}
fn in_binder<T>(self, value: &ty::Binder<'tcx, T>) -> Result<Self, Self::Error>
@@ -325,7 +326,8 @@ pub trait PrettyPrinter<'tcx>:
{
this
.tcx()
- .module_children(visible_parent)
+ // FIXME(typed_def_id): Further propagate ModDefId
+ .module_children(ModDefId::new_unchecked(*visible_parent))
.iter()
.filter(|child| child.res.opt_def_id() == Some(def_id))
.find(|child| child.vis.is_public() && child.ident.name != kw::Underscore)
@@ -363,7 +365,7 @@ pub trait PrettyPrinter<'tcx>:
self.write_str(get_local_name(&self, symbol, parent, parent_key).as_str())?;
self.write_str("::")?;
} else if let DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::Trait
- | DefKind::TyAlias | DefKind::Fn | DefKind::Const | DefKind::Static(_) = kind
+ | DefKind::TyAlias { .. } | DefKind::Fn | DefKind::Const | DefKind::Static(_) = kind
{
} else {
// If not covered above, like for example items out of `impl` blocks, fallback.
@@ -550,7 +552,8 @@ pub trait PrettyPrinter<'tcx>:
// that's public and whose identifier isn't `_`.
let reexport = self
.tcx()
- .module_children(visible_parent)
+ // FIXME(typed_def_id): Further propagate ModDefId
+ .module_children(ModDefId::new_unchecked(visible_parent))
.iter()
.filter(|child| child.res.opt_def_id() == Some(def_id))
.find(|child| child.vis.is_public() && child.ident.name != kw::Underscore)
@@ -679,12 +682,12 @@ pub trait PrettyPrinter<'tcx>:
}
p!(")")
}
- ty::FnDef(def_id, substs) => {
+ ty::FnDef(def_id, args) => {
if with_no_queries() {
- p!(print_def_path(def_id, substs));
+ p!(print_def_path(def_id, args));
} else {
- let sig = self.tcx().fn_sig(def_id).subst(self.tcx(), substs);
- p!(print(sig), " {{", print_value_path(def_id, substs), "}}");
+ let sig = self.tcx().fn_sig(def_id).instantiate(self.tcx(), args);
+ p!(print(sig), " {{", print_value_path(def_id, args), "}}");
}
}
ty::FnPtr(ref bare_fn) => p!(print(bare_fn)),
@@ -715,8 +718,8 @@ pub trait PrettyPrinter<'tcx>:
false => p!(write("{s}")),
},
},
- ty::Adt(def, substs) => {
- p!(print_def_path(def.did(), substs));
+ ty::Adt(def, args) => {
+ p!(print_def_path(def.did(), args));
}
ty::Dynamic(data, r, repr) => {
let print_r = self.should_print_region(r);
@@ -739,7 +742,7 @@ pub trait PrettyPrinter<'tcx>:
if !(self.should_print_verbose() || with_no_queries())
&& self.tcx().is_impl_trait_in_trait(data.def_id)
{
- return self.pretty_print_opaque_impl_type(data.def_id, data.substs);
+ return self.pretty_print_opaque_impl_type(data.def_id, data.args);
} else {
p!(print(data))
}
@@ -751,7 +754,7 @@ pub trait PrettyPrinter<'tcx>:
false => p!(write("{name}")),
},
},
- ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
+ ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
// We use verbose printing in 'NO_QUERIES' mode, to
// avoid needing to call `predicates_of`. This should
// only affect certain debug messages (e.g. messages printed
@@ -759,27 +762,27 @@ pub trait PrettyPrinter<'tcx>:
// and should have no effect on any compiler output.
if self.should_print_verbose() {
// FIXME(eddyb) print this with `print_def_path`.
- p!(write("Opaque({:?}, {:?})", def_id, substs));
+ p!(write("Opaque({:?}, {:?})", def_id, args));
return Ok(self);
}
let parent = self.tcx().parent(def_id);
match self.tcx().def_kind(parent) {
- DefKind::TyAlias | DefKind::AssocTy => {
+ DefKind::TyAlias { .. } | DefKind::AssocTy => {
// NOTE: I know we should check for NO_QUERIES here, but it's alright.
// `type_of` on a type alias or assoc type should never cause a cycle.
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, .. }) =
- *self.tcx().type_of(parent).subst_identity().kind()
+ *self.tcx().type_of(parent).instantiate_identity().kind()
{
if d == def_id {
// If the type alias directly starts with the `impl` of the
// opaque type we're printing, then skip the `::{opaque#1}`.
- p!(print_def_path(parent, substs));
+ p!(print_def_path(parent, args));
return Ok(self);
}
}
// Complex opaque type, e.g. `type Foo = (i32, impl Debug);`
- p!(print_def_path(def_id, substs));
+ p!(print_def_path(def_id, args));
return Ok(self);
}
_ => {
@@ -787,13 +790,13 @@ pub trait PrettyPrinter<'tcx>:
p!(print_def_path(def_id, &[]));
return Ok(self);
} else {
- return self.pretty_print_opaque_impl_type(def_id, substs);
+ return self.pretty_print_opaque_impl_type(def_id, args);
}
}
}
}
ty::Str => p!("str"),
- ty::Generator(did, substs, movability) => {
+ ty::Generator(did, args, movability) => {
p!(write("["));
let generator_kind = self.tcx().generator_kind(did).unwrap();
let should_print_movability =
@@ -818,20 +821,20 @@ pub trait PrettyPrinter<'tcx>:
self.tcx().sess.source_map().span_to_embeddable_string(span)
));
} else {
- p!(write("@"), print_def_path(did, substs));
+ p!(write("@"), print_def_path(did, args));
}
} else {
- p!(print_def_path(did, substs));
+ p!(print_def_path(did, args));
p!(" upvar_tys=(");
- if !substs.as_generator().is_valid() {
+ if !args.as_generator().is_valid() {
p!("unavailable");
} else {
- self = self.comma_sep(substs.as_generator().upvar_tys())?;
+ self = self.comma_sep(args.as_generator().upvar_tys().iter())?;
}
p!(")");
- if substs.as_generator().is_valid() {
- p!(" ", print(substs.as_generator().witness()));
+ if args.as_generator().is_valid() {
+ p!(" ", print(args.as_generator().witness()));
}
}
@@ -840,7 +843,7 @@ pub trait PrettyPrinter<'tcx>:
ty::GeneratorWitness(types) => {
p!(in_binder(&types));
}
- ty::GeneratorWitnessMIR(did, substs) => {
+ ty::GeneratorWitnessMIR(did, args) => {
p!(write("["));
if !self.tcx().sess.verbose() {
p!("generator witness");
@@ -854,22 +857,22 @@ pub trait PrettyPrinter<'tcx>:
self.tcx().sess.source_map().span_to_embeddable_string(span)
));
} else {
- p!(write("@"), print_def_path(did, substs));
+ p!(write("@"), print_def_path(did, args));
}
} else {
- p!(print_def_path(did, substs));
+ p!(print_def_path(did, args));
}
p!("]")
}
- ty::Closure(did, substs) => {
+ ty::Closure(did, args) => {
p!(write("["));
if !self.should_print_verbose() {
p!(write("closure"));
// FIXME(eddyb) should use `def_span`.
if let Some(did) = did.as_local() {
if self.tcx().sess.opts.unstable_opts.span_free_formats {
- p!("@", print_def_path(did.to_def_id(), substs));
+ p!("@", print_def_path(did.to_def_id(), args));
} else {
let span = self.tcx().def_span(did);
let preference = if FORCE_TRIMMED_PATH.with(|flag| flag.get()) {
@@ -885,21 +888,21 @@ pub trait PrettyPrinter<'tcx>:
));
}
} else {
- p!(write("@"), print_def_path(did, substs));
+ p!(write("@"), print_def_path(did, args));
}
} else {
- p!(print_def_path(did, substs));
- if !substs.as_closure().is_valid() {
- p!(" closure_substs=(unavailable)");
- p!(write(" substs={:?}", substs));
+ p!(print_def_path(did, args));
+ if !args.as_closure().is_valid() {
+ p!(" closure_args=(unavailable)");
+ p!(write(" args={:?}", args));
} else {
- p!(" closure_kind_ty=", print(substs.as_closure().kind_ty()));
+ p!(" closure_kind_ty=", print(args.as_closure().kind_ty()));
p!(
" closure_sig_as_fn_ptr_ty=",
- print(substs.as_closure().sig_as_fn_ptr_ty())
+ print(args.as_closure().sig_as_fn_ptr_ty())
);
p!(" upvar_tys=(");
- self = self.comma_sep(substs.as_closure().upvar_tys())?;
+ self = self.comma_sep(args.as_closure().upvar_tys().iter())?;
p!(")");
}
}
@@ -915,7 +918,7 @@ pub trait PrettyPrinter<'tcx>:
fn pretty_print_opaque_impl_type(
mut self,
def_id: DefId,
- substs: &'tcx ty::List<ty::GenericArg<'tcx>>,
+ args: &'tcx ty::List<ty::GenericArg<'tcx>>,
) -> Result<Self::Type, Self::Error> {
let tcx = self.tcx();
@@ -928,7 +931,7 @@ pub trait PrettyPrinter<'tcx>:
let mut is_sized = false;
let mut lifetimes = SmallVec::<[ty::Region<'tcx>; 1]>::new();
- for (predicate, _) in bounds.subst_iter_copied(tcx, substs) {
+ for (predicate, _) in bounds.iter_instantiated_copied(tcx, args) {
let bound_predicate = predicate.kind();
match bound_predicate.skip_binder() {
@@ -978,9 +981,9 @@ pub trait PrettyPrinter<'tcx>:
define_scoped_cx!(cx);
// Get the (single) generic ty (the args) of this FnOnce trait ref.
let generics = tcx.generics_of(trait_ref.def_id);
- let args = generics.own_substs_no_defaults(tcx, trait_ref.substs);
+ let own_args = generics.own_args_no_defaults(tcx, trait_ref.args);
- match (entry.return_ty, args[0].expect_ty()) {
+ match (entry.return_ty, own_args[0].expect_ty()) {
// We can only print `impl Fn() -> ()` if we have a tuple of args and we recorded
// a return type.
(Some(return_ty), arg_tys) if matches!(arg_tys.kind(), ty::Tuple(_)) => {
@@ -1044,12 +1047,12 @@ pub trait PrettyPrinter<'tcx>:
p!(print(trait_ref.print_only_trait_name()));
let generics = tcx.generics_of(trait_ref.def_id);
- let args = generics.own_substs_no_defaults(tcx, trait_ref.substs);
+ let own_args = generics.own_args_no_defaults(tcx, trait_ref.args);
- if !args.is_empty() || !assoc_items.is_empty() {
+ if !own_args.is_empty() || !assoc_items.is_empty() {
let mut first = true;
- for ty in args {
+ for ty in own_args {
if first {
p!("<");
first = false;
@@ -1068,8 +1071,8 @@ pub trait PrettyPrinter<'tcx>:
&& assoc.trait_container(tcx) == tcx.lang_items().gen_trait()
&& assoc.name == rustc_span::sym::Return
{
- if let ty::Generator(_, substs, _) = substs.type_at(0).kind() {
- let return_ty = substs.as_generator().return_ty();
+ if let ty::Generator(_, args, _) = args.type_at(0).kind() {
+ let return_ty = args.as_generator().return_ty();
if !return_ty.is_ty_var() {
return_ty.into()
} else {
@@ -1182,7 +1185,7 @@ pub trait PrettyPrinter<'tcx>:
&def_key.disambiguated_data,
)
},
- &alias_ty.substs[1..],
+ &alias_ty.args[1..],
)
}
@@ -1211,7 +1214,7 @@ pub trait PrettyPrinter<'tcx>:
// Special-case `Fn(...) -> ...` and re-sugar it.
let fn_trait_kind = cx.tcx().fn_trait_kind_from_def_id(principal.def_id);
if !cx.should_print_verbose() && fn_trait_kind.is_some() {
- if let ty::Tuple(tys) = principal.substs.type_at(0).kind() {
+ if let ty::Tuple(tys) = principal.args.type_at(0).kind() {
let mut projections = predicates.projection_bounds();
if let (Some(proj), None) = (projections.next(), projections.next()) {
p!(pretty_fn_sig(
@@ -1234,7 +1237,7 @@ pub trait PrettyPrinter<'tcx>:
let args = cx
.tcx()
.generics_of(principal.def_id)
- .own_substs_no_defaults(cx.tcx(), principal.substs);
+ .own_args_no_defaults(cx.tcx(), principal.args);
let mut projections = predicates.projection_bounds();
@@ -1341,10 +1344,10 @@ pub trait PrettyPrinter<'tcx>:
}
match ct.kind() {
- ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => {
+ ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args }) => {
match self.tcx().def_kind(def) {
DefKind::Const | DefKind::AssocConst => {
- p!(print_value_path(def, substs))
+ p!(print_value_path(def, args))
}
DefKind::AnonConst => {
if def.is_local()
@@ -1449,7 +1452,7 @@ pub trait PrettyPrinter<'tcx>:
self.tcx().try_get_global_alloc(alloc_id)
{
self = self.typed_value(
- |this| this.print_value_path(instance.def_id(), instance.substs),
+ |this| this.print_value_path(instance.def_id(), instance.args),
|this| this.print_type(ty),
" as ",
)?;
@@ -1497,7 +1500,7 @@ pub trait PrettyPrinter<'tcx>:
let data = int.assert_bits(self.tcx().data_layout.pointer_size);
self = self.typed_value(
|mut this| {
- write!(this, "0x{:x}", data)?;
+ write!(this, "0x{data:x}")?;
Ok(this)
},
|this| this.print_type(ty),
@@ -1510,7 +1513,7 @@ pub trait PrettyPrinter<'tcx>:
if int.size() == Size::ZERO {
write!(this, "transmute(())")?;
} else {
- write!(this, "transmute(0x{:x})", int)?;
+ write!(this, "transmute(0x{int:x})")?;
}
Ok(this)
};
@@ -1619,11 +1622,11 @@ pub trait PrettyPrinter<'tcx>:
": ",
)?;
}
- ty::Adt(def, substs) => {
+ ty::Adt(def, args) => {
let variant_idx =
contents.variant.expect("destructed const of adt without variant idx");
let variant_def = &def.variant(variant_idx);
- p!(print_value_path(variant_def.def_id, substs));
+ p!(print_value_path(variant_def.def_id, args));
match variant_def.ctor_kind() {
Some(CtorKind::Const) => {}
Some(CtorKind::Fn) => {
@@ -1673,7 +1676,7 @@ pub trait PrettyPrinter<'tcx>:
fn pretty_closure_as_impl(
mut self,
- closure: ty::ClosureSubsts<'tcx>,
+ closure: ty::ClosureArgs<'tcx>,
) -> Result<Self::Const, Self::Error> {
let sig = closure.sig();
let kind = closure.kind_ty().to_opt_closure_kind().unwrap_or(ty::ClosureKind::Fn);
@@ -1798,29 +1801,29 @@ impl<'t> TyCtxt<'t> {
/// Returns a string identifying this `DefId`. This string is
/// suitable for user output.
pub fn def_path_str(self, def_id: impl IntoQueryParam<DefId>) -> String {
- self.def_path_str_with_substs(def_id, &[])
+ self.def_path_str_with_args(def_id, &[])
}
- pub fn def_path_str_with_substs(
+ pub fn def_path_str_with_args(
self,
def_id: impl IntoQueryParam<DefId>,
- substs: &'t [GenericArg<'t>],
+ args: &'t [GenericArg<'t>],
) -> String {
let def_id = def_id.into_query_param();
let ns = guess_def_namespace(self, def_id);
debug!("def_path_str: def_id={:?}, ns={:?}", def_id, ns);
- FmtPrinter::new(self, ns).print_def_path(def_id, substs).unwrap().into_buffer()
+ FmtPrinter::new(self, ns).print_def_path(def_id, args).unwrap().into_buffer()
}
- pub fn value_path_str_with_substs(
+ pub fn value_path_str_with_args(
self,
def_id: impl IntoQueryParam<DefId>,
- substs: &'t [GenericArg<'t>],
+ args: &'t [GenericArg<'t>],
) -> String {
let def_id = def_id.into_query_param();
let ns = guess_def_namespace(self, def_id);
debug!("value_path_str: def_id={:?}, ns={:?}", def_id, ns);
- FmtPrinter::new(self, ns).print_value_path(def_id, substs).unwrap().into_buffer()
+ FmtPrinter::new(self, ns).print_value_path(def_id, args).unwrap().into_buffer()
}
}
@@ -1847,11 +1850,11 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
fn print_def_path(
mut self,
def_id: DefId,
- substs: &'tcx [GenericArg<'tcx>],
+ args: &'tcx [GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
define_scoped_cx!(self);
- if substs.is_empty() {
+ if args.is_empty() {
match self.try_print_trimmed_def_path(def_id)? {
(cx, true) => return Ok(cx),
(cx, false) => self = cx,
@@ -1900,7 +1903,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
}
}
- self.default_print_def_path(def_id, substs)
+ self.default_print_def_path(def_id, args)
}
fn print_region(self, region: ty::Region<'tcx>) -> Result<Self::Region, Self::Error> {
@@ -1932,7 +1935,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
self.empty_path = true;
if cnum == LOCAL_CRATE {
- if self.tcx.sess.rust_2018() {
+ if self.tcx.sess.at_least_rust_2018() {
// We add the `crate::` keyword on Rust 2018, only when desired.
if SHOULD_PREFIX_WITH_CRATE.with(|flag| flag.get()) {
write!(self, "{}", kw::Crate)?;
@@ -2017,11 +2020,37 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
) -> Result<Self::Path, Self::Error> {
self = print_prefix(self)?;
- if args.first().is_some() {
+ let tcx = self.tcx;
+
+ let args = args.iter().copied();
+
+ let args: Vec<_> = if !tcx.sess.verbose() {
+ // skip host param as those are printed as `~const`
+ args.filter(|arg| match arg.unpack() {
+ // FIXME(effects) there should be a better way than just matching the name
+ GenericArgKind::Const(c)
+ if tcx.features().effects
+ && matches!(
+ c.kind(),
+ ty::ConstKind::Param(ty::ParamConst { name: sym::host, .. })
+ ) =>
+ {
+ false
+ }
+ _ => true,
+ })
+ .collect()
+ } else {
+ // If -Zverbose is passed, we should print the host parameter instead
+ // of eating it.
+ args.collect()
+ };
+
+ if !args.is_empty() {
if self.in_value {
write!(self, "::")?;
}
- self.generic_delimiters(|cx| cx.comma_sep(args.iter().cloned()))
+ self.generic_delimiters(|cx| cx.comma_sep(args.into_iter()))
} else {
Ok(self)
}
@@ -2044,10 +2073,10 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
fn print_value_path(
mut self,
def_id: DefId,
- substs: &'tcx [GenericArg<'tcx>],
+ args: &'tcx [GenericArg<'tcx>],
) -> Result<Self::Path, Self::Error> {
let was_in_value = std::mem::replace(&mut self.in_value, true);
- self = self.print_def_path(def_id, substs)?;
+ self = self.print_def_path(def_id, args)?;
self.in_value = was_in_value;
Ok(self)
@@ -2348,10 +2377,10 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
} else {
cont
};
- let _ = write!(cx, "{}", w);
+ let _ = write!(cx, "{w}");
};
let do_continue = |cx: &mut Self, cont: Symbol| {
- let _ = write!(cx, "{}", cont);
+ let _ = write!(cx, "{cont}");
};
define_scoped_cx!(self);
@@ -2387,7 +2416,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
let (new_value, map) = if self.should_print_verbose() {
for var in value.bound_vars().iter() {
start_or_continue(&mut self, "for<", ", ");
- write!(self, "{:?}", var)?;
+ write!(self, "{var:?}")?;
}
start_or_continue(&mut self, "", "> ");
(value.clone().skip_binder(), BTreeMap::default())
@@ -2695,7 +2724,7 @@ impl<'tcx> ty::PolyTraitPredicate<'tcx> {
#[derive(Debug, Copy, Clone, Lift)]
pub struct PrintClosureAsImpl<'tcx> {
- pub closure: ty::ClosureSubsts<'tcx>,
+ pub closure: ty::ClosureArgs<'tcx>,
}
forward_display_to_print! {
@@ -2707,8 +2736,9 @@ forward_display_to_print! {
// HACK(eddyb) these are exhaustive instead of generic,
// because `for<'tcx>` isn't possible yet.
ty::PolyExistentialPredicate<'tcx>,
+ ty::PolyExistentialProjection<'tcx>,
+ ty::PolyExistentialTraitRef<'tcx>,
ty::Binder<'tcx, ty::TraitRef<'tcx>>,
- ty::Binder<'tcx, ty::ExistentialTraitRef<'tcx>>,
ty::Binder<'tcx, TraitRefPrintOnlyTraitPath<'tcx>>,
ty::Binder<'tcx, TraitRefPrintOnlyTraitName<'tcx>>,
ty::Binder<'tcx, ty::FnSig<'tcx>>,
@@ -2771,7 +2801,7 @@ define_print_and_forward_display! {
}
TraitRefPrintOnlyTraitPath<'tcx> {
- p!(print_def_path(self.0.def_id, self.0.substs));
+ p!(print_def_path(self.0.def_id, self.0.args));
}
TraitRefPrintOnlyTraitName<'tcx> {
@@ -2779,10 +2809,7 @@ define_print_and_forward_display! {
}
TraitPredPrintModifiersAndPath<'tcx> {
- if let ty::BoundConstness::ConstIfConst = self.0.constness {
- p!("~const ")
- }
-
+ // FIXME(effects) print `~const` here
if let ty::ImplPolarity::Negative = self.0.polarity {
p!("!")
}
@@ -2816,9 +2843,12 @@ define_print_and_forward_display! {
ty::TraitPredicate<'tcx> {
p!(print(self.trait_ref.self_ty()), ": ");
- if let ty::BoundConstness::ConstIfConst = self.constness && cx.tcx().features().const_trait_impl {
- p!("~const ");
+ if let Some(idx) = cx.tcx().generics_of(self.trait_ref.def_id).host_effect_index {
+ if self.trait_ref.args.const_at(idx) != cx.tcx().consts.true_ {
+ p!("~const ");
+ }
}
+ // FIXME(effects) print `~const` here
if let ty::ImplPolarity::Negative = self.polarity {
p!("!");
}
@@ -2842,16 +2872,12 @@ define_print_and_forward_display! {
if let DefKind::Impl { of_trait: false } = cx.tcx().def_kind(cx.tcx().parent(self.def_id)) {
p!(pretty_print_inherent_projection(self))
} else {
- p!(print_def_path(self.def_id, self.substs));
+ p!(print_def_path(self.def_id, self.args));
}
}
ty::ClosureKind {
- match *self {
- ty::ClosureKind::Fn => p!("Fn"),
- ty::ClosureKind::FnMut => p!("FnMut"),
- ty::ClosureKind::FnOnce => p!("FnOnce"),
- }
+ p!(write("{}", self.as_str()))
}
ty::Predicate<'tcx> {
@@ -2891,7 +2917,7 @@ define_print_and_forward_display! {
ty::PredicateKind::ObjectSafe(trait_def_id) => {
p!("the trait `", print_def_path(trait_def_id, &[]), "` is object-safe")
}
- ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => p!(
+ ty::PredicateKind::ClosureKind(closure_def_id, _closure_args, kind) => p!(
"the closure `",
print_value_path(closure_def_id, &[]),
write("` implements the trait `{}`", kind)
@@ -2960,7 +2986,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N
match child.res {
def::Res::Def(DefKind::AssocTy, _) => {}
- def::Res::Def(DefKind::TyAlias, _) => {}
+ def::Res::Def(DefKind::TyAlias { .. }, _) => {}
def::Res::Def(defkind, def_id) => {
if let Some(ns) = defkind.ns() {
collect_fn(&child.ident, ns, def_id);
diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs
index 5741832c9..47512d350 100644
--- a/compiler/rustc_middle/src/ty/relate.rs
+++ b/compiler/rustc_middle/src/ty/relate.rs
@@ -6,7 +6,7 @@
use crate::ty::error::{ExpectedFound, TypeError};
use crate::ty::{self, Expr, ImplSubject, Term, TermKind, Ty, TyCtxt, TypeFoldable};
-use crate::ty::{GenericArg, GenericArgKind, SubstsRef};
+use crate::ty::{GenericArg, GenericArgKind, GenericArgsRef};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_target::spec::abi;
@@ -43,23 +43,23 @@ pub trait TypeRelation<'tcx>: Sized {
Relate::relate(self, a, b)
}
- /// Relate the two substitutions for the given item. The default
+ /// Relate the two args for the given item. The default
/// is to look up the variance for the item and proceed
/// accordingly.
- fn relate_item_substs(
+ fn relate_item_args(
&mut self,
item_def_id: DefId,
- a_subst: SubstsRef<'tcx>,
- b_subst: SubstsRef<'tcx>,
- ) -> RelateResult<'tcx, SubstsRef<'tcx>> {
+ a_arg: GenericArgsRef<'tcx>,
+ b_arg: GenericArgsRef<'tcx>,
+ ) -> RelateResult<'tcx, GenericArgsRef<'tcx>> {
debug!(
- "relate_item_substs(item_def_id={:?}, a_subst={:?}, b_subst={:?})",
- item_def_id, a_subst, b_subst
+ "relate_item_args(item_def_id={:?}, a_arg={:?}, b_arg={:?})",
+ item_def_id, a_arg, b_arg
);
let tcx = self.tcx();
let opt_variances = tcx.variances_of(item_def_id);
- relate_substs_with_variances(self, item_def_id, opt_variances, a_subst, b_subst, true)
+ relate_args_with_variances(self, item_def_id, opt_variances, a_arg, b_arg, true)
}
/// Switch variance for the purpose of relating `a` and `b`.
@@ -134,31 +134,32 @@ pub fn relate_type_and_mut<'tcx, R: TypeRelation<'tcx>>(
}
#[inline]
-pub fn relate_substs<'tcx, R: TypeRelation<'tcx>>(
+pub fn relate_args<'tcx, R: TypeRelation<'tcx>>(
relation: &mut R,
- a_subst: SubstsRef<'tcx>,
- b_subst: SubstsRef<'tcx>,
-) -> RelateResult<'tcx, SubstsRef<'tcx>> {
- relation.tcx().mk_substs_from_iter(iter::zip(a_subst, b_subst).map(|(a, b)| {
+ a_arg: GenericArgsRef<'tcx>,
+ b_arg: GenericArgsRef<'tcx>,
+) -> RelateResult<'tcx, GenericArgsRef<'tcx>> {
+ relation.tcx().mk_args_from_iter(iter::zip(a_arg, b_arg).map(|(a, b)| {
relation.relate_with_variance(ty::Invariant, ty::VarianceDiagInfo::default(), a, b)
}))
}
-pub fn relate_substs_with_variances<'tcx, R: TypeRelation<'tcx>>(
+pub fn relate_args_with_variances<'tcx, R: TypeRelation<'tcx>>(
relation: &mut R,
ty_def_id: DefId,
variances: &[ty::Variance],
- a_subst: SubstsRef<'tcx>,
- b_subst: SubstsRef<'tcx>,
+ a_arg: GenericArgsRef<'tcx>,
+ b_arg: GenericArgsRef<'tcx>,
fetch_ty_for_diag: bool,
-) -> RelateResult<'tcx, SubstsRef<'tcx>> {
+) -> RelateResult<'tcx, GenericArgsRef<'tcx>> {
let tcx = relation.tcx();
let mut cached_ty = None;
- let params = iter::zip(a_subst, b_subst).enumerate().map(|(i, (a, b))| {
+ let params = iter::zip(a_arg, b_arg).enumerate().map(|(i, (a, b))| {
let variance = variances[i];
let variance_info = if variance == ty::Invariant && fetch_ty_for_diag {
- let ty = *cached_ty.get_or_insert_with(|| tcx.type_of(ty_def_id).subst(tcx, a_subst));
+ let ty =
+ *cached_ty.get_or_insert_with(|| tcx.type_of(ty_def_id).instantiate(tcx, a_arg));
ty::VarianceDiagInfo::Invariant { ty, param_index: i.try_into().unwrap() }
} else {
ty::VarianceDiagInfo::default()
@@ -166,7 +167,7 @@ pub fn relate_substs_with_variances<'tcx, R: TypeRelation<'tcx>>(
relation.relate_with_variance(variance, variance_info, a, b)
});
- tcx.mk_substs_from_iter(params)
+ tcx.mk_args_from_iter(params)
}
impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
@@ -272,8 +273,8 @@ impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> {
if a.def_id != b.def_id {
Err(TypeError::ProjectionMismatched(expected_found(relation, a.def_id, b.def_id)))
} else {
- let substs = relation.relate(a.substs, b.substs)?;
- Ok(relation.tcx().mk_alias_ty(a.def_id, substs))
+ let args = relation.relate(a.args, b.args)?;
+ Ok(relation.tcx().mk_alias_ty(a.def_id, args))
}
}
}
@@ -293,13 +294,13 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialProjection<'tcx> {
a.term,
b.term,
)?;
- let substs = relation.relate_with_variance(
+ let args = relation.relate_with_variance(
ty::Invariant,
ty::VarianceDiagInfo::default(),
- a.substs,
- b.substs,
+ a.args,
+ b.args,
)?;
- Ok(ty::ExistentialProjection { def_id: a.def_id, substs, term })
+ Ok(ty::ExistentialProjection { def_id: a.def_id, args, term })
}
}
}
@@ -314,8 +315,8 @@ impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> {
if a.def_id != b.def_id {
Err(TypeError::Traits(expected_found(relation, a.def_id, b.def_id)))
} else {
- let substs = relate_substs(relation, a.substs, b.substs)?;
- Ok(ty::TraitRef::new(relation.tcx(), a.def_id, substs))
+ let args = relate_args(relation, a.args, b.args)?;
+ Ok(ty::TraitRef::new(relation.tcx(), a.def_id, args))
}
}
}
@@ -330,8 +331,8 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialTraitRef<'tcx> {
if a.def_id != b.def_id {
Err(TypeError::Traits(expected_found(relation, a.def_id, b.def_id)))
} else {
- let substs = relate_substs(relation, a.substs, b.substs)?;
- Ok(ty::ExistentialTraitRef { def_id: a.def_id, substs })
+ let args = relate_args(relation, a.args, b.args)?;
+ Ok(ty::ExistentialTraitRef { def_id: a.def_id, args })
}
}
}
@@ -426,9 +427,9 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
(ty::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => Ok(a),
- (&ty::Adt(a_def, a_substs), &ty::Adt(b_def, b_substs)) if a_def == b_def => {
- let substs = relation.relate_item_substs(a_def.did(), a_substs, b_substs)?;
- Ok(Ty::new_adt(tcx, a_def, substs))
+ (&ty::Adt(a_def, a_args), &ty::Adt(b_def, b_args)) if a_def == b_def => {
+ let args = relation.relate_item_args(a_def.did(), a_args, b_args)?;
+ Ok(Ty::new_adt(tcx, a_def, args))
}
(&ty::Foreign(a_id), &ty::Foreign(b_id)) if a_id == b_id => Ok(Ty::new_foreign(tcx, a_id)),
@@ -442,14 +443,14 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
Ok(Ty::new_dynamic(tcx, relation.relate(a_obj, b_obj)?, region_bound, a_repr))
}
- (&ty::Generator(a_id, a_substs, movability), &ty::Generator(b_id, b_substs, _))
+ (&ty::Generator(a_id, a_args, movability), &ty::Generator(b_id, b_args, _))
if a_id == b_id =>
{
// All Generator types with the same id represent
// the (anonymous) type of the same generator expression. So
// all of their regions should be equated.
- let substs = relation.relate(a_substs, b_substs)?;
- Ok(Ty::new_generator(tcx, a_id, substs, movability))
+ let args = relation.relate(a_args, b_args)?;
+ Ok(Ty::new_generator(tcx, a_id, args, movability))
}
(&ty::GeneratorWitness(a_types), &ty::GeneratorWitness(b_types)) => {
@@ -462,22 +463,22 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
Ok(Ty::new_generator_witness(tcx, types))
}
- (&ty::GeneratorWitnessMIR(a_id, a_substs), &ty::GeneratorWitnessMIR(b_id, b_substs))
+ (&ty::GeneratorWitnessMIR(a_id, a_args), &ty::GeneratorWitnessMIR(b_id, b_args))
if a_id == b_id =>
{
// All GeneratorWitness types with the same id represent
// the (anonymous) type of the same generator expression. So
// all of their regions should be equated.
- let substs = relation.relate(a_substs, b_substs)?;
- Ok(Ty::new_generator_witness_mir(tcx, a_id, substs))
+ let args = relation.relate(a_args, b_args)?;
+ Ok(Ty::new_generator_witness_mir(tcx, a_id, args))
}
- (&ty::Closure(a_id, a_substs), &ty::Closure(b_id, b_substs)) if a_id == b_id => {
+ (&ty::Closure(a_id, a_args), &ty::Closure(b_id, b_args)) if a_id == b_id => {
// All Closure types with the same id represent
// the (anonymous) type of the same closure expression. So
// all of their regions should be equated.
- let substs = relation.relate(a_substs, b_substs)?;
- Ok(Ty::new_closure(tcx, a_id, &substs))
+ let args = relation.relate(a_args, b_args)?;
+ Ok(Ty::new_closure(tcx, a_id, &args))
}
(&ty::RawPtr(a_mt), &ty::RawPtr(b_mt)) => {
@@ -535,11 +536,9 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
}
}
- (&ty::FnDef(a_def_id, a_substs), &ty::FnDef(b_def_id, b_substs))
- if a_def_id == b_def_id =>
- {
- let substs = relation.relate_item_substs(a_def_id, a_substs, b_substs)?;
- Ok(Ty::new_fn_def(tcx, a_def_id, substs))
+ (&ty::FnDef(a_def_id, a_args), &ty::FnDef(b_def_id, b_args)) if a_def_id == b_def_id => {
+ let args = relation.relate_item_args(a_def_id, a_args, b_args)?;
+ Ok(Ty::new_fn_def(tcx, a_def_id, args))
}
(&ty::FnPtr(a_fty), &ty::FnPtr(b_fty)) => {
@@ -547,35 +546,29 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
Ok(Ty::new_fn_ptr(tcx, fty))
}
- // The substs of opaque types may not all be invariant, so we have
+ // The args of opaque types may not all be invariant, so we have
// to treat them separately from other aliases.
(
- &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: a_substs, .. }),
- &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: b_substs, .. }),
+ &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, args: a_args, .. }),
+ &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, args: b_args, .. }),
) if a_def_id == b_def_id => {
let opt_variances = tcx.variances_of(a_def_id);
- let substs = relate_substs_with_variances(
+ let args = relate_args_with_variances(
relation,
a_def_id,
opt_variances,
- a_substs,
- b_substs,
+ a_args,
+ b_args,
false, // do not fetch `type_of(a_def_id)`, as it will cause a cycle
)?;
- Ok(Ty::new_opaque(tcx, a_def_id, substs))
+ Ok(Ty::new_opaque(tcx, a_def_id, args))
}
// Alias tend to mostly already be handled downstream due to normalization.
(&ty::Alias(a_kind, a_data), &ty::Alias(b_kind, b_data)) => {
- // FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): This if can be removed
- // and the assert uncommented once the new desugaring is stable.
- if a_kind == b_kind {
- let alias_ty = relation.relate(a_data, b_data)?;
- // assert_eq!(a_kind, b_kind);
- Ok(Ty::new_alias(tcx, a_kind, alias_ty))
- } else {
- Err(TypeError::Sorts(expected_found(relation, a, b)))
- }
+ let alias_ty = relation.relate(a_data, b_data)?;
+ assert_eq!(a_kind, b_kind);
+ Ok(Ty::new_alias(tcx, a_kind, alias_ty))
}
_ => Err(TypeError::Sorts(expected_found(relation, a, b))),
@@ -624,15 +617,15 @@ pub fn structurally_relate_consts<'tcx, R: TypeRelation<'tcx>>(
// be stabilized.
(ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu)) if au.def == bu.def => {
assert_eq!(a.ty(), b.ty());
- let substs = relation.relate_with_variance(
+ let args = relation.relate_with_variance(
ty::Variance::Invariant,
ty::VarianceDiagInfo::default(),
- au.substs,
- bu.substs,
+ au.args,
+ bu.args,
)?;
return Ok(ty::Const::new_unevaluated(
tcx,
- ty::UnevaluatedConst { def: au.def, substs },
+ ty::UnevaluatedConst { def: au.def, args },
a.ty(),
));
}
@@ -646,7 +639,7 @@ pub fn structurally_relate_consts<'tcx, R: TypeRelation<'tcx>>(
// FIXME(generic_const_exprs): relating the `ty()`s is a little weird since it is supposed to
// ICE If they mismatch. Unfortunately `ConstKind::Expr` is a little special and can be thought
// of as being generic over the argument types, however this is implicit so these types don't get
- // related when we relate the substs of the item this const arg is for.
+ // related when we relate the args of the item this const arg is for.
let expr = match (ae, be) {
(Expr::Binop(a_op, al, ar), Expr::Binop(b_op, bl, br)) if a_op == b_op => {
r.relate(al.ty(), bl.ty())?;
@@ -720,35 +713,35 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
}
}
-impl<'tcx> Relate<'tcx> for ty::ClosureSubsts<'tcx> {
+impl<'tcx> Relate<'tcx> for ty::ClosureArgs<'tcx> {
fn relate<R: TypeRelation<'tcx>>(
relation: &mut R,
- a: ty::ClosureSubsts<'tcx>,
- b: ty::ClosureSubsts<'tcx>,
- ) -> RelateResult<'tcx, ty::ClosureSubsts<'tcx>> {
- let substs = relate_substs(relation, a.substs, b.substs)?;
- Ok(ty::ClosureSubsts { substs })
+ a: ty::ClosureArgs<'tcx>,
+ b: ty::ClosureArgs<'tcx>,
+ ) -> RelateResult<'tcx, ty::ClosureArgs<'tcx>> {
+ let args = relate_args(relation, a.args, b.args)?;
+ Ok(ty::ClosureArgs { args })
}
}
-impl<'tcx> Relate<'tcx> for ty::GeneratorSubsts<'tcx> {
+impl<'tcx> Relate<'tcx> for ty::GeneratorArgs<'tcx> {
fn relate<R: TypeRelation<'tcx>>(
relation: &mut R,
- a: ty::GeneratorSubsts<'tcx>,
- b: ty::GeneratorSubsts<'tcx>,
- ) -> RelateResult<'tcx, ty::GeneratorSubsts<'tcx>> {
- let substs = relate_substs(relation, a.substs, b.substs)?;
- Ok(ty::GeneratorSubsts { substs })
+ a: ty::GeneratorArgs<'tcx>,
+ b: ty::GeneratorArgs<'tcx>,
+ ) -> RelateResult<'tcx, ty::GeneratorArgs<'tcx>> {
+ let args = relate_args(relation, a.args, b.args)?;
+ Ok(ty::GeneratorArgs { args })
}
}
-impl<'tcx> Relate<'tcx> for SubstsRef<'tcx> {
+impl<'tcx> Relate<'tcx> for GenericArgsRef<'tcx> {
fn relate<R: TypeRelation<'tcx>>(
relation: &mut R,
- a: SubstsRef<'tcx>,
- b: SubstsRef<'tcx>,
- ) -> RelateResult<'tcx, SubstsRef<'tcx>> {
- relate_substs(relation, a, b)
+ a: GenericArgsRef<'tcx>,
+ b: GenericArgsRef<'tcx>,
+ ) -> RelateResult<'tcx, GenericArgsRef<'tcx>> {
+ relate_args(relation, a, b)
}
}
@@ -833,7 +826,6 @@ impl<'tcx> Relate<'tcx> for ty::TraitPredicate<'tcx> {
) -> RelateResult<'tcx, ty::TraitPredicate<'tcx>> {
Ok(ty::TraitPredicate {
trait_ref: relation.relate(a.trait_ref, b.trait_ref)?,
- constness: relation.relate(a.constness, b.constness)?,
polarity: relation.relate(a.polarity, b.polarity)?,
})
}
diff --git a/compiler/rustc_middle/src/ty/rvalue_scopes.rs b/compiler/rustc_middle/src/ty/rvalue_scopes.rs
index e79b79a25..17eabec25 100644
--- a/compiler/rustc_middle/src/ty/rvalue_scopes.rs
+++ b/compiler/rustc_middle/src/ty/rvalue_scopes.rs
@@ -1,12 +1,12 @@
use crate::middle::region::{Scope, ScopeData, ScopeTree};
-use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
+use rustc_hir::ItemLocalMap;
/// `RvalueScopes` is a mapping from sub-expressions to _extended_ lifetime as determined by
/// rules laid out in `rustc_hir_analysis::check::rvalue_scopes`.
#[derive(TyEncodable, TyDecodable, Clone, Debug, Default, Eq, PartialEq, HashStable)]
pub struct RvalueScopes {
- map: FxHashMap<hir::ItemLocalId, Option<Scope>>,
+ map: ItemLocalMap<Option<Scope>>,
}
impl RvalueScopes {
diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs
index 7220d133f..f979ddd00 100644
--- a/compiler/rustc_middle/src/ty/structural_impls.rs
+++ b/compiler/rustc_middle/src/ty/structural_impls.rs
@@ -11,13 +11,15 @@ use crate::ty::{self, AliasTy, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
use rustc_hir::def::Namespace;
use rustc_index::{Idx, IndexVec};
use rustc_target::abi::TyAndLayout;
-use rustc_type_ir::ConstKind;
+use rustc_type_ir::{ConstKind, DebugWithInfcx, InferCtxtLike, OptWithInfcx};
-use std::fmt;
+use std::fmt::{self, Debug};
use std::ops::ControlFlow;
use std::rc::Rc;
use std::sync::Arc;
+use super::{GenericArg, GenericArgKind, Region};
+
impl fmt::Debug for ty::TraitDef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
ty::tls::with(|tcx| {
@@ -71,9 +73,9 @@ impl fmt::Debug for ty::BoundRegionKind {
ty::BrAnon(span) => write!(f, "BrAnon({span:?})"),
ty::BrNamed(did, name) => {
if did.is_crate_root() {
- write!(f, "BrNamed({})", name)
+ write!(f, "BrNamed({name})")
} else {
- write!(f, "BrNamed({:?}, {})", did, name)
+ write!(f, "BrNamed({did:?}, {name})")
}
}
ty::BrEnv => write!(f, "BrEnv"),
@@ -89,7 +91,16 @@ impl fmt::Debug for ty::FreeRegion {
impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- let ty::FnSig { inputs_and_output: _, c_variadic, unsafety, abi } = self;
+ OptWithInfcx::new_no_ctx(self).fmt(f)
+ }
+}
+impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::FnSig<'tcx> {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
+ let sig = this.data;
+ let ty::FnSig { inputs_and_output: _, c_variadic, unsafety, abi } = sig;
write!(f, "{}", unsafety.prefix_str())?;
match abi {
@@ -98,15 +109,15 @@ impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
};
write!(f, "fn(")?;
- let inputs = self.inputs();
+ let inputs = sig.inputs();
match inputs.len() {
0 if *c_variadic => write!(f, "...)")?,
0 => write!(f, ")")?,
_ => {
- for ty in &self.inputs()[0..(self.inputs().len() - 1)] {
- write!(f, "{ty:?}, ")?;
+ for ty in &sig.inputs()[0..(sig.inputs().len() - 1)] {
+ write!(f, "{:?}, ", &this.wrap(ty))?;
}
- write!(f, "{:?}", self.inputs().last().unwrap())?;
+ write!(f, "{:?}", &this.wrap(sig.inputs().last().unwrap()))?;
if *c_variadic {
write!(f, "...")?;
}
@@ -114,9 +125,9 @@ impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
}
}
- match self.output().kind() {
+ match sig.output().kind() {
ty::Tuple(list) if list.is_empty() => Ok(()),
- _ => write!(f, " -> {:?}", self.output()),
+ _ => write!(f, " -> {:?}", &this.wrap(sig.output())),
}
}
}
@@ -133,6 +144,14 @@ impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
}
}
+impl<'tcx> ty::DebugWithInfcx<TyCtxt<'tcx>> for Ty<'tcx> {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
+ this.data.fmt(f)
+ }
+}
impl<'tcx> fmt::Debug for Ty<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
with_no_trimmed_paths!(fmt::Display::fmt(self, f))
@@ -153,9 +172,7 @@ impl fmt::Debug for ty::ParamConst {
impl<'tcx> fmt::Debug for ty::TraitPredicate<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- if let ty::BoundConstness::ConstIfConst = self.constness {
- write!(f, "~const ")?;
- }
+ // FIXME(effects) printing?
write!(f, "TraitPredicate({:?}, polarity:{:?})", self.trait_ref, self.polarity)
}
}
@@ -186,7 +203,7 @@ impl<'tcx> fmt::Debug for ty::ClauseKind<'tcx> {
ty::ClauseKind::RegionOutlives(ref pair) => pair.fmt(f),
ty::ClauseKind::TypeOutlives(ref pair) => pair.fmt(f),
ty::ClauseKind::Projection(ref pair) => pair.fmt(f),
- ty::ClauseKind::WellFormed(ref data) => write!(f, "WellFormed({:?})", data),
+ ty::ClauseKind::WellFormed(ref data) => write!(f, "WellFormed({data:?})"),
ty::ClauseKind::ConstEvaluatable(ct) => {
write!(f, "ConstEvaluatable({ct:?})")
}
@@ -201,12 +218,12 @@ impl<'tcx> fmt::Debug for ty::PredicateKind<'tcx> {
ty::PredicateKind::Subtype(ref pair) => pair.fmt(f),
ty::PredicateKind::Coerce(ref pair) => pair.fmt(f),
ty::PredicateKind::ObjectSafe(trait_def_id) => {
- write!(f, "ObjectSafe({:?})", trait_def_id)
+ write!(f, "ObjectSafe({trait_def_id:?})")
}
- ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
- write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
+ ty::PredicateKind::ClosureKind(closure_def_id, closure_args, kind) => {
+ write!(f, "ClosureKind({closure_def_id:?}, {closure_args:?}, {kind:?})")
}
- ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
+ ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({c1:?}, {c2:?})"),
ty::PredicateKind::Ambiguous => write!(f, "Ambiguous"),
ty::PredicateKind::AliasRelate(t1, t2, dir) => {
write!(f, "AliasRelate({t1:?}, {dir:?}, {t2:?})")
@@ -217,9 +234,17 @@ impl<'tcx> fmt::Debug for ty::PredicateKind<'tcx> {
impl<'tcx> fmt::Debug for AliasTy<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ OptWithInfcx::new_no_ctx(self).fmt(f)
+ }
+}
+impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for AliasTy<'tcx> {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
f.debug_struct("AliasTy")
- .field("substs", &self.substs)
- .field("def_id", &self.def_id)
+ .field("args", &this.map(|data| data.args))
+ .field("def_id", &this.data.def_id)
.finish()
}
}
@@ -232,13 +257,93 @@ impl<'tcx> fmt::Debug for ty::InferConst<'tcx> {
}
}
}
+impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::InferConst<'tcx> {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
+ use ty::InferConst::*;
+ match this.infcx.and_then(|infcx| infcx.universe_of_ct(*this.data)) {
+ None => write!(f, "{:?}", this.data),
+ Some(universe) => match *this.data {
+ Var(vid) => write!(f, "?{}_{}c", vid.index, universe.index()),
+ Fresh(_) => {
+ unreachable!()
+ }
+ },
+ }
+ }
+}
+
+impl<'tcx> fmt::Debug for ty::consts::Expr<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ OptWithInfcx::new_no_ctx(self).fmt(f)
+ }
+}
+impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::consts::Expr<'tcx> {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
+ match this.data {
+ ty::Expr::Binop(op, lhs, rhs) => {
+ write!(f, "({op:?}: {:?}, {:?})", &this.wrap(lhs), &this.wrap(rhs))
+ }
+ ty::Expr::UnOp(op, rhs) => write!(f, "({op:?}: {:?})", &this.wrap(rhs)),
+ ty::Expr::FunctionCall(func, args) => {
+ write!(f, "{:?}(", &this.wrap(func))?;
+ for arg in args.as_slice().iter().rev().skip(1).rev() {
+ write!(f, "{:?}, ", &this.wrap(arg))?;
+ }
+ if let Some(arg) = args.last() {
+ write!(f, "{:?}", &this.wrap(arg))?;
+ }
+
+ write!(f, ")")
+ }
+ ty::Expr::Cast(cast_kind, lhs, rhs) => {
+ write!(f, "({cast_kind:?}: {:?}, {:?})", &this.wrap(lhs), &this.wrap(rhs))
+ }
+ }
+ }
+}
+
+impl<'tcx> fmt::Debug for ty::UnevaluatedConst<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ OptWithInfcx::new_no_ctx(self).fmt(f)
+ }
+}
+impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::UnevaluatedConst<'tcx> {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
+ f.debug_struct("UnevaluatedConst")
+ .field("def", &this.data.def)
+ .field("args", &this.wrap(this.data.args))
+ .finish()
+ }
+}
impl<'tcx> fmt::Debug for ty::Const<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ OptWithInfcx::new_no_ctx(self).fmt(f)
+ }
+}
+impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::Const<'tcx> {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
// This reflects what `Const` looked liked before `Interned` was
// introduced. We print it like this to avoid having to update expected
// output in a lot of tests.
- write!(f, "Const {{ ty: {:?}, kind: {:?} }}", self.ty(), self.kind())
+ write!(
+ f,
+ "Const {{ ty: {:?}, kind: {:?} }}",
+ &this.map(|data| data.ty()),
+ &this.map(|data| data.kind())
+ )
}
}
@@ -261,6 +366,66 @@ impl<T: fmt::Debug> fmt::Debug for ty::Placeholder<T> {
}
}
+impl<'tcx> fmt::Debug for GenericArg<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self.unpack() {
+ GenericArgKind::Lifetime(lt) => lt.fmt(f),
+ GenericArgKind::Type(ty) => ty.fmt(f),
+ GenericArgKind::Const(ct) => ct.fmt(f),
+ }
+ }
+}
+impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for GenericArg<'tcx> {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
+ match this.data.unpack() {
+ GenericArgKind::Lifetime(lt) => write!(f, "{:?}", &this.wrap(lt)),
+ GenericArgKind::Const(ct) => write!(f, "{:?}", &this.wrap(ct)),
+ GenericArgKind::Type(ty) => write!(f, "{:?}", &this.wrap(ty)),
+ }
+ }
+}
+
+impl<'tcx> fmt::Debug for Region<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{:?}", self.kind())
+ }
+}
+impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for Region<'tcx> {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
+ write!(f, "{:?}", &this.map(|data| data.kind()))
+ }
+}
+
+impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::RegionVid {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
+ match this.infcx.and_then(|infcx| infcx.universe_of_lt(*this.data)) {
+ Some(universe) => write!(f, "'?{}_{}", this.data.index(), universe.index()),
+ None => write!(f, "{:?}", this.data),
+ }
+ }
+}
+
+impl<'tcx, T: DebugWithInfcx<TyCtxt<'tcx>>> DebugWithInfcx<TyCtxt<'tcx>> for ty::Binder<'tcx, T> {
+ fn fmt<InfCtx: InferCtxtLike<TyCtxt<'tcx>>>(
+ this: OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
+ f.debug_tuple("Binder")
+ .field(&this.map(|data| data.as_ref().skip_binder()))
+ .field(&this.data.bound_vars())
+ .finish()
+ }
+}
+
///////////////////////////////////////////////////////////////////////////
// Atomic structs
//
@@ -273,7 +438,6 @@ CloneLiftImpls! {
(),
bool,
usize,
- u8,
u16,
u32,
u64,
@@ -303,10 +467,8 @@ TrivialTypeTraversalAndLiftImpls! {
::rustc_hir::Unsafety,
::rustc_target::asm::InlineAsmRegOrRegClass,
::rustc_target::spec::abi::Abi,
- crate::mir::coverage::ExpressionOperandId,
- crate::mir::coverage::CounterValueReference,
- crate::mir::coverage::InjectedExpressionId,
- crate::mir::coverage::InjectedExpressionIndex,
+ crate::mir::coverage::CounterId,
+ crate::mir::coverage::ExpressionId,
crate::mir::coverage::MappedExpressionIndex,
crate::mir::Local,
crate::mir::Promoted,
@@ -435,7 +597,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
type Lifted = ty::ParamEnv<'tcx>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(self.caller_bounds())
- .map(|caller_bounds| ty::ParamEnv::new(caller_bounds, self.reveal(), self.constness()))
+ .map(|caller_bounds| ty::ParamEnv::new(caller_bounds, self.reveal()))
}
}
@@ -528,26 +690,26 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
ty::RawPtr(tm) => ty::RawPtr(tm.try_fold_with(folder)?),
ty::Array(typ, sz) => ty::Array(typ.try_fold_with(folder)?, sz.try_fold_with(folder)?),
ty::Slice(typ) => ty::Slice(typ.try_fold_with(folder)?),
- ty::Adt(tid, substs) => ty::Adt(tid, substs.try_fold_with(folder)?),
+ ty::Adt(tid, args) => ty::Adt(tid, args.try_fold_with(folder)?),
ty::Dynamic(trait_ty, region, representation) => ty::Dynamic(
trait_ty.try_fold_with(folder)?,
region.try_fold_with(folder)?,
representation,
),
ty::Tuple(ts) => ty::Tuple(ts.try_fold_with(folder)?),
- ty::FnDef(def_id, substs) => ty::FnDef(def_id, substs.try_fold_with(folder)?),
+ ty::FnDef(def_id, args) => ty::FnDef(def_id, args.try_fold_with(folder)?),
ty::FnPtr(f) => ty::FnPtr(f.try_fold_with(folder)?),
ty::Ref(r, ty, mutbl) => {
ty::Ref(r.try_fold_with(folder)?, ty.try_fold_with(folder)?, mutbl)
}
- ty::Generator(did, substs, movability) => {
- ty::Generator(did, substs.try_fold_with(folder)?, movability)
+ ty::Generator(did, args, movability) => {
+ ty::Generator(did, args.try_fold_with(folder)?, movability)
}
ty::GeneratorWitness(types) => ty::GeneratorWitness(types.try_fold_with(folder)?),
- ty::GeneratorWitnessMIR(did, substs) => {
- ty::GeneratorWitnessMIR(did, substs.try_fold_with(folder)?)
+ ty::GeneratorWitnessMIR(did, args) => {
+ ty::GeneratorWitnessMIR(did, args.try_fold_with(folder)?)
}
- ty::Closure(did, substs) => ty::Closure(did, substs.try_fold_with(folder)?),
+ ty::Closure(did, args) => ty::Closure(did, args.try_fold_with(folder)?),
ty::Alias(kind, data) => ty::Alias(kind, data.try_fold_with(folder)?),
ty::Bool
@@ -581,22 +743,22 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for Ty<'tcx> {
sz.visit_with(visitor)
}
ty::Slice(typ) => typ.visit_with(visitor),
- ty::Adt(_, substs) => substs.visit_with(visitor),
+ ty::Adt(_, args) => args.visit_with(visitor),
ty::Dynamic(ref trait_ty, ref reg, _) => {
trait_ty.visit_with(visitor)?;
reg.visit_with(visitor)
}
ty::Tuple(ts) => ts.visit_with(visitor),
- ty::FnDef(_, substs) => substs.visit_with(visitor),
+ ty::FnDef(_, args) => args.visit_with(visitor),
ty::FnPtr(ref f) => f.visit_with(visitor),
ty::Ref(r, ty, _) => {
r.visit_with(visitor)?;
ty.visit_with(visitor)
}
- ty::Generator(_did, ref substs, _) => substs.visit_with(visitor),
+ ty::Generator(_did, ref args, _) => args.visit_with(visitor),
ty::GeneratorWitness(ref types) => types.visit_with(visitor),
- ty::GeneratorWitnessMIR(_did, ref substs) => substs.visit_with(visitor),
- ty::Closure(_did, ref substs) => substs.visit_with(visitor),
+ ty::GeneratorWitnessMIR(_did, ref args) => args.visit_with(visitor),
+ ty::Closure(_did, ref args) => args.visit_with(visitor),
ty::Alias(_, ref data) => data.visit_with(visitor),
ty::Bool
@@ -776,7 +938,7 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::UnevaluatedConst<'tcx> {
&self,
visitor: &mut V,
) -> ControlFlow<V::BreakTy> {
- self.substs.visit_with(visitor)
+ self.args.visit_with(visitor)
}
}
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs
index 94746fbdc..0291cdd6c 100644
--- a/compiler/rustc_middle/src/ty/sty.rs
+++ b/compiler/rustc_middle/src/ty/sty.rs
@@ -3,19 +3,18 @@
#![allow(rustc::usage_of_ty_tykind)]
use crate::infer::canonical::Canonical;
-use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
use crate::ty::visit::ValidateBoundVars;
use crate::ty::InferTy::*;
use crate::ty::{
self, AdtDef, Discr, Term, Ty, TyCtxt, TypeFlags, TypeSuperVisitable, TypeVisitable,
TypeVisitableExt, TypeVisitor,
};
+use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
use crate::ty::{List, ParamEnv};
use hir::def::DefKind;
use polonius_engine::Atom;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::intern::Interned;
-use rustc_error_messages::DiagnosticMessage;
use rustc_errors::{DiagnosticArgValue, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
@@ -35,9 +34,12 @@ use std::ops::{ControlFlow, Deref, Range};
use ty::util::IntTypeExt;
use rustc_type_ir::sty::TyKind::*;
+use rustc_type_ir::CollectAndApply;
+use rustc_type_ir::ConstKind as IrConstKind;
+use rustc_type_ir::DebugWithInfcx;
+use rustc_type_ir::DynKind;
+use rustc_type_ir::RegionKind as IrRegionKind;
use rustc_type_ir::TyKind as IrTyKind;
-use rustc_type_ir::{CollectAndApply, ConstKind as IrConstKind};
-use rustc_type_ir::{DynKind, RegionKind as IrRegionKind};
use super::GenericParamDefKind;
@@ -215,7 +217,7 @@ impl<'tcx> Article for TyKind<'tcx> {
///
/// ## Generators
///
-/// Generators are handled similarly in `GeneratorSubsts`. The set of
+/// Generators are handled similarly in `GeneratorArgs`. The set of
/// type parameters is similar, but `CK` and `CS` are replaced by the
/// following type parameters:
///
@@ -228,33 +230,30 @@ impl<'tcx> Article for TyKind<'tcx> {
/// completion of the generator.
/// * `GW`: The "generator witness".
#[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable, Lift)]
-pub struct ClosureSubsts<'tcx> {
+pub struct ClosureArgs<'tcx> {
/// Lifetime and type parameters from the enclosing function,
/// concatenated with a tuple containing the types of the upvars.
///
/// These are separated out because codegen wants to pass them around
/// when monomorphizing.
- pub substs: SubstsRef<'tcx>,
+ pub args: GenericArgsRef<'tcx>,
}
/// Struct returned by `split()`.
-pub struct ClosureSubstsParts<'tcx, T> {
- pub parent_substs: &'tcx [GenericArg<'tcx>],
+pub struct ClosureArgsParts<'tcx, T> {
+ pub parent_args: &'tcx [GenericArg<'tcx>],
pub closure_kind_ty: T,
pub closure_sig_as_fn_ptr_ty: T,
pub tupled_upvars_ty: T,
}
-impl<'tcx> ClosureSubsts<'tcx> {
- /// Construct `ClosureSubsts` from `ClosureSubstsParts`, containing `Substs`
+impl<'tcx> ClosureArgs<'tcx> {
+ /// Construct `ClosureArgs` from `ClosureArgsParts`, containing `Args`
/// for the closure parent, alongside additional closure-specific components.
- pub fn new(
- tcx: TyCtxt<'tcx>,
- parts: ClosureSubstsParts<'tcx, Ty<'tcx>>,
- ) -> ClosureSubsts<'tcx> {
- ClosureSubsts {
- substs: tcx.mk_substs_from_iter(
- parts.parent_substs.iter().copied().chain(
+ pub fn new(tcx: TyCtxt<'tcx>, parts: ClosureArgsParts<'tcx, Ty<'tcx>>) -> ClosureArgs<'tcx> {
+ ClosureArgs {
+ args: tcx.mk_args_from_iter(
+ parts.parent_args.iter().copied().chain(
[parts.closure_kind_ty, parts.closure_sig_as_fn_ptr_ty, parts.tupled_upvars_ty]
.iter()
.map(|&ty| ty.into()),
@@ -263,53 +262,47 @@ impl<'tcx> ClosureSubsts<'tcx> {
}
}
- /// Divides the closure substs into their respective components.
- /// The ordering assumed here must match that used by `ClosureSubsts::new` above.
- fn split(self) -> ClosureSubstsParts<'tcx, GenericArg<'tcx>> {
- match self.substs[..] {
- [
- ref parent_substs @ ..,
- closure_kind_ty,
- closure_sig_as_fn_ptr_ty,
- tupled_upvars_ty,
- ] => ClosureSubstsParts {
- parent_substs,
- closure_kind_ty,
- closure_sig_as_fn_ptr_ty,
- tupled_upvars_ty,
- },
- _ => bug!("closure substs missing synthetics"),
+ /// Divides the closure args into their respective components.
+ /// The ordering assumed here must match that used by `ClosureArgs::new` above.
+ fn split(self) -> ClosureArgsParts<'tcx, GenericArg<'tcx>> {
+ match self.args[..] {
+ [ref parent_args @ .., closure_kind_ty, closure_sig_as_fn_ptr_ty, tupled_upvars_ty] => {
+ ClosureArgsParts {
+ parent_args,
+ closure_kind_ty,
+ closure_sig_as_fn_ptr_ty,
+ tupled_upvars_ty,
+ }
+ }
+ _ => bug!("closure args missing synthetics"),
}
}
/// Returns `true` only if enough of the synthetic types are known to
- /// allow using all of the methods on `ClosureSubsts` without panicking.
+ /// allow using all of the methods on `ClosureArgs` without panicking.
///
/// Used primarily by `ty::print::pretty` to be able to handle closure
/// types that haven't had their synthetic types substituted in.
pub fn is_valid(self) -> bool {
- self.substs.len() >= 3
- && matches!(self.split().tupled_upvars_ty.expect_ty().kind(), Tuple(_))
+ self.args.len() >= 3 && matches!(self.split().tupled_upvars_ty.expect_ty().kind(), Tuple(_))
}
/// Returns the substitutions of the closure's parent.
- pub fn parent_substs(self) -> &'tcx [GenericArg<'tcx>] {
- self.split().parent_substs
+ pub fn parent_args(self) -> &'tcx [GenericArg<'tcx>] {
+ self.split().parent_args
}
/// Returns an iterator over the list of types of captured paths by the closure.
/// In case there was a type error in figuring out the types of the captured path, an
/// empty iterator is returned.
#[inline]
- pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
+ pub fn upvar_tys(self) -> &'tcx List<Ty<'tcx>> {
match self.tupled_upvars_ty().kind() {
- TyKind::Error(_) => None,
- TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
+ TyKind::Error(_) => ty::List::empty(),
+ TyKind::Tuple(..) => self.tupled_upvars_ty().tuple_fields(),
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
}
- .into_iter()
- .flatten()
}
/// Returns the tuple type representing the upvars for this closure.
@@ -320,7 +313,7 @@ impl<'tcx> ClosureSubsts<'tcx> {
/// Returns the closure kind for this closure; may return a type
/// variable during inference. To get the closure kind during
- /// inference, use `infcx.closure_kind(substs)`.
+ /// inference, use `infcx.closure_kind(args)`.
pub fn kind_ty(self) -> Ty<'tcx> {
self.split().closure_kind_ty.expect_ty()
}
@@ -328,7 +321,7 @@ impl<'tcx> ClosureSubsts<'tcx> {
/// Returns the `fn` pointer type representing the closure signature for this
/// closure.
// FIXME(eddyb) this should be unnecessary, as the shallowly resolved
- // type is known at the time of the creation of `ClosureSubsts`,
+ // type is known at the time of the creation of `ClosureArgs`,
// see `rustc_hir_analysis::check::closure`.
pub fn sig_as_fn_ptr_ty(self) -> Ty<'tcx> {
self.split().closure_sig_as_fn_ptr_ty.expect_ty()
@@ -357,14 +350,14 @@ impl<'tcx> ClosureSubsts<'tcx> {
}
}
-/// Similar to `ClosureSubsts`; see the above documentation for more.
+/// Similar to `ClosureArgs`; see the above documentation for more.
#[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable, Lift)]
-pub struct GeneratorSubsts<'tcx> {
- pub substs: SubstsRef<'tcx>,
+pub struct GeneratorArgs<'tcx> {
+ pub args: GenericArgsRef<'tcx>,
}
-pub struct GeneratorSubstsParts<'tcx, T> {
- pub parent_substs: &'tcx [GenericArg<'tcx>],
+pub struct GeneratorArgsParts<'tcx, T> {
+ pub parent_args: &'tcx [GenericArg<'tcx>],
pub resume_ty: T,
pub yield_ty: T,
pub return_ty: T,
@@ -372,16 +365,16 @@ pub struct GeneratorSubstsParts<'tcx, T> {
pub tupled_upvars_ty: T,
}
-impl<'tcx> GeneratorSubsts<'tcx> {
- /// Construct `GeneratorSubsts` from `GeneratorSubstsParts`, containing `Substs`
+impl<'tcx> GeneratorArgs<'tcx> {
+ /// Construct `GeneratorArgs` from `GeneratorArgsParts`, containing `Args`
/// for the generator parent, alongside additional generator-specific components.
pub fn new(
tcx: TyCtxt<'tcx>,
- parts: GeneratorSubstsParts<'tcx, Ty<'tcx>>,
- ) -> GeneratorSubsts<'tcx> {
- GeneratorSubsts {
- substs: tcx.mk_substs_from_iter(
- parts.parent_substs.iter().copied().chain(
+ parts: GeneratorArgsParts<'tcx, Ty<'tcx>>,
+ ) -> GeneratorArgs<'tcx> {
+ GeneratorArgs {
+ args: tcx.mk_args_from_iter(
+ parts.parent_args.iter().copied().chain(
[
parts.resume_ty,
parts.yield_ty,
@@ -396,13 +389,13 @@ impl<'tcx> GeneratorSubsts<'tcx> {
}
}
- /// Divides the generator substs into their respective components.
- /// The ordering assumed here must match that used by `GeneratorSubsts::new` above.
- fn split(self) -> GeneratorSubstsParts<'tcx, GenericArg<'tcx>> {
- match self.substs[..] {
- [ref parent_substs @ .., resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty] => {
- GeneratorSubstsParts {
- parent_substs,
+ /// Divides the generator args into their respective components.
+ /// The ordering assumed here must match that used by `GeneratorArgs::new` above.
+ fn split(self) -> GeneratorArgsParts<'tcx, GenericArg<'tcx>> {
+ match self.args[..] {
+ [ref parent_args @ .., resume_ty, yield_ty, return_ty, witness, tupled_upvars_ty] => {
+ GeneratorArgsParts {
+ parent_args,
resume_ty,
yield_ty,
return_ty,
@@ -410,23 +403,22 @@ impl<'tcx> GeneratorSubsts<'tcx> {
tupled_upvars_ty,
}
}
- _ => bug!("generator substs missing synthetics"),
+ _ => bug!("generator args missing synthetics"),
}
}
/// Returns `true` only if enough of the synthetic types are known to
- /// allow using all of the methods on `GeneratorSubsts` without panicking.
+ /// allow using all of the methods on `GeneratorArgs` without panicking.
///
/// Used primarily by `ty::print::pretty` to be able to handle generator
/// types that haven't had their synthetic types substituted in.
pub fn is_valid(self) -> bool {
- self.substs.len() >= 5
- && matches!(self.split().tupled_upvars_ty.expect_ty().kind(), Tuple(_))
+ self.args.len() >= 5 && matches!(self.split().tupled_upvars_ty.expect_ty().kind(), Tuple(_))
}
/// Returns the substitutions of the generator's parent.
- pub fn parent_substs(self) -> &'tcx [GenericArg<'tcx>] {
- self.split().parent_substs
+ pub fn parent_args(self) -> &'tcx [GenericArg<'tcx>] {
+ self.split().parent_args
}
/// This describes the types that can be contained in a generator.
@@ -442,15 +434,13 @@ impl<'tcx> GeneratorSubsts<'tcx> {
/// In case there was a type error in figuring out the types of the captured path, an
/// empty iterator is returned.
#[inline]
- pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
+ pub fn upvar_tys(self) -> &'tcx List<Ty<'tcx>> {
match self.tupled_upvars_ty().kind() {
- TyKind::Error(_) => None,
- TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
+ TyKind::Error(_) => ty::List::empty(),
+ TyKind::Tuple(..) => self.tupled_upvars_ty().tuple_fields(),
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
}
- .into_iter()
- .flatten()
}
/// Returns the tuple type representing the upvars for this generator.
@@ -495,7 +485,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
}
}
-impl<'tcx> GeneratorSubsts<'tcx> {
+impl<'tcx> GeneratorArgs<'tcx> {
/// Generator has not been resumed yet.
pub const UNRESUMED: usize = 0;
/// Generator has returned or is completed.
@@ -574,7 +564,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
let layout = tcx.generator_layout(def_id).unwrap();
layout.variant_fields.iter().map(move |variant| {
variant.iter().map(move |field| {
- ty::EarlyBinder::bind(layout.field_tys[*field].ty).subst(tcx, self.substs)
+ ty::EarlyBinder::bind(layout.field_tys[*field].ty).instantiate(tcx, self.args)
})
})
}
@@ -582,43 +572,41 @@ impl<'tcx> GeneratorSubsts<'tcx> {
/// This is the types of the fields of a generator which are not stored in a
/// variant.
#[inline]
- pub fn prefix_tys(self) -> impl Iterator<Item = Ty<'tcx>> {
+ pub fn prefix_tys(self) -> &'tcx List<Ty<'tcx>> {
self.upvar_tys()
}
}
#[derive(Debug, Copy, Clone, HashStable)]
-pub enum UpvarSubsts<'tcx> {
- Closure(SubstsRef<'tcx>),
- Generator(SubstsRef<'tcx>),
+pub enum UpvarArgs<'tcx> {
+ Closure(GenericArgsRef<'tcx>),
+ Generator(GenericArgsRef<'tcx>),
}
-impl<'tcx> UpvarSubsts<'tcx> {
+impl<'tcx> UpvarArgs<'tcx> {
/// Returns an iterator over the list of types of captured paths by the closure/generator.
/// In case there was a type error in figuring out the types of the captured path, an
/// empty iterator is returned.
#[inline]
- pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
+ pub fn upvar_tys(self) -> &'tcx List<Ty<'tcx>> {
let tupled_tys = match self {
- UpvarSubsts::Closure(substs) => substs.as_closure().tupled_upvars_ty(),
- UpvarSubsts::Generator(substs) => substs.as_generator().tupled_upvars_ty(),
+ UpvarArgs::Closure(args) => args.as_closure().tupled_upvars_ty(),
+ UpvarArgs::Generator(args) => args.as_generator().tupled_upvars_ty(),
};
match tupled_tys.kind() {
- TyKind::Error(_) => None,
- TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
+ TyKind::Error(_) => ty::List::empty(),
+ TyKind::Tuple(..) => self.tupled_upvars_ty().tuple_fields(),
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
}
- .into_iter()
- .flatten()
}
#[inline]
pub fn tupled_upvars_ty(self) -> Ty<'tcx> {
match self {
- UpvarSubsts::Closure(substs) => substs.as_closure().tupled_upvars_ty(),
- UpvarSubsts::Generator(substs) => substs.as_generator().tupled_upvars_ty(),
+ UpvarArgs::Closure(args) => args.as_closure().tupled_upvars_ty(),
+ UpvarArgs::Generator(args) => args.as_generator().tupled_upvars_ty(),
}
}
}
@@ -635,46 +623,46 @@ impl<'tcx> UpvarSubsts<'tcx> {
///
/// When the inline const is instantiated, `R` is substituted as the actual inferred
/// type of the constant. The reason that `R` is represented as an extra type parameter
-/// is the same reason that [`ClosureSubsts`] have `CS` and `U` as type parameters:
+/// is the same reason that [`ClosureArgs`] have `CS` and `U` as type parameters:
/// inline const can reference lifetimes that are internal to the creating function.
#[derive(Copy, Clone, Debug)]
-pub struct InlineConstSubsts<'tcx> {
+pub struct InlineConstArgs<'tcx> {
/// Generic parameters from the enclosing item,
/// concatenated with the inferred type of the constant.
- pub substs: SubstsRef<'tcx>,
+ pub args: GenericArgsRef<'tcx>,
}
/// Struct returned by `split()`.
-pub struct InlineConstSubstsParts<'tcx, T> {
- pub parent_substs: &'tcx [GenericArg<'tcx>],
+pub struct InlineConstArgsParts<'tcx, T> {
+ pub parent_args: &'tcx [GenericArg<'tcx>],
pub ty: T,
}
-impl<'tcx> InlineConstSubsts<'tcx> {
- /// Construct `InlineConstSubsts` from `InlineConstSubstsParts`.
+impl<'tcx> InlineConstArgs<'tcx> {
+ /// Construct `InlineConstArgs` from `InlineConstArgsParts`.
pub fn new(
tcx: TyCtxt<'tcx>,
- parts: InlineConstSubstsParts<'tcx, Ty<'tcx>>,
- ) -> InlineConstSubsts<'tcx> {
- InlineConstSubsts {
- substs: tcx.mk_substs_from_iter(
- parts.parent_substs.iter().copied().chain(std::iter::once(parts.ty.into())),
+ parts: InlineConstArgsParts<'tcx, Ty<'tcx>>,
+ ) -> InlineConstArgs<'tcx> {
+ InlineConstArgs {
+ args: tcx.mk_args_from_iter(
+ parts.parent_args.iter().copied().chain(std::iter::once(parts.ty.into())),
),
}
}
- /// Divides the inline const substs into their respective components.
- /// The ordering assumed here must match that used by `InlineConstSubsts::new` above.
- fn split(self) -> InlineConstSubstsParts<'tcx, GenericArg<'tcx>> {
- match self.substs[..] {
- [ref parent_substs @ .., ty] => InlineConstSubstsParts { parent_substs, ty },
- _ => bug!("inline const substs missing synthetics"),
+ /// Divides the inline const args into their respective components.
+ /// The ordering assumed here must match that used by `InlineConstArgs::new` above.
+ fn split(self) -> InlineConstArgsParts<'tcx, GenericArg<'tcx>> {
+ match self.args[..] {
+ [ref parent_args @ .., ty] => InlineConstArgsParts { parent_args, ty },
+ _ => bug!("inline const args missing synthetics"),
}
}
/// Returns the substitutions of the inline const's parent.
- pub fn parent_substs(self) -> &'tcx [GenericArg<'tcx>] {
- self.split().parent_substs
+ pub fn parent_args(self) -> &'tcx [GenericArg<'tcx>] {
+ self.split().parent_args
}
/// Returns the type of this inline const.
@@ -694,6 +682,15 @@ pub enum ExistentialPredicate<'tcx> {
AutoTrait(DefId),
}
+impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ExistentialPredicate<'tcx> {
+ fn fmt<InfCtx: rustc_type_ir::InferCtxtLike<TyCtxt<'tcx>>>(
+ this: rustc_type_ir::OptWithInfcx<'_, TyCtxt<'tcx>, InfCtx, &Self>,
+ f: &mut core::fmt::Formatter<'_>,
+ ) -> core::fmt::Result {
+ fmt::Debug::fmt(&this.data, f)
+ }
+}
+
impl<'tcx> ExistentialPredicate<'tcx> {
/// Compares via an ordering that will not change if modules are reordered or other changes are
/// made to the tree. In particular, this ordering is preserved across incremental compilations.
@@ -725,7 +722,7 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
use crate::ty::ToPredicate;
match self.skip_binder() {
ExistentialPredicate::Trait(tr) => {
- self.rebind(tr).with_self_ty(tcx, self_ty).without_const().to_predicate(tcx)
+ self.rebind(tr).with_self_ty(tcx, self_ty).to_predicate(tcx)
}
ExistentialPredicate::Projection(p) => {
self.rebind(p.with_self_ty(tcx, self_ty)).to_predicate(tcx)
@@ -736,12 +733,11 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
ty::TraitRef::new(tcx, did, [self_ty])
} else {
// If this is an ill-formed auto trait, then synthesize
- // new error substs for the missing generics.
- let err_substs =
- ty::InternalSubsts::extend_with_error(tcx, did, &[self_ty.into()]);
- ty::TraitRef::new(tcx, did, err_substs)
+ // new error args for the missing generics.
+ let err_args = ty::GenericArgs::extend_with_error(tcx, did, &[self_ty.into()]);
+ ty::TraitRef::new(tcx, did, err_args)
};
- self.rebind(trait_ref).without_const().to_predicate(tcx)
+ self.rebind(trait_ref).to_predicate(tcx)
}
}
}
@@ -815,7 +811,7 @@ impl<'tcx> List<ty::PolyExistentialPredicate<'tcx>> {
/// T: Foo<U>
/// ```
/// This would be represented by a trait-reference where the `DefId` is the
-/// `DefId` for the trait `Foo` and the substs define `T` as parameter 0,
+/// `DefId` for the trait `Foo` and the args define `T` as parameter 0,
/// and `U` as parameter 1.
///
/// Trait references also appear in object types like `Foo<U>`, but in
@@ -824,7 +820,7 @@ impl<'tcx> List<ty::PolyExistentialPredicate<'tcx>> {
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
pub struct TraitRef<'tcx> {
pub def_id: DefId,
- pub substs: SubstsRef<'tcx>,
+ pub args: GenericArgsRef<'tcx>,
/// This field exists to prevent the creation of `TraitRef` without
/// calling [`TraitRef::new`].
pub(super) _use_trait_ref_new_instead: (),
@@ -834,60 +830,48 @@ impl<'tcx> TraitRef<'tcx> {
pub fn new(
tcx: TyCtxt<'tcx>,
trait_def_id: DefId,
- substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
+ args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
) -> Self {
- let substs = tcx.check_and_mk_substs(trait_def_id, substs);
- Self { def_id: trait_def_id, substs, _use_trait_ref_new_instead: () }
+ let args = tcx.check_and_mk_args(trait_def_id, args);
+ Self { def_id: trait_def_id, args, _use_trait_ref_new_instead: () }
}
pub fn from_lang_item(
tcx: TyCtxt<'tcx>,
trait_lang_item: LangItem,
span: Span,
- substs: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
+ args: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
) -> Self {
let trait_def_id = tcx.require_lang_item(trait_lang_item, Some(span));
- Self::new(tcx, trait_def_id, substs)
+ Self::new(tcx, trait_def_id, args)
}
pub fn from_method(
tcx: TyCtxt<'tcx>,
trait_id: DefId,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
) -> ty::TraitRef<'tcx> {
let defs = tcx.generics_of(trait_id);
- ty::TraitRef::new(tcx, trait_id, tcx.mk_substs(&substs[..defs.params.len()]))
+ ty::TraitRef::new(tcx, trait_id, tcx.mk_args(&args[..defs.params.len()]))
}
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
/// are the parameters defined on trait.
pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> TraitRef<'tcx> {
- ty::TraitRef::new(tcx, def_id, InternalSubsts::identity_for_item(tcx, def_id))
+ ty::TraitRef::new(tcx, def_id, GenericArgs::identity_for_item(tcx, def_id))
}
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
ty::TraitRef::new(
tcx,
self.def_id,
- [self_ty.into()].into_iter().chain(self.substs.iter().skip(1)),
+ [self_ty.into()].into_iter().chain(self.args.iter().skip(1)),
)
}
- /// Converts this trait ref to a trait predicate with a given `constness` and a positive polarity.
- #[inline]
- pub fn with_constness(self, constness: ty::BoundConstness) -> ty::TraitPredicate<'tcx> {
- ty::TraitPredicate { trait_ref: self, constness, polarity: ty::ImplPolarity::Positive }
- }
-
- /// Converts this trait ref to a trait predicate without `const` and a positive polarity.
- #[inline]
- pub fn without_const(self) -> ty::TraitPredicate<'tcx> {
- self.with_constness(ty::BoundConstness::NotConst)
- }
-
#[inline]
pub fn self_ty(&self) -> Ty<'tcx> {
- self.substs.type_at(0)
+ self.args.type_at(0)
}
}
@@ -920,7 +904,7 @@ impl<'tcx> IntoDiagnosticArg for TraitRef<'tcx> {
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
pub struct ExistentialTraitRef<'tcx> {
pub def_id: DefId,
- pub substs: SubstsRef<'tcx>,
+ pub args: GenericArgsRef<'tcx>,
}
impl<'tcx> ExistentialTraitRef<'tcx> {
@@ -929,11 +913,11 @@ impl<'tcx> ExistentialTraitRef<'tcx> {
trait_ref: ty::TraitRef<'tcx>,
) -> ty::ExistentialTraitRef<'tcx> {
// Assert there is a Self.
- trait_ref.substs.type_at(0);
+ trait_ref.args.type_at(0);
ty::ExistentialTraitRef {
def_id: trait_ref.def_id,
- substs: tcx.mk_substs(&trait_ref.substs[1..]),
+ args: tcx.mk_args(&trait_ref.args[1..]),
}
}
@@ -945,7 +929,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> {
// otherwise the escaping vars would be captured by the binder
// debug_assert!(!self_ty.has_escaping_bound_vars());
- ty::TraitRef::new(tcx, self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter()))
+ ty::TraitRef::new(tcx, self.def_id, [self_ty.into()].into_iter().chain(self.args.iter()))
}
}
@@ -1214,7 +1198,7 @@ pub struct AliasTy<'tcx> {
///
/// For RPIT the substitutions are for the generics of the function,
/// while for TAIT it is used for the generic parameters of the alias.
- pub substs: SubstsRef<'tcx>,
+ pub args: GenericArgsRef<'tcx>,
/// The `DefId` of the `TraitItem` or `ImplItem` for the associated type `N` depending on whether
/// this is a projection or an inherent projection or the `DefId` of the `OpaqueType` item if
@@ -1237,9 +1221,9 @@ impl<'tcx> AliasTy<'tcx> {
pub fn kind(self, tcx: TyCtxt<'tcx>) -> ty::AliasKind {
match tcx.def_kind(self.def_id) {
DefKind::AssocTy if let DefKind::Impl { of_trait: false } = tcx.def_kind(tcx.parent(self.def_id)) => ty::Inherent,
- DefKind::AssocTy | DefKind::ImplTraitPlaceholder => ty::Projection,
+ DefKind::AssocTy => ty::Projection,
DefKind::OpaqueTy => ty::Opaque,
- DefKind::TyAlias => ty::Weak,
+ DefKind::TyAlias { .. } => ty::Weak,
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
}
}
@@ -1252,11 +1236,11 @@ impl<'tcx> AliasTy<'tcx> {
/// The following methods work only with associated type projections.
impl<'tcx> AliasTy<'tcx> {
pub fn self_ty(self) -> Ty<'tcx> {
- self.substs.type_at(0)
+ self.args.type_at(0)
}
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
- tcx.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter().skip(1)))
+ tcx.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.args.iter().skip(1)))
}
}
@@ -1265,17 +1249,14 @@ impl<'tcx> AliasTy<'tcx> {
pub fn trait_def_id(self, tcx: TyCtxt<'tcx>) -> DefId {
match tcx.def_kind(self.def_id) {
DefKind::AssocTy | DefKind::AssocConst => tcx.parent(self.def_id),
- DefKind::ImplTraitPlaceholder => {
- tcx.parent(tcx.impl_trait_in_trait_parent_fn(self.def_id))
- }
kind => bug!("expected a projection AliasTy; found {kind:?}"),
}
}
- /// Extracts the underlying trait reference and own substs from this projection.
+ /// Extracts the underlying trait reference and own args from this projection.
/// For example, if this is a projection of `<T as StreamingIterator>::Item<'a>`,
- /// then this function would return a `T: StreamingIterator` trait reference and `['a]` as the own substs
- pub fn trait_ref_and_own_substs(
+ /// then this function would return a `T: StreamingIterator` trait reference and `['a]` as the own args
+ pub fn trait_ref_and_own_args(
self,
tcx: TyCtxt<'tcx>,
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) {
@@ -1283,8 +1264,8 @@ impl<'tcx> AliasTy<'tcx> {
let trait_def_id = self.trait_def_id(tcx);
let trait_generics = tcx.generics_of(trait_def_id);
(
- ty::TraitRef::new(tcx, trait_def_id, self.substs.truncate_to(tcx, trait_generics)),
- &self.substs[trait_generics.count()..],
+ ty::TraitRef::new(tcx, trait_def_id, self.args.truncate_to(tcx, trait_generics)),
+ &self.args[trait_generics.count()..],
)
}
@@ -1292,18 +1273,18 @@ impl<'tcx> AliasTy<'tcx> {
/// For example, if this is a projection of `<T as Iterator>::Item`,
/// then this function would return a `T: Iterator` trait reference.
///
- /// WARNING: This will drop the substs for generic associated types
- /// consider calling [Self::trait_ref_and_own_substs] to get those
+ /// WARNING: This will drop the args for generic associated types
+ /// consider calling [Self::trait_ref_and_own_args] to get those
/// as well.
pub fn trait_ref(self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> {
let def_id = self.trait_def_id(tcx);
- ty::TraitRef::new(tcx, def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id)))
+ ty::TraitRef::new(tcx, def_id, self.args.truncate_to(tcx, tcx.generics_of(def_id)))
}
}
/// The following methods work only with inherent associated type projections.
impl<'tcx> AliasTy<'tcx> {
- /// Transform the substitutions to have the given `impl` substs as the base and the GAT substs on top of that.
+ /// Transform the substitutions to have the given `impl` args as the base and the GAT args on top of that.
///
/// Does the following transformation:
///
@@ -1313,14 +1294,14 @@ impl<'tcx> AliasTy<'tcx> {
/// I_i impl subst
/// P_j GAT subst
/// ```
- pub fn rebase_substs_onto_impl(
+ pub fn rebase_inherent_args_onto_impl(
self,
- impl_substs: ty::SubstsRef<'tcx>,
+ impl_args: ty::GenericArgsRef<'tcx>,
tcx: TyCtxt<'tcx>,
- ) -> ty::SubstsRef<'tcx> {
+ ) -> ty::GenericArgsRef<'tcx> {
debug_assert_eq!(self.kind(tcx), ty::Inherent);
- tcx.mk_substs_from_iter(impl_substs.into_iter().chain(self.substs.into_iter().skip(1)))
+ tcx.mk_args_from_iter(impl_args.into_iter().chain(self.args.into_iter().skip(1)))
}
}
@@ -1574,12 +1555,6 @@ impl<'tcx> Deref for Region<'tcx> {
}
}
-impl<'tcx> fmt::Debug for Region<'tcx> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{:?}", self.kind())
- }
-}
-
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
#[derive(HashStable)]
pub struct EarlyBoundRegion {
@@ -1646,7 +1621,7 @@ impl From<BoundVar> for BoundTy {
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
pub struct ExistentialProjection<'tcx> {
pub def_id: DefId,
- pub substs: SubstsRef<'tcx>,
+ pub args: GenericArgsRef<'tcx>,
pub term: Term<'tcx>,
}
@@ -1660,8 +1635,8 @@ impl<'tcx> ExistentialProjection<'tcx> {
pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::ExistentialTraitRef<'tcx> {
let def_id = tcx.parent(self.def_id);
let subst_count = tcx.generics_of(def_id).count() - 1;
- let substs = tcx.mk_substs(&self.substs[..subst_count]);
- ty::ExistentialTraitRef { def_id, substs }
+ let args = tcx.mk_args(&self.args[..subst_count]);
+ ty::ExistentialTraitRef { def_id, args }
}
pub fn with_self_ty(
@@ -1674,7 +1649,7 @@ impl<'tcx> ExistentialProjection<'tcx> {
ty::ProjectionPredicate {
projection_ty: tcx
- .mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.substs)),
+ .mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.args)),
term: self.term,
}
}
@@ -1684,11 +1659,11 @@ impl<'tcx> ExistentialProjection<'tcx> {
projection_predicate: ty::ProjectionPredicate<'tcx>,
) -> Self {
// Assert there is a Self.
- projection_predicate.projection_ty.substs.type_at(0);
+ projection_predicate.projection_ty.args.type_at(0);
Self {
def_id: projection_predicate.projection_ty.def_id,
- substs: tcx.mk_substs(&projection_predicate.projection_ty.substs[1..]),
+ args: tcx.mk_args(&projection_predicate.projection_ty.args[1..]),
term: projection_predicate.term,
}
}
@@ -1970,15 +1945,14 @@ impl<'tcx> Ty<'tcx> {
(kind, tcx.def_kind(alias_ty.def_id)),
(ty::Opaque, DefKind::OpaqueTy)
| (ty::Projection | ty::Inherent, DefKind::AssocTy)
- | (ty::Opaque | ty::Projection, DefKind::ImplTraitPlaceholder)
- | (ty::Weak, DefKind::TyAlias)
+ | (ty::Weak, DefKind::TyAlias { .. })
);
Ty::new(tcx, Alias(kind, alias_ty))
}
#[inline]
- pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
- Ty::new_alias(tcx, ty::Opaque, tcx.mk_alias_ty(def_id, substs))
+ pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
+ Ty::new_alias(tcx, ty::Opaque, tcx.mk_alias_ty(def_id, args))
}
/// Constructs a `TyKind::Error` type with current `ErrorGuaranteed`
@@ -1998,7 +1972,7 @@ impl<'tcx> Ty<'tcx> {
pub fn new_error_with_message<S: Into<MultiSpan>>(
tcx: TyCtxt<'tcx>,
span: S,
- msg: impl Into<DiagnosticMessage>,
+ msg: impl Into<String>,
) -> Ty<'tcx> {
let reported = tcx.sess.delay_span_bug(span, msg);
Ty::new(tcx, Error(reported))
@@ -2070,8 +2044,8 @@ impl<'tcx> Ty<'tcx> {
}
#[inline]
- pub fn new_adt(tcx: TyCtxt<'tcx>, def: AdtDef<'tcx>, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
- Ty::new(tcx, Adt(def, substs))
+ pub fn new_adt(tcx: TyCtxt<'tcx>, def: AdtDef<'tcx>, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
+ Ty::new(tcx, Adt(def, args))
}
#[inline]
@@ -2115,10 +2089,10 @@ impl<'tcx> Ty<'tcx> {
pub fn new_fn_def(
tcx: TyCtxt<'tcx>,
def_id: DefId,
- substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
+ args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
) -> Ty<'tcx> {
- let substs = tcx.check_and_mk_substs(def_id, substs);
- Ty::new(tcx, FnDef(def_id, substs))
+ let args = tcx.check_and_mk_args(def_id, args);
+ Ty::new(tcx, FnDef(def_id, args))
}
#[inline]
@@ -2140,38 +2114,38 @@ impl<'tcx> Ty<'tcx> {
pub fn new_projection(
tcx: TyCtxt<'tcx>,
item_def_id: DefId,
- substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
+ args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
) -> Ty<'tcx> {
- Ty::new_alias(tcx, ty::Projection, tcx.mk_alias_ty(item_def_id, substs))
+ Ty::new_alias(tcx, ty::Projection, tcx.mk_alias_ty(item_def_id, args))
}
#[inline]
pub fn new_closure(
tcx: TyCtxt<'tcx>,
def_id: DefId,
- closure_substs: SubstsRef<'tcx>,
+ closure_args: GenericArgsRef<'tcx>,
) -> Ty<'tcx> {
debug_assert_eq!(
- closure_substs.len(),
+ closure_args.len(),
tcx.generics_of(tcx.typeck_root_def_id(def_id)).count() + 3,
"closure constructed with incorrect substitutions"
);
- Ty::new(tcx, Closure(def_id, closure_substs))
+ Ty::new(tcx, Closure(def_id, closure_args))
}
#[inline]
pub fn new_generator(
tcx: TyCtxt<'tcx>,
def_id: DefId,
- generator_substs: SubstsRef<'tcx>,
+ generator_args: GenericArgsRef<'tcx>,
movability: hir::Movability,
) -> Ty<'tcx> {
debug_assert_eq!(
- generator_substs.len(),
+ generator_args.len(),
tcx.generics_of(tcx.typeck_root_def_id(def_id)).count() + 5,
"generator constructed with incorrect number of substitutions"
);
- Ty::new(tcx, Generator(def_id, generator_substs, movability))
+ Ty::new(tcx, Generator(def_id, generator_args, movability))
}
#[inline]
@@ -2186,9 +2160,9 @@ impl<'tcx> Ty<'tcx> {
pub fn new_generator_witness_mir(
tcx: TyCtxt<'tcx>,
id: DefId,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
) -> Ty<'tcx> {
- Ty::new(tcx, GeneratorWitnessMIR(id, substs))
+ Ty::new(tcx, GeneratorWitnessMIR(id, args))
}
// misc
@@ -2212,19 +2186,18 @@ impl<'tcx> Ty<'tcx> {
fn new_generic_adt(tcx: TyCtxt<'tcx>, wrapper_def_id: DefId, ty_param: Ty<'tcx>) -> Ty<'tcx> {
let adt_def = tcx.adt_def(wrapper_def_id);
- let substs =
- InternalSubsts::for_item(tcx, wrapper_def_id, |param, substs| match param.kind {
- GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => bug!(),
- GenericParamDefKind::Type { has_default, .. } => {
- if param.index == 0 {
- ty_param.into()
- } else {
- assert!(has_default);
- tcx.type_of(param.def_id).subst(tcx, substs).into()
- }
+ let args = GenericArgs::for_item(tcx, wrapper_def_id, |param, args| match param.kind {
+ GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => bug!(),
+ GenericParamDefKind::Type { has_default, .. } => {
+ if param.index == 0 {
+ ty_param.into()
+ } else {
+ assert!(has_default);
+ tcx.type_of(param.def_id).instantiate(tcx, args).into()
}
- });
- Ty::new(tcx, Adt(adt_def, substs))
+ }
+ });
+ Ty::new(tcx, Adt(adt_def, args))
}
#[inline]
@@ -2255,8 +2228,8 @@ impl<'tcx> Ty<'tcx> {
pub fn new_task_context(tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
let context_did = tcx.require_lang_item(LangItem::Context, None);
let context_adt_ref = tcx.adt_def(context_did);
- let context_substs = tcx.mk_substs(&[tcx.lifetimes.re_erased.into()]);
- let context_ty = Ty::new_adt(tcx, context_adt_ref, context_substs);
+ let context_args = tcx.mk_args(&[tcx.lifetimes.re_erased.into()]);
+ let context_ty = Ty::new_adt(tcx, context_adt_ref, context_args);
Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, context_ty)
}
}
@@ -2380,10 +2353,10 @@ impl<'tcx> Ty<'tcx> {
pub fn simd_size_and_type(self, tcx: TyCtxt<'tcx>) -> (u64, Ty<'tcx>) {
match self.kind() {
- Adt(def, substs) => {
+ Adt(def, args) => {
assert!(def.repr().simd(), "`simd_size_and_type` called on non-SIMD type");
let variant = def.non_enum_variant();
- let f0_ty = variant.fields[FieldIdx::from_u32(0)].ty(tcx, substs);
+ let f0_ty = variant.fields[FieldIdx::from_u32(0)].ty(tcx, args);
match f0_ty.kind() {
// If the first field is an array, we assume it is the only field and its
@@ -2444,7 +2417,7 @@ impl<'tcx> Ty<'tcx> {
/// Panics if called on any type other than `Box<T>`.
pub fn boxed_ty(self) -> Ty<'tcx> {
match self.kind() {
- Adt(def, substs) if def.is_box() => substs.type_at(0),
+ Adt(def, args) if def.is_box() => args.type_at(0),
_ => bug!("`boxed_ty` is called on non-box type {:?}", self),
}
}
@@ -2608,14 +2581,14 @@ impl<'tcx> Ty<'tcx> {
pub fn fn_sig(self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> {
match self.kind() {
- FnDef(def_id, substs) => tcx.fn_sig(*def_id).subst(tcx, substs),
+ FnDef(def_id, args) => tcx.fn_sig(*def_id).instantiate(tcx, args),
FnPtr(f) => *f,
Error(_) => {
// ignore errors (#54954)
ty::Binder::dummy(FnSig::fake())
}
Closure(..) => bug!(
- "to get the signature of a closure, use `substs.as_closure().sig()` not `fn_sig()`",
+ "to get the signature of a closure, use `args.as_closure().sig()` not `fn_sig()`",
),
_ => bug!("Ty::fn_sig() called on non-fn type: {:?}", self),
}
@@ -2649,7 +2622,7 @@ impl<'tcx> Ty<'tcx> {
#[inline]
pub fn tuple_fields(self) -> &'tcx List<Ty<'tcx>> {
match self.kind() {
- Tuple(substs) => substs,
+ Tuple(args) => args,
_ => bug!("tuple_fields called on non-tuple"),
}
}
@@ -2661,8 +2634,8 @@ impl<'tcx> Ty<'tcx> {
pub fn variant_range(self, tcx: TyCtxt<'tcx>) -> Option<Range<VariantIdx>> {
match self.kind() {
TyKind::Adt(adt, _) => Some(adt.variant_range()),
- TyKind::Generator(def_id, substs, _) => {
- Some(substs.as_generator().variant_range(*def_id, tcx))
+ TyKind::Generator(def_id, args, _) => {
+ Some(args.as_generator().variant_range(*def_id, tcx))
}
_ => None,
}
@@ -2679,16 +2652,11 @@ impl<'tcx> Ty<'tcx> {
variant_index: VariantIdx,
) -> Option<Discr<'tcx>> {
match self.kind() {
- TyKind::Adt(adt, _) if adt.variants().is_empty() => {
- // This can actually happen during CTFE, see
- // https://github.com/rust-lang/rust/issues/89765.
- None
- }
TyKind::Adt(adt, _) if adt.is_enum() => {
Some(adt.discriminant_for_variant(tcx, variant_index))
}
- TyKind::Generator(def_id, substs, _) => {
- Some(substs.as_generator().discriminant_for_variant(*def_id, tcx, variant_index))
+ TyKind::Generator(def_id, args, _) => {
+ Some(args.as_generator().discriminant_for_variant(*def_id, tcx, variant_index))
}
_ => None,
}
@@ -2698,13 +2666,13 @@ impl<'tcx> Ty<'tcx> {
pub fn discriminant_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match self.kind() {
ty::Adt(adt, _) if adt.is_enum() => adt.repr().discr_type().to_ty(tcx),
- ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx),
+ ty::Generator(_, args, _) => args.as_generator().discr_ty(tcx),
ty::Param(_) | ty::Alias(..) | ty::Infer(ty::TyVar(_)) => {
let assoc_items = tcx.associated_item_def_ids(
tcx.require_lang_item(hir::LangItem::DiscriminantKind, None),
);
- Ty::new_projection(tcx, assoc_items[0], tcx.mk_substs(&[self.into()]))
+ Ty::new_projection(tcx, assoc_items[0], tcx.mk_args(&[self.into()]))
}
ty::Bool
@@ -2777,7 +2745,7 @@ impl<'tcx> Ty<'tcx> {
ty::Str | ty::Slice(_) => (tcx.types.usize, false),
ty::Dynamic(..) => {
let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, None);
- (tcx.type_of(dyn_metadata).subst(tcx, &[tail.into()]), false)
+ (tcx.type_of(dyn_metadata).instantiate(tcx, &[tail.into()]), false)
},
// type parameters only have unit metadata if they're sized, so return true
@@ -2794,7 +2762,7 @@ impl<'tcx> Ty<'tcx> {
}
/// When we create a closure, we record its kind (i.e., what trait
- /// it implements) into its `ClosureSubsts` using a type
+ /// it implements) into its `ClosureArgs` using a type
/// parameter. This is kind of a phantom type, except that the
/// most convenient thing for us to are the integral types. This
/// function converts such a special type into the closure
@@ -2857,13 +2825,13 @@ impl<'tcx> Ty<'tcx> {
ty::Tuple(tys) => tys.iter().all(|ty| ty.is_trivially_sized(tcx)),
- ty::Adt(def, _substs) => def.sized_constraint(tcx).skip_binder().is_empty(),
+ ty::Adt(def, _args) => def.sized_constraint(tcx).skip_binder().is_empty(),
- ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => false,
+ ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) | ty::Bound(..) => false,
ty::Infer(ty::TyVar(_)) => false,
- ty::Bound(..) | ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
+ ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
bug!("`is_trivially_sized` applied to unexpected type: {:?}", self)
}
}
diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs
index 98c70e330..6e55e7915 100644
--- a/compiler/rustc_middle/src/ty/trait_def.rs
+++ b/compiler/rustc_middle/src/ty/trait_def.rs
@@ -236,7 +236,7 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
for &impl_def_id in tcx.hir().trait_impls(trait_id) {
let impl_def_id = impl_def_id.to_def_id();
- let impl_self_ty = tcx.type_of(impl_def_id).subst_identity();
+ let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
if impl_self_ty.references_error() {
continue;
}
diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs
index 8cbffa148..327cd0a5d 100644
--- a/compiler/rustc_middle/src/ty/typeck_results.rs
+++ b/compiler/rustc_middle/src/ty/typeck_results.rs
@@ -4,13 +4,12 @@ use crate::{
traits::ObligationCause,
ty::{
self, tls, BindingMode, BoundVar, CanonicalPolyFnSig, ClosureSizeProfileData,
- GenericArgKind, InternalSubsts, SubstsRef, Ty, UserSubsts,
+ GenericArgKind, GenericArgs, GenericArgsRef, Ty, UserArgs,
},
};
use rustc_data_structures::{
- fx::{FxHashMap, FxIndexMap},
- sync::Lrc,
- unord::{UnordItems, UnordSet},
+ fx::FxIndexMap,
+ unord::{ExtendUnord, UnordItems, UnordSet},
};
use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir;
@@ -54,7 +53,7 @@ pub struct TypeckResults<'tcx> {
/// of this node. This only applies to nodes that refer to entities
/// parameterized by type parameters, such as generic fns, types, or
/// other items.
- node_substs: ItemLocalMap<SubstsRef<'tcx>>,
+ node_args: ItemLocalMap<GenericArgsRef<'tcx>>,
/// This will either store the canonicalized types provided by the user
/// or the substitutions that the user explicitly gave (if any) attached
@@ -145,7 +144,7 @@ pub struct TypeckResults<'tcx> {
/// This is used for warning unused imports. During type
/// checking, this `Lrc` should not be cloned: it must have a ref-count
/// of 1 so that we can insert things into the set mutably.
- pub used_trait_imports: Lrc<UnordSet<LocalDefId>>,
+ pub used_trait_imports: UnordSet<LocalDefId>,
/// If any errors occurred while type-checking this body,
/// this field will be set to `Some(ErrorGuaranteed)`.
@@ -183,7 +182,7 @@ pub struct TypeckResults<'tcx> {
/// we never capture `t`. This becomes an issue when we build MIR as we require
/// information on `t` in order to create place `t.0` and `t.1`. We can solve this
/// issue by fake reading `t`.
- pub closure_fake_reads: FxHashMap<LocalDefId, Vec<(HirPlace<'tcx>, FakeReadCause, hir::HirId)>>,
+ pub closure_fake_reads: LocalDefIdMap<Vec<(HirPlace<'tcx>, FakeReadCause, hir::HirId)>>,
/// Tracks the rvalue scoping rules which defines finer scoping for rvalue expressions
/// by applying extended parameter rules.
@@ -197,7 +196,7 @@ pub struct TypeckResults<'tcx> {
/// Stores the predicates that apply on generator witness types.
/// formatting modified file tests/ui/generator/retain-resume-ref.rs
pub generator_interior_predicates:
- FxHashMap<LocalDefId, Vec<(ty::Predicate<'tcx>, ObligationCause<'tcx>)>>,
+ LocalDefIdMap<Vec<(ty::Predicate<'tcx>, ObligationCause<'tcx>)>>,
/// We sometimes treat byte string literals (which are of type `&[u8; N]`)
/// as `&[u8]`, depending on the pattern in which they are used.
@@ -207,7 +206,7 @@ pub struct TypeckResults<'tcx> {
/// Contains the data for evaluating the effect of feature `capture_disjoint_fields`
/// on closure size.
- pub closure_size_eval: FxHashMap<LocalDefId, ClosureSizeProfileData<'tcx>>,
+ pub closure_size_eval: LocalDefIdMap<ClosureSizeProfileData<'tcx>>,
/// Container types and field indices of `offset_of!` expressions
offset_of_data: ItemLocalMap<(Ty<'tcx>, Vec<FieldIdx>)>,
@@ -265,7 +264,7 @@ impl<'tcx> TypeckResults<'tcx> {
user_provided_types: Default::default(),
user_provided_sigs: Default::default(),
node_types: Default::default(),
- node_substs: Default::default(),
+ node_args: Default::default(),
adjustments: Default::default(),
pat_binding_modes: Default::default(),
pat_adjustments: Default::default(),
@@ -273,7 +272,7 @@ impl<'tcx> TypeckResults<'tcx> {
liberated_fn_sigs: Default::default(),
fru_field_types: Default::default(),
coercion_casts: Default::default(),
- used_trait_imports: Lrc::new(Default::default()),
+ used_trait_imports: Default::default(),
tainted_by_errors: None,
concrete_opaque_types: Default::default(),
closure_min_captures: Default::default(),
@@ -385,18 +384,18 @@ impl<'tcx> TypeckResults<'tcx> {
self.node_types.get(&id.local_id).cloned()
}
- pub fn node_substs_mut(&mut self) -> LocalTableInContextMut<'_, SubstsRef<'tcx>> {
- LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_substs }
+ pub fn node_args_mut(&mut self) -> LocalTableInContextMut<'_, GenericArgsRef<'tcx>> {
+ LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_args }
}
- pub fn node_substs(&self, id: hir::HirId) -> SubstsRef<'tcx> {
+ pub fn node_args(&self, id: hir::HirId) -> GenericArgsRef<'tcx> {
validate_hir_id_for_typeck_results(self.hir_owner, id);
- self.node_substs.get(&id.local_id).cloned().unwrap_or_else(|| InternalSubsts::empty())
+ self.node_args.get(&id.local_id).cloned().unwrap_or_else(|| GenericArgs::empty())
}
- pub fn node_substs_opt(&self, id: hir::HirId) -> Option<SubstsRef<'tcx>> {
+ pub fn node_args_opt(&self, id: hir::HirId) -> Option<GenericArgsRef<'tcx>> {
validate_hir_id_for_typeck_results(self.hir_owner, id);
- self.node_substs.get(&id.local_id).cloned()
+ self.node_args.get(&id.local_id).cloned()
}
/// Returns the type of a pattern as a monotype. Like [`expr_ty`], this function
@@ -636,7 +635,7 @@ impl<'a, V> LocalTableInContextMut<'a, V> {
&mut self,
items: UnordItems<(hir::HirId, V), impl Iterator<Item = (hir::HirId, V)>>,
) {
- self.data.extend(items.map(|(id, value)| {
+ self.data.extend_unord(items.map(|(id, value)| {
validate_hir_id_for_typeck_results(self.hir_owner, id);
(id.local_id, value)
}))
@@ -671,12 +670,12 @@ impl<'tcx> CanonicalUserType<'tcx> {
pub fn is_identity(&self) -> bool {
match self.value {
UserType::Ty(_) => false,
- UserType::TypeOf(_, user_substs) => {
- if user_substs.user_self_ty.is_some() {
+ UserType::TypeOf(_, user_args) => {
+ if user_args.user_self_ty.is_some() {
return false;
}
- iter::zip(user_substs.substs, BoundVar::new(0)..).all(|(kind, cvar)| {
+ iter::zip(user_args.args, BoundVar::new(0)..).all(|(kind, cvar)| {
match kind.unpack() {
GenericArgKind::Type(ty) => match ty.kind() {
ty::Bound(debruijn, b) => {
@@ -721,5 +720,5 @@ pub enum UserType<'tcx> {
/// The canonical type is the result of `type_of(def_id)` with the
/// given substitutions applied.
- TypeOf(DefId, UserSubsts<'tcx>),
+ TypeOf(DefId, UserArgs<'tcx>),
}
diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs
index e2e4a2dbd..564f982f8 100644
--- a/compiler/rustc_middle/src/ty/util.rs
+++ b/compiler/rustc_middle/src/ty/util.rs
@@ -7,7 +7,7 @@ use crate::ty::{
self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeVisitableExt,
};
-use crate::ty::{GenericArgKind, SubstsRef};
+use crate::ty::{GenericArgKind, GenericArgsRef};
use rustc_apfloat::Float as _;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher};
@@ -19,7 +19,7 @@ use rustc_index::bit_set::GrowableBitSet;
use rustc_macros::HashStable;
use rustc_session::Limit;
use rustc_span::sym;
-use rustc_target::abi::{Integer, IntegerType, Size, TargetDataLayout};
+use rustc_target::abi::{Integer, IntegerType, Size};
use rustc_target::spec::abi::Abi;
use smallvec::SmallVec;
use std::{fmt, iter};
@@ -57,7 +57,7 @@ impl<'tcx> fmt::Display for Discr<'tcx> {
let x = self.val;
// sign extend the raw representation to be an i128
let x = size.sign_extend(x) as i128;
- write!(fmt, "{}", x)
+ write!(fmt, "{x}")
}
_ => write!(fmt, "{}", self.val),
}
@@ -156,7 +156,7 @@ impl<'tcx> TyCtxt<'tcx> {
| DefKind::Enum
| DefKind::Trait
| DefKind::OpaqueTy
- | DefKind::TyAlias
+ | DefKind::TyAlias { .. }
| DefKind::ForeignTy
| DefKind::TraitAlias
| DefKind::AssocTy
@@ -226,14 +226,14 @@ impl<'tcx> TyCtxt<'tcx> {
return Ty::new_error(self, reported);
}
match *ty.kind() {
- ty::Adt(def, substs) => {
+ ty::Adt(def, args) => {
if !def.is_struct() {
break;
}
match def.non_enum_variant().tail_opt() {
Some(field) => {
f();
- ty = field.ty(self, substs);
+ ty = field.ty(self, args);
}
None => break,
}
@@ -301,12 +301,12 @@ impl<'tcx> TyCtxt<'tcx> {
let (mut a, mut b) = (source, target);
loop {
match (&a.kind(), &b.kind()) {
- (&ty::Adt(a_def, a_substs), &ty::Adt(b_def, b_substs))
+ (&ty::Adt(a_def, a_args), &ty::Adt(b_def, b_args))
if a_def == b_def && a_def.is_struct() =>
{
if let Some(f) = a_def.non_enum_variant().tail_opt() {
- a = f.ty(self, a_substs);
- b = f.ty(self, b_substs);
+ a = f.ty(self, a_args);
+ b = f.ty(self, b_args);
} else {
break;
}
@@ -349,7 +349,7 @@ impl<'tcx> TyCtxt<'tcx> {
let drop_trait = self.lang_items().drop_trait()?;
self.ensure().coherent_trait(drop_trait);
- let ty = self.type_of(adt_did).subst_identity();
+ let ty = self.type_of(adt_did).instantiate_identity();
let mut dtor_candidate = None;
self.for_each_relevant_impl(drop_trait, ty, |impl_did| {
if validate(self, impl_did).is_err() {
@@ -358,7 +358,8 @@ impl<'tcx> TyCtxt<'tcx> {
}
let Some(item_id) = self.associated_item_def_ids(impl_did).first() else {
- self.sess.delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
+ self.sess
+ .delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
return;
};
@@ -383,7 +384,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Note that this returns only the constraints for the
/// destructor of `def` itself. For the destructors of the
/// contents, you need `adt_dtorck_constraint`.
- pub fn destructor_constraints(self, def: ty::AdtDef<'tcx>) -> Vec<ty::subst::GenericArg<'tcx>> {
+ pub fn destructor_constraints(self, def: ty::AdtDef<'tcx>) -> Vec<ty::GenericArg<'tcx>> {
let dtor = match def.destructor(self) {
None => {
debug!("destructor_constraints({:?}) - no dtor", def.did());
@@ -400,7 +401,7 @@ impl<'tcx> TyCtxt<'tcx> {
// must be live.
// We need to return the list of parameters from the ADTs
- // generics/substs that correspond to impure parameters on the
+ // generics/args that correspond to impure parameters on the
// impl's generics. This is a bit ugly, but conceptually simple:
//
// Suppose our ADT looks like the following
@@ -412,21 +413,21 @@ impl<'tcx> TyCtxt<'tcx> {
// impl<#[may_dangle] P0, P1, P2> Drop for S<P1, P2, P0>
//
// We want to return the parameters (X, Y). For that, we match
- // up the item-substs <X, Y, Z> with the substs on the impl ADT,
- // <P1, P2, P0>, and then look up which of the impl substs refer to
+ // up the item-args <X, Y, Z> with the args on the impl ADT,
+ // <P1, P2, P0>, and then look up which of the impl args refer to
// parameters marked as pure.
- let impl_substs = match *self.type_of(impl_def_id).subst_identity().kind() {
- ty::Adt(def_, substs) if def_ == def => substs,
+ let impl_args = match *self.type_of(impl_def_id).instantiate_identity().kind() {
+ ty::Adt(def_, args) if def_ == def => args,
_ => bug!(),
};
- let item_substs = match *self.type_of(def.did()).subst_identity().kind() {
- ty::Adt(def_, substs) if def_ == def => substs,
+ let item_args = match *self.type_of(def.did()).instantiate_identity().kind() {
+ ty::Adt(def_, args) if def_ == def => args,
_ => bug!(),
};
- let result = iter::zip(item_substs, impl_substs)
+ let result = iter::zip(item_args, impl_args)
.filter(|&(_, k)| {
match k.unpack() {
GenericArgKind::Lifetime(region) => match region.kind() {
@@ -459,12 +460,12 @@ impl<'tcx> TyCtxt<'tcx> {
/// Checks whether each generic argument is simply a unique generic parameter.
pub fn uses_unique_generic_params(
self,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
ignore_regions: CheckRegions,
) -> Result<(), NotUniqueParam<'tcx>> {
let mut seen = GrowableBitSet::default();
let mut seen_late = FxHashSet::default();
- for arg in substs {
+ for arg in args {
match arg.unpack() {
GenericArgKind::Lifetime(lt) => match (ignore_regions, lt.kind()) {
(CheckRegions::Bound, ty::ReLateBound(di, reg)) => {
@@ -510,10 +511,10 @@ impl<'tcx> TyCtxt<'tcx> {
/// for better caching.
pub fn uses_unique_placeholders_ignoring_regions(
self,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
) -> Result<(), NotUniqueParam<'tcx>> {
let mut seen = GrowableBitSet::default();
- for arg in substs {
+ for arg in args {
match arg.unpack() {
// Ignore regions, since we can't resolve those in a canonicalized
// query in the trait solver.
@@ -594,7 +595,7 @@ impl<'tcx> TyCtxt<'tcx> {
def_id
}
- /// Given the `DefId` and substs a closure, creates the type of
+ /// Given the `DefId` and args a closure, creates the type of
/// `self` argument that the closure expects. For example, for a
/// `Fn` closure, this would return a reference type `&T` where
/// `T = closure_ty`.
@@ -607,11 +608,11 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn closure_env_ty(
self,
closure_def_id: DefId,
- closure_substs: SubstsRef<'tcx>,
+ closure_args: GenericArgsRef<'tcx>,
env_region: ty::Region<'tcx>,
) -> Option<Ty<'tcx>> {
- let closure_ty = Ty::new_closure(self, closure_def_id, closure_substs);
- let closure_kind_ty = closure_substs.as_closure().kind_ty();
+ let closure_ty = Ty::new_closure(self, closure_def_id, closure_args);
+ let closure_kind_ty = closure_args.as_closure().kind_ty();
let closure_kind = closure_kind_ty.to_opt_closure_kind()?;
let env_ty = match closure_kind {
ty::ClosureKind::Fn => Ty::new_imm_ref(self, env_region, closure_ty),
@@ -654,7 +655,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// Returns the type a reference to the thread local takes in MIR.
pub fn thread_local_ptr_ty(self, def_id: DefId) -> Ty<'tcx> {
- let static_ty = self.type_of(def_id).subst_identity();
+ let static_ty = self.type_of(def_id).instantiate_identity();
if self.is_mutable_static(def_id) {
Ty::new_mut_ptr(self, static_ty)
} else if self.is_foreign_item(def_id) {
@@ -670,7 +671,7 @@ impl<'tcx> TyCtxt<'tcx> {
// Make sure that any constants in the static's type are evaluated.
let static_ty = self.normalize_erasing_regions(
ty::ParamEnv::empty(),
- self.type_of(def_id).subst_identity(),
+ self.type_of(def_id).instantiate_identity(),
);
// Make sure that accesses to unsafe statics end up using raw pointers.
@@ -719,7 +720,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn try_expand_impl_trait_type(
self,
def_id: DefId,
- substs: SubstsRef<'tcx>,
+ args: GenericArgsRef<'tcx>,
) -> Result<Ty<'tcx>, Ty<'tcx>> {
let mut visitor = OpaqueTypeExpander {
seen_opaque_tys: FxHashSet::default(),
@@ -732,7 +733,7 @@ impl<'tcx> TyCtxt<'tcx> {
tcx: self,
};
- let expanded_type = visitor.expand_opaque_ty(def_id, substs).unwrap();
+ let expanded_type = visitor.expand_opaque_ty(def_id, args).unwrap();
if visitor.found_recursion { Err(expanded_type) } else { Ok(expanded_type) }
}
@@ -799,7 +800,7 @@ struct OpaqueTypeExpander<'tcx> {
seen_opaque_tys: FxHashSet<DefId>,
// Cache of all expansions we've seen so far. This is a critical
// optimization for some large types produced by async fn trees.
- expanded_cache: FxHashMap<(DefId, SubstsRef<'tcx>), Ty<'tcx>>,
+ expanded_cache: FxHashMap<(DefId, GenericArgsRef<'tcx>), Ty<'tcx>>,
primary_def_id: Option<DefId>,
found_recursion: bool,
found_any_recursion: bool,
@@ -812,19 +813,19 @@ struct OpaqueTypeExpander<'tcx> {
}
impl<'tcx> OpaqueTypeExpander<'tcx> {
- fn expand_opaque_ty(&mut self, def_id: DefId, substs: SubstsRef<'tcx>) -> Option<Ty<'tcx>> {
+ fn expand_opaque_ty(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> Option<Ty<'tcx>> {
if self.found_any_recursion {
return None;
}
- let substs = substs.fold_with(self);
+ let args = args.fold_with(self);
if !self.check_recursion || self.seen_opaque_tys.insert(def_id) {
- let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) {
+ let expanded_ty = match self.expanded_cache.get(&(def_id, args)) {
Some(expanded_ty) => *expanded_ty,
None => {
let generic_ty = self.tcx.type_of(def_id);
- let concrete_ty = generic_ty.subst(self.tcx, substs);
+ let concrete_ty = generic_ty.instantiate(self.tcx, args);
let expanded_ty = self.fold_ty(concrete_ty);
- self.expanded_cache.insert((def_id, substs), expanded_ty);
+ self.expanded_cache.insert((def_id, args), expanded_ty);
expanded_ty
}
};
@@ -841,21 +842,21 @@ impl<'tcx> OpaqueTypeExpander<'tcx> {
}
}
- fn expand_generator(&mut self, def_id: DefId, substs: SubstsRef<'tcx>) -> Option<Ty<'tcx>> {
+ fn expand_generator(&mut self, def_id: DefId, args: GenericArgsRef<'tcx>) -> Option<Ty<'tcx>> {
if self.found_any_recursion {
return None;
}
- let substs = substs.fold_with(self);
+ let args = args.fold_with(self);
if !self.check_recursion || self.seen_opaque_tys.insert(def_id) {
- let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) {
+ let expanded_ty = match self.expanded_cache.get(&(def_id, args)) {
Some(expanded_ty) => *expanded_ty,
None => {
for bty in self.tcx.generator_hidden_types(def_id) {
- let hidden_ty = bty.subst(self.tcx, substs);
+ let hidden_ty = bty.instantiate(self.tcx, args);
self.fold_ty(hidden_ty);
}
- let expanded_ty = Ty::new_generator_witness_mir(self.tcx, def_id, substs);
- self.expanded_cache.insert((def_id, substs), expanded_ty);
+ let expanded_ty = Ty::new_generator_witness_mir(self.tcx, def_id, args);
+ self.expanded_cache.insert((def_id, args), expanded_ty);
expanded_ty
}
};
@@ -879,16 +880,16 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for OpaqueTypeExpander<'tcx> {
}
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
- let mut t = if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) = *t.kind() {
- self.expand_opaque_ty(def_id, substs).unwrap_or(t)
+ let mut t = if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) = *t.kind() {
+ self.expand_opaque_ty(def_id, args).unwrap_or(t)
} else if t.has_opaque_types() || t.has_generators() {
t.super_fold_with(self)
} else {
t
};
if self.expand_generators {
- if let ty::GeneratorWitnessMIR(def_id, substs) = *t.kind() {
- t = self.expand_generator(def_id, substs).unwrap_or(t);
+ if let ty::GeneratorWitnessMIR(def_id, args) = *t.kind() {
+ t = self.expand_generator(def_id, args).unwrap_or(t);
}
}
t
@@ -1084,7 +1085,7 @@ impl<'tcx> Ty<'tcx> {
#[inline]
pub fn needs_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
// Avoid querying in simple cases.
- match needs_drop_components(self, &tcx.data_layout) {
+ match needs_drop_components(tcx, self) {
Err(AlwaysRequiresDrop) => true,
Ok(components) => {
let query_ty = match *components {
@@ -1117,7 +1118,7 @@ impl<'tcx> Ty<'tcx> {
#[inline]
pub fn has_significant_drop(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
// Avoid querying in simple cases.
- match needs_drop_components(self, &tcx.data_layout) {
+ match needs_drop_components(tcx, self) {
Err(AlwaysRequiresDrop) => true,
Ok(components) => {
let query_ty = match *components {
@@ -1277,10 +1278,10 @@ impl<'tcx> ExplicitSelf<'tcx> {
/// *any* of the returned types need drop. Returns `Err(AlwaysRequiresDrop)` if
/// this type always needs drop.
pub fn needs_drop_components<'tcx>(
+ tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
- target_layout: &TargetDataLayout,
) -> Result<SmallVec<[Ty<'tcx>; 2]>, AlwaysRequiresDrop> {
- match ty.kind() {
+ match *ty.kind() {
ty::Infer(ty::FreshIntTy(_))
| ty::Infer(ty::FreshFloatTy(_))
| ty::Bool
@@ -1302,11 +1303,11 @@ pub fn needs_drop_components<'tcx>(
ty::Dynamic(..) | ty::Error(_) => Err(AlwaysRequiresDrop),
- ty::Slice(ty) => needs_drop_components(*ty, target_layout),
+ ty::Slice(ty) => needs_drop_components(tcx, ty),
ty::Array(elem_ty, size) => {
- match needs_drop_components(*elem_ty, target_layout) {
+ match needs_drop_components(tcx, elem_ty) {
Ok(v) if v.is_empty() => Ok(v),
- res => match size.try_to_bits(target_layout.pointer_size) {
+ res => match size.try_to_target_usize(tcx) {
// Arrays of size zero don't need drop, even if their element
// type does.
Some(0) => Ok(SmallVec::new()),
@@ -1320,7 +1321,7 @@ pub fn needs_drop_components<'tcx>(
}
// If any field needs drop, then the whole tuple does.
ty::Tuple(fields) => fields.iter().try_fold(SmallVec::new(), move |mut acc, elem| {
- acc.extend(needs_drop_components(elem, target_layout)?);
+ acc.extend(needs_drop_components(tcx, elem)?);
Ok(acc)
}),
diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs
index 520bb55e0..156eda477 100644
--- a/compiler/rustc_middle/src/ty/visit.rs
+++ b/compiler/rustc_middle/src/ty/visit.rs
@@ -88,14 +88,10 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable<TyCtxt<'tcx>> {
self.has_type_flags(TypeFlags::HAS_INFER)
}
fn has_placeholders(&self) -> bool {
- self.has_type_flags(
- TypeFlags::HAS_RE_PLACEHOLDER
- | TypeFlags::HAS_TY_PLACEHOLDER
- | TypeFlags::HAS_CT_PLACEHOLDER,
- )
+ self.has_type_flags(TypeFlags::HAS_PLACEHOLDER)
}
fn has_non_region_placeholders(&self) -> bool {
- self.has_type_flags(TypeFlags::HAS_TY_PLACEHOLDER | TypeFlags::HAS_CT_PLACEHOLDER)
+ self.has_type_flags(TypeFlags::HAS_PLACEHOLDER - TypeFlags::HAS_RE_PLACEHOLDER)
}
fn has_param(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_PARAM)
diff --git a/compiler/rustc_middle/src/ty/vtable.rs b/compiler/rustc_middle/src/ty/vtable.rs
index 443791d0a..97402caa0 100644
--- a/compiler/rustc_middle/src/ty/vtable.rs
+++ b/compiler/rustc_middle/src/ty/vtable.rs
@@ -29,8 +29,8 @@ impl<'tcx> fmt::Debug for VtblEntry<'tcx> {
VtblEntry::MetadataSize => write!(f, "MetadataSize"),
VtblEntry::MetadataAlign => write!(f, "MetadataAlign"),
VtblEntry::Vacant => write!(f, "Vacant"),
- VtblEntry::Method(instance) => write!(f, "Method({})", instance),
- VtblEntry::TraitVPtr(trait_ref) => write!(f, "TraitVPtr({})", trait_ref),
+ VtblEntry::Method(instance) => write!(f, "Method({instance})"),
+ VtblEntry::TraitVPtr(trait_ref) => write!(f, "TraitVPtr({trait_ref})"),
}
}
}
diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs
index 04a635a68..7c3d9ed39 100644
--- a/compiler/rustc_middle/src/ty/walk.rs
+++ b/compiler/rustc_middle/src/ty/walk.rs
@@ -1,8 +1,8 @@
//! An iterator over the type substructure.
//! WARNING: this does not keep track of the region depth.
-use crate::ty::subst::{GenericArg, GenericArgKind};
use crate::ty::{self, Ty};
+use crate::ty::{GenericArg, GenericArgKind};
use rustc_data_structures::sso::SsoHashSet;
use smallvec::SmallVec;
@@ -166,33 +166,33 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>)
stack.push(lt.into());
}
ty::Alias(_, data) => {
- stack.extend(data.substs.iter().rev());
+ stack.extend(data.args.iter().rev());
}
ty::Dynamic(obj, lt, _) => {
stack.push(lt.into());
stack.extend(obj.iter().rev().flat_map(|predicate| {
- let (substs, opt_ty) = match predicate.skip_binder() {
- ty::ExistentialPredicate::Trait(tr) => (tr.substs, None),
- ty::ExistentialPredicate::Projection(p) => (p.substs, Some(p.term)),
+ let (args, opt_ty) = match predicate.skip_binder() {
+ ty::ExistentialPredicate::Trait(tr) => (tr.args, None),
+ ty::ExistentialPredicate::Projection(p) => (p.args, Some(p.term)),
ty::ExistentialPredicate::AutoTrait(_) =>
// Empty iterator
{
- (ty::InternalSubsts::empty(), None)
+ (ty::GenericArgs::empty(), None)
}
};
- substs.iter().rev().chain(opt_ty.map(|term| match term.unpack() {
+ args.iter().rev().chain(opt_ty.map(|term| match term.unpack() {
ty::TermKind::Ty(ty) => ty.into(),
ty::TermKind::Const(ct) => ct.into(),
}))
}));
}
- ty::Adt(_, substs)
- | ty::Closure(_, substs)
- | ty::Generator(_, substs, _)
- | ty::GeneratorWitnessMIR(_, substs)
- | ty::FnDef(_, substs) => {
- stack.extend(substs.iter().rev());
+ ty::Adt(_, args)
+ | ty::Closure(_, args)
+ | ty::Generator(_, args, _)
+ | ty::GeneratorWitnessMIR(_, args)
+ | ty::FnDef(_, args) => {
+ stack.extend(args.iter().rev());
}
ty::Tuple(ts) => stack.extend(ts.iter().rev().map(GenericArg::from)),
ty::GeneratorWitness(ts) => {
@@ -233,7 +233,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>)
},
ty::ConstKind::Unevaluated(ct) => {
- stack.extend(ct.substs.iter().rev());
+ stack.extend(ct.args.iter().rev());
}
}
}