1
Fork 0

Alias folding/visiting traits instead of re-export

This commit is contained in:
Alan Egerton 2023-02-09 14:02:47 +00:00
parent 62846d7c99
commit ba55a453eb
No known key found for this signature in database
GPG key ID: 7D4C2F6C22122532
77 changed files with 201 additions and 185 deletions

View file

@ -42,7 +42,7 @@ pub struct Canonical<'tcx, V> {
pub type CanonicalVarInfos<'tcx> = &'tcx List<CanonicalVarInfo<'tcx>>;
impl<'tcx> ty::TypeFoldable<'tcx> for CanonicalVarInfos<'tcx> {
impl<'tcx> ty::ir::TypeFoldable<'tcx> for CanonicalVarInfos<'tcx> {
fn try_fold_with<F: ty::FallibleTypeFolder<'tcx>>(
self,
folder: &mut F,

View file

@ -60,6 +60,7 @@
#![feature(yeet_expr)]
#![feature(result_option_inspect)]
#![feature(const_option)]
#![feature(trait_alias)]
#![recursion_limit = "512"]
#![allow(rustc::potential_query_instability)]

View file

@ -69,7 +69,7 @@ macro_rules! CloneLiftImpls {
macro_rules! TrivialTypeTraversalImpls {
(for <$tcx:lifetime> { $($ty:ty,)+ }) => {
$(
impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty {
impl<$tcx> $crate::ty::fold::ir::TypeFoldable<$tcx> for $ty {
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$tcx>>(
self,
_: &mut F,
@ -86,7 +86,7 @@ macro_rules! TrivialTypeTraversalImpls {
}
}
impl<$tcx> $crate::ty::visit::TypeVisitable<$tcx> for $ty {
impl<$tcx> $crate::ty::visit::ir::TypeVisitable<$tcx> for $ty {
#[inline]
fn visit_with<F: $crate::ty::visit::TypeVisitor<$tcx>>(
&self,
@ -121,7 +121,7 @@ macro_rules! EnumTypeTraversalImpl {
(impl<$($p:tt),*> TypeFoldable<$tcx:tt> for $s:path {
$($variants:tt)*
} $(where $($wc:tt)*)*) => {
impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s
impl<$($p),*> $crate::ty::fold::ir::TypeFoldable<$tcx> for $s
$(where $($wc)*)*
{
fn try_fold_with<V: $crate::ty::fold::FallibleTypeFolder<$tcx>>(
@ -136,7 +136,7 @@ macro_rules! EnumTypeTraversalImpl {
(impl<$($p:tt),*> TypeVisitable<$tcx:tt> for $s:path {
$($variants:tt)*
} $(where $($wc:tt)*)*) => {
impl<$($p),*> $crate::ty::visit::TypeVisitable<$tcx> for $s
impl<$($p),*> $crate::ty::visit::ir::TypeVisitable<$tcx> for $s
$(where $($wc)*)*
{
fn visit_with<V: $crate::ty::visit::TypeVisitor<$tcx>>(
@ -163,7 +163,7 @@ macro_rules! EnumTypeTraversalImpl {
output(
$variant ( $($variant_arg),* ) => {
$variant (
$($crate::ty::fold::TypeFoldable::try_fold_with($variant_arg, $folder)?),*
$($crate::ty::fold::ir::TypeFoldable::try_fold_with($variant_arg, $folder)?),*
)
}
$($output)*
@ -180,7 +180,7 @@ macro_rules! EnumTypeTraversalImpl {
output(
$variant { $($variant_arg),* } => {
$variant {
$($variant_arg: $crate::ty::fold::TypeFoldable::fold_with(
$($variant_arg: $crate::ty::fold::ir::TypeFoldable::fold_with(
$variant_arg, $folder
)?),* }
}
@ -216,7 +216,7 @@ macro_rules! EnumTypeTraversalImpl {
input($($input)*)
output(
$variant ( $($variant_arg),* ) => {
$($crate::ty::visit::TypeVisitable::visit_with(
$($crate::ty::visit::ir::TypeVisitable::visit_with(
$variant_arg, $visitor
)?;)*
::std::ops::ControlFlow::Continue(())
@ -234,7 +234,7 @@ macro_rules! EnumTypeTraversalImpl {
input($($input)*)
output(
$variant { $($variant_arg),* } => {
$($crate::ty::visit::TypeVisitable::visit_with(
$($crate::ty::visit::ir::TypeVisitable::visit_with(
$variant_arg, $visitor
)?;)*
::std::ops::ControlFlow::Continue(())

View file

@ -7,10 +7,10 @@ use crate::mir::interpret::{
};
use crate::mir::visit::MirVisitable;
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable};
use crate::ty::fold::{ir::TypeFoldable, FallibleTypeFolder};
use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::visit::{TypeVisitable, TypeVisitor};
use crate::ty::{self, DefIdTree, List, Ty, TyCtxt};
use crate::ty::{self, ir, DefIdTree, List, Ty, TyCtxt};
use crate::ty::{AdtDef, InstanceDef, ScalarInt, UserTypeAnnotationIndex};
use crate::ty::{GenericArg, InternalSubsts, SubstsRef};
@ -2751,7 +2751,7 @@ impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection {
}
}
impl<'tcx> TypeVisitable<'tcx> for UserTypeProjection {
impl<'tcx> ir::TypeVisitable<'tcx> for UserTypeProjection {
fn visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> ControlFlow<Vs::BreakTy> {
self.base.visit_with(visitor)
// Note: there's nothing in `self.proj` to visit.

View file

@ -2,7 +2,7 @@
use super::*;
impl<'tcx, R: Idx, C: Idx> TypeVisitable<'tcx> for BitMatrix<R, C> {
impl<'tcx, R: Idx, C: Idx> ir::TypeVisitable<'tcx> for BitMatrix<R, C> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
ControlFlow::Continue(())
}

View file

@ -2,7 +2,10 @@ use std::ops::ControlFlow;
use rustc_data_structures::intern::Interned;
use crate::ty::{FallibleTypeFolder, Ty, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor};
use crate::ty::{
ir::{self, TypeFoldable, TypeVisitable},
FallibleTypeFolder, Ty, TypeFolder, TypeVisitor,
};
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
pub struct ExternalConstraints<'tcx>(pub(crate) Interned<'tcx, ExternalConstraintsData<'tcx>>);
@ -25,18 +28,20 @@ pub struct ExternalConstraintsData<'tcx> {
impl<'tcx> TypeFoldable<'tcx> for ExternalConstraints<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
Ok(FallibleTypeFolder::tcx(folder).intern_external_constraints(ExternalConstraintsData {
regions: (),
opaque_types: self
.opaque_types
.iter()
.map(|opaque| opaque.try_fold_with(folder))
.collect::<Result<_, F::Error>>()?,
}))
Ok(ir::FallibleTypeFolder::tcx(folder).intern_external_constraints(
ExternalConstraintsData {
regions: (),
opaque_types: self
.opaque_types
.iter()
.map(|opaque| opaque.try_fold_with(folder))
.collect::<Result<_, F::Error>>()?,
},
))
}
fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
TypeFolder::tcx(folder).intern_external_constraints(ExternalConstraintsData {
ir::TypeFolder::tcx(folder).intern_external_constraints(ExternalConstraintsData {
regions: (),
opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(),
})

View file

@ -1,7 +1,6 @@
//! A subset of a mir body used for const evaluatability checking.
use crate::ty::{
self, Const, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeVisitable,
self, ir::TypeFolder, Const, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable,
};
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def_id::DefId;

View file

@ -3,9 +3,10 @@
use std::ops::ControlFlow;
use crate::ty::{
visit::TypeVisitable, AliasTy, Const, ConstKind, DefIdTree, FallibleTypeFolder, InferConst,
InferTy, Opaque, PolyTraitPredicate, Projection, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable,
TypeSuperVisitable, TypeVisitor,
ir::{FallibleTypeFolder, TypeVisitor},
visit::TypeVisitable,
AliasTy, Const, ConstKind, DefIdTree, InferConst, InferTy, Opaque, PolyTraitPredicate,
Projection, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable,
};
use rustc_data_structures::fx::FxHashMap;

View file

@ -1,5 +1,4 @@
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
use crate::ty::visit::TypeVisitable;
use crate::ty::fold::{ir::TypeFolder, TypeFoldable, TypeSuperFoldable};
use crate::ty::{self, Ty, TyCtxt, TypeFlags};
pub(super) fn provide(providers: &mut ty::query::Providers) {

View file

@ -48,7 +48,10 @@ use rustc_hir::def_id::DefId;
use std::collections::BTreeMap;
pub use ir::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable};
pub trait TypeFoldable<'tcx> = ir::TypeFoldable<'tcx> + TypeVisitable<'tcx>;
pub trait TypeSuperFoldable<'tcx> = ir::TypeSuperFoldable<'tcx>;
pub trait TypeFolder<'tcx> = ir::TypeFolder<'tcx>;
pub trait FallibleTypeFolder<'tcx> = ir::FallibleTypeFolder<'tcx>;
pub mod ir {
use crate::ty::{self, ir::TypeVisitable, Binder, Ty, TyCtxt};
@ -233,7 +236,7 @@ where
pub ct_op: H,
}
impl<'tcx, F, G, H> TypeFolder<'tcx> for BottomUpFolder<'tcx, F, G, H>
impl<'tcx, F, G, H> ir::TypeFolder<'tcx> for BottomUpFolder<'tcx, F, G, H>
where
F: FnMut(Ty<'tcx>) -> Ty<'tcx>,
G: FnMut(ty::Region<'tcx>) -> ty::Region<'tcx>,
@ -323,7 +326,7 @@ impl<'a, 'tcx> RegionFolder<'a, 'tcx> {
}
}
impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
impl<'a, 'tcx> ir::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
self.tcx
}
@ -397,7 +400,7 @@ impl<'tcx, D: BoundVarReplacerDelegate<'tcx>> BoundVarReplacer<'tcx, D> {
}
}
impl<'tcx, D> TypeFolder<'tcx> for BoundVarReplacer<'tcx, D>
impl<'tcx, D> ir::TypeFolder<'tcx> for BoundVarReplacer<'tcx, D>
where
D: BoundVarReplacerDelegate<'tcx>,
{
@ -663,7 +666,7 @@ impl<'tcx> Shifter<'tcx> {
}
}
impl<'tcx> TypeFolder<'tcx> for Shifter<'tcx> {
impl<'tcx> ir::TypeFolder<'tcx> for Shifter<'tcx> {
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
self.tcx
}

View file

@ -1,6 +1,6 @@
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitable};
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable};
use crate::ty::{EarlyBinder, InternalSubsts, SubstsRef};
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::Namespace;
@ -674,7 +674,7 @@ fn polymorphize<'tcx>(
tcx: TyCtxt<'tcx>,
}
impl<'tcx> ty::TypeFolder<'tcx> for PolymorphizationFolder<'tcx> {
impl<'tcx> ty::ir::TypeFolder<'tcx> for PolymorphizationFolder<'tcx> {
fn tcx<'a>(&'a self) -> TyCtxt<'tcx> {
self.tcx
}

View file

@ -917,13 +917,13 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Term<'tcx> {
}
}
impl<'tcx> TypeFoldable<'tcx> for Term<'tcx> {
impl<'tcx> ir::TypeFoldable<'tcx> for Term<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
Ok(self.unpack().try_fold_with(folder)?.pack())
}
}
impl<'tcx> TypeVisitable<'tcx> for Term<'tcx> {
impl<'tcx> ir::TypeVisitable<'tcx> for Term<'tcx> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.unpack().visit_with(visitor)
}
@ -1619,7 +1619,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ParamEnv<'tcx> {
}
}
impl<'tcx> TypeFoldable<'tcx> for ParamEnv<'tcx> {
impl<'tcx> ir::TypeFoldable<'tcx> for ParamEnv<'tcx> {
fn try_fold_with<F: ty::fold::FallibleTypeFolder<'tcx>>(
self,
folder: &mut F,
@ -1632,7 +1632,7 @@ impl<'tcx> TypeFoldable<'tcx> for ParamEnv<'tcx> {
}
}
impl<'tcx> TypeVisitable<'tcx> for ParamEnv<'tcx> {
impl<'tcx> ir::TypeVisitable<'tcx> for ParamEnv<'tcx> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.caller_bounds().visit_with(visitor)?;
self.reveal().visit_with(visitor)

View file

@ -9,7 +9,10 @@
use crate::mir;
use crate::traits::query::NoSolution;
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder};
use crate::ty::fold::{
ir::{FallibleTypeFolder, TypeFolder},
TypeFoldable,
};
use crate::ty::{self, EarlyBinder, SubstsRef, Ty, TyCtxt};
#[derive(Debug, Copy, Clone, HashStable, TyEncodable, TyDecodable)]

View file

@ -1,5 +1,5 @@
use crate::error::ConstNotUsedTraitAlias;
use crate::ty::fold::{TypeFolder, TypeSuperFoldable};
use crate::ty::fold::{ir::TypeFolder, TypeSuperFoldable};
use crate::ty::subst::{GenericArg, GenericArgKind};
use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc_data_structures::fx::FxHashMap;

View file

@ -2221,7 +2221,7 @@ struct RegionFolder<'a, 'tcx> {
),
}
impl<'a, 'tcx> ty::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
impl<'a, 'tcx> ty::ir::TypeFolder<'tcx> for RegionFolder<'a, 'tcx> {
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
self.tcx
}
@ -2493,7 +2493,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
}
}
impl<'tcx> ty::visit::TypeVisitor<'tcx> for RegionNameCollector<'tcx> {
impl<'tcx> ty::visit::ir::TypeVisitor<'tcx> for RegionNameCollector<'tcx> {
type BreakTy = ();
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {

View file

@ -4,10 +4,10 @@
use crate::mir::interpret;
use crate::mir::{Field, ProjectionKind};
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
use crate::ty::fold::{ir::TypeSuperFoldable, FallibleTypeFolder, TypeFoldable};
use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer};
use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
use crate::ty::{self, AliasTy, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
use crate::ty::visit::{ir::TypeSuperVisitable, TypeVisitable, TypeVisitor};
use crate::ty::{self, ir, AliasTy, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
use rustc_data_structures::functor::IdFunctor;
use rustc_hir::def::Namespace;
use rustc_index::vec::{Idx, IndexVec};
@ -363,19 +363,19 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
// TypeFoldable implementations.
/// AdtDefs are basically the same as a DefId.
impl<'tcx> TypeFoldable<'tcx> for ty::AdtDef<'tcx> {
impl<'tcx> ir::TypeFoldable<'tcx> for ty::AdtDef<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _folder: &mut F) -> Result<Self, F::Error> {
Ok(self)
}
}
impl<'tcx> TypeVisitable<'tcx> for ty::AdtDef<'tcx> {
impl<'tcx> ir::TypeVisitable<'tcx> for ty::AdtDef<'tcx> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<V::BreakTy> {
ControlFlow::Continue(())
}
}
impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) {
impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> ir::TypeFoldable<'tcx> for (T, U) {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(
self,
folder: &mut F,
@ -384,15 +384,15 @@ impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> TypeFoldable<'tcx> for
}
}
impl<'tcx, T: TypeVisitable<'tcx>, U: TypeVisitable<'tcx>> TypeVisitable<'tcx> for (T, U) {
impl<'tcx, T: TypeVisitable<'tcx>, U: TypeVisitable<'tcx>> ir::TypeVisitable<'tcx> for (T, U) {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.0.visit_with(visitor)?;
self.1.visit_with(visitor)
}
}
impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>> TypeFoldable<'tcx>
for (A, B, C)
impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>>
ir::TypeFoldable<'tcx> for (A, B, C)
{
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(
self,
@ -407,7 +407,7 @@ impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>>
}
impl<'tcx, A: TypeVisitable<'tcx>, B: TypeVisitable<'tcx>, C: TypeVisitable<'tcx>>
TypeVisitable<'tcx> for (A, B, C)
ir::TypeVisitable<'tcx> for (A, B, C)
{
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.0.visit_with(visitor)?;
@ -442,7 +442,7 @@ EnumTypeTraversalImpl! {
} where T: TypeVisitable<'tcx>, E: TypeVisitable<'tcx>,
}
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<'tcx> for Rc<T> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(
mut self,
folder: &mut F,
@ -482,13 +482,13 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc<T> {
}
}
impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for Rc<T> {
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<'tcx> for Rc<T> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
(**self).visit_with(visitor)
}
}
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc<T> {
impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<'tcx> for Arc<T> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(
mut self,
folder: &mut F,
@ -528,61 +528,61 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc<T> {
}
}
impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for Arc<T> {
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<'tcx> for Arc<T> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
(**self).visit_with(visitor)
}
}
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<T> {
impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<'tcx> for Box<T> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
self.try_map_id(|value| value.try_fold_with(folder))
}
}
impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for Box<T> {
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<'tcx> for Box<T> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
(**self).visit_with(visitor)
}
}
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<'tcx> for Vec<T> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
self.try_map_id(|t| t.try_fold_with(folder))
}
}
impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for Vec<T> {
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<'tcx> for Vec<T> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.iter().try_for_each(|t| t.visit_with(visitor))
}
}
impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for &[T] {
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<'tcx> for &[T] {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.iter().try_for_each(|t| t.visit_with(visitor))
}
}
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<'tcx> for Box<[T]> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
self.try_map_id(|t| t.try_fold_with(folder))
}
}
impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for Box<[T]> {
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<'tcx> for Box<[T]> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.iter().try_for_each(|t| t.visit_with(visitor))
}
}
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<'tcx, T> {
impl<'tcx, T: TypeFoldable<'tcx>> ir::TypeFoldable<'tcx> for ty::Binder<'tcx, T> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
folder.try_fold_binder(self)
}
}
impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for ty::Binder<'tcx, T> {
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<'tcx> for ty::Binder<'tcx, T> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
visitor.visit_binder(self)
}
@ -603,31 +603,31 @@ impl<'tcx, T: TypeVisitable<'tcx>> TypeSuperVisitable<'tcx> for ty::Binder<'tcx,
}
}
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
impl<'tcx> ir::TypeFoldable<'tcx> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_poly_existential_predicates(v))
}
}
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Const<'tcx>> {
impl<'tcx> ir::TypeFoldable<'tcx> for &'tcx ty::List<ty::Const<'tcx>> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
ty::util::fold_list(self, folder, |tcx, v| tcx.mk_const_list(v.iter()))
}
}
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
impl<'tcx> ir::TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v))
}
}
impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
impl<'tcx> ir::TypeFoldable<'tcx> for Ty<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
folder.try_fold_ty(self)
}
}
impl<'tcx> TypeVisitable<'tcx> for Ty<'tcx> {
impl<'tcx> ir::TypeVisitable<'tcx> for Ty<'tcx> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
visitor.visit_ty(*self)
}
@ -727,13 +727,13 @@ impl<'tcx> TypeSuperVisitable<'tcx> for Ty<'tcx> {
}
}
impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
impl<'tcx> ir::TypeFoldable<'tcx> for ty::Region<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
folder.try_fold_region(self)
}
}
impl<'tcx> TypeVisitable<'tcx> for ty::Region<'tcx> {
impl<'tcx> ir::TypeVisitable<'tcx> for ty::Region<'tcx> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
visitor.visit_region(*self)
}
@ -754,13 +754,13 @@ impl<'tcx> TypeSuperVisitable<'tcx> for ty::Region<'tcx> {
}
}
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
impl<'tcx> ir::TypeFoldable<'tcx> for ty::Predicate<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
folder.try_fold_predicate(self)
}
}
impl<'tcx> TypeVisitable<'tcx> for ty::Predicate<'tcx> {
impl<'tcx> ir::TypeVisitable<'tcx> for ty::Predicate<'tcx> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
visitor.visit_predicate(*self)
}
@ -792,31 +792,31 @@ impl<'tcx> TypeSuperVisitable<'tcx> for ty::Predicate<'tcx> {
}
}
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
impl<'tcx> ir::TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_predicates(v))
}
}
impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec<I, T> {
impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> ir::TypeFoldable<'tcx> for IndexVec<I, T> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
self.try_map_id(|x| x.try_fold_with(folder))
}
}
impl<'tcx, T: TypeVisitable<'tcx>, I: Idx> TypeVisitable<'tcx> for IndexVec<I, T> {
impl<'tcx, T: TypeVisitable<'tcx>, I: Idx> ir::TypeVisitable<'tcx> for IndexVec<I, T> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.iter().try_for_each(|t| t.visit_with(visitor))
}
}
impl<'tcx> TypeFoldable<'tcx> for ty::Const<'tcx> {
impl<'tcx> ir::TypeFoldable<'tcx> for ty::Const<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
folder.try_fold_const(self)
}
}
impl<'tcx> TypeVisitable<'tcx> for ty::Const<'tcx> {
impl<'tcx> ir::TypeVisitable<'tcx> for ty::Const<'tcx> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
visitor.visit_const(*self)
}
@ -844,13 +844,13 @@ impl<'tcx> TypeSuperVisitable<'tcx> for ty::Const<'tcx> {
}
}
impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> {
impl<'tcx> ir::TypeFoldable<'tcx> for InferConst<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _folder: &mut F) -> Result<Self, F::Error> {
Ok(self)
}
}
impl<'tcx> TypeVisitable<'tcx> for InferConst<'tcx> {
impl<'tcx> ir::TypeVisitable<'tcx> for InferConst<'tcx> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, _visitor: &mut V) -> ControlFlow<V::BreakTy> {
ControlFlow::Continue(())
}
@ -862,7 +862,7 @@ impl<'tcx> TypeSuperVisitable<'tcx> for ty::UnevaluatedConst<'tcx> {
}
}
impl<'tcx> TypeVisitable<'tcx> for TyAndLayout<'tcx, Ty<'tcx>> {
impl<'tcx> ir::TypeVisitable<'tcx> for TyAndLayout<'tcx, Ty<'tcx>> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
visitor.visit_ty(self.ty)
}

View file

@ -7,8 +7,10 @@ use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
use crate::ty::visit::ValidateBoundVars;
use crate::ty::InferTy::*;
use crate::ty::{
self, AdtDef, DefIdTree, Discr, FallibleTypeFolder, Term, Ty, TyCtxt, TypeFlags, TypeFoldable,
TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitor,
self,
ir::{FallibleTypeFolder, TypeVisitor},
AdtDef, DefIdTree, Discr, Term, Ty, TyCtxt, TypeFlags, TypeFoldable, TypeSuperFoldable,
TypeSuperVisitable, TypeVisitable,
};
use crate::ty::{List, ParamEnv};
use hir::def::DefKind;

View file

@ -1,10 +1,10 @@
// Type substitutions.
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable};
use crate::ty::fold::{ir::TypeFolder, FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts};
use crate::ty::visit::{TypeVisitable, TypeVisitor};
use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt};
use crate::ty::{self, ir, Lift, List, ParamConst, Ty, TyCtxt};
use rustc_data_structures::intern::Interned;
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
@ -227,7 +227,7 @@ impl<'a, 'tcx> Lift<'tcx> for GenericArg<'a> {
}
}
impl<'tcx> TypeFoldable<'tcx> for GenericArg<'tcx> {
impl<'tcx> ir::TypeFoldable<'tcx> for GenericArg<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
match self.unpack() {
GenericArgKind::Lifetime(lt) => lt.try_fold_with(folder).map(Into::into),
@ -237,7 +237,7 @@ impl<'tcx> TypeFoldable<'tcx> for GenericArg<'tcx> {
}
}
impl<'tcx> TypeVisitable<'tcx> for GenericArg<'tcx> {
impl<'tcx> ir::TypeVisitable<'tcx> for GenericArg<'tcx> {
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
match self.unpack() {
GenericArgKind::Lifetime(lt) => lt.visit_with(visitor),
@ -475,7 +475,7 @@ impl<'tcx> InternalSubsts<'tcx> {
}
}
impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> {
impl<'tcx> ir::TypeFoldable<'tcx> for SubstsRef<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
// This code is hot enough that it's worth specializing for the most
// common length lists, to avoid the overhead of `SmallVec` creation.
@ -503,7 +503,7 @@ impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> {
}
}
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
impl<'tcx> ir::TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
// This code is fairly hot, though not as hot as `SubstsRef`.
//
@ -535,7 +535,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
}
}
impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for &'tcx ty::List<T> {
impl<'tcx, T: TypeVisitable<'tcx>> ir::TypeVisitable<'tcx> for &'tcx ty::List<T> {
#[inline]
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.iter().try_for_each(|t| t.visit_with(visitor))
@ -553,8 +553,8 @@ impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for &'tcx ty::List<T> {
pub struct EarlyBinder<T>(pub T);
/// For early binders, you should first call `subst` before using any visitors.
impl<'tcx, T> !TypeFoldable<'tcx> for ty::EarlyBinder<T> {}
impl<'tcx, T> !TypeVisitable<'tcx> for ty::EarlyBinder<T> {}
impl<'tcx, T> !ir::TypeFoldable<'tcx> for ty::EarlyBinder<T> {}
impl<'tcx, T> !ir::TypeVisitable<'tcx> for ty::EarlyBinder<T> {}
impl<T> EarlyBinder<T> {
pub fn as_ref(&self) -> EarlyBinder<&T> {

View file

@ -4,8 +4,8 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::mir;
use crate::ty::layout::IntegerExt;
use crate::ty::{
self, DefIdTree, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeVisitable,
self, ir::TypeFolder, DefIdTree, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable,
TypeSuperFoldable,
};
use crate::ty::{GenericArgKind, SubstsRef};
use rustc_apfloat::Float as _;

View file

@ -44,7 +44,9 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sso::SsoHashSet;
use std::ops::ControlFlow;
pub use ir::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
pub trait TypeVisitable<'tcx> = ir::TypeVisitable<'tcx>;
pub trait TypeSuperVisitable<'tcx> = ir::TypeSuperVisitable<'tcx>;
pub trait TypeVisitor<'tcx> = ir::TypeVisitor<'tcx>;
pub mod ir {
use crate::ty::{self, Binder, Ty, TypeFlags};
@ -292,7 +294,7 @@ impl<'tcx> TyCtxt<'tcx> {
callback: F,
}
impl<'tcx, F> TypeVisitor<'tcx> for RegionVisitor<F>
impl<'tcx, F> ir::TypeVisitor<'tcx> for RegionVisitor<F>
where
F: FnMut(ty::Region<'tcx>) -> bool,
{
@ -394,7 +396,7 @@ impl<'tcx> ValidateBoundVars<'tcx> {
}
}
impl<'tcx> TypeVisitor<'tcx> for ValidateBoundVars<'tcx> {
impl<'tcx> ir::TypeVisitor<'tcx> for ValidateBoundVars<'tcx> {
type BreakTy = ();
fn visit_binder<T: TypeVisitable<'tcx>>(
@ -506,7 +508,7 @@ struct HasEscapingVarsVisitor {
outer_index: ty::DebruijnIndex,
}
impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
impl<'tcx> ir::TypeVisitor<'tcx> for HasEscapingVarsVisitor {
type BreakTy = FoundEscapingVars;
fn visit_binder<T: TypeVisitable<'tcx>>(
@ -583,7 +585,7 @@ impl std::fmt::Debug for HasTypeFlagsVisitor {
}
}
impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
impl<'tcx> ir::TypeVisitor<'tcx> for HasTypeFlagsVisitor {
type BreakTy = FoundFlags;
#[inline]
@ -653,7 +655,7 @@ impl LateBoundRegionsCollector {
}
}
impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
impl<'tcx> ir::TypeVisitor<'tcx> for LateBoundRegionsCollector {
fn visit_binder<T: TypeVisitable<'tcx>>(
&mut self,
t: &Binder<'tcx, T>,
@ -715,7 +717,7 @@ impl MaxUniverse {
}
}
impl<'tcx> TypeVisitor<'tcx> for MaxUniverse {
impl<'tcx> ir::TypeVisitor<'tcx> for MaxUniverse {
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::Placeholder(placeholder) = t.kind() {
self.max_universe = ty::UniverseIndex::from_u32(