Relax constrained generics to TypeVisitable

上级 f66c06f7
......@@ -7,6 +7,7 @@
};
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{self, RegionVid, Ty};
use crate::{
......@@ -163,7 +164,7 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
/// `location`.
fn add_regular_live_constraint<T>(&mut self, live_ty: T, location: Location)
where
T: TypeFoldable<'tcx>,
T: TypeVisitable<'tcx>,
{
debug!("add_regular_live_constraint(live_ty={:?}, location={:?})", live_ty, location);
......
......@@ -3,7 +3,7 @@
use rustc_index::interval::IntervalSet;
use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_middle::mir::{BasicBlock, Body, ConstraintCategory, Local, Location};
use rustc_middle::ty::{Ty, TypeFoldable};
use rustc_middle::ty::{Ty, TypeFoldable, TypeVisitable};
use rustc_trait_selection::traits::query::dropck_outlives::DropckOutlivesResult;
use rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives;
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
......@@ -477,7 +477,7 @@ fn initialized_at_exit(&mut self, block: BasicBlock, mpi: MovePathIndex) -> bool
/// points `live_at`.
fn add_use_live_facts_for(
&mut self,
value: impl TypeFoldable<'tcx>,
value: impl TypeVisitable<'tcx>,
live_at: &IntervalSet<PointIndex>,
) {
debug!("add_use_live_facts_for(value={:?})", value);
......@@ -542,7 +542,7 @@ fn add_drop_live_facts_for(
fn make_all_regions_live(
elements: &RegionValueElements,
typeck: &mut TypeChecker<'_, 'tcx>,
value: impl TypeFoldable<'tcx>,
value: impl TypeVisitable<'tcx>,
live_at: &IntervalSet<PointIndex>,
) {
debug!("make_all_regions_live(value={:?})", value);
......
use rustc_middle::mir::interpret::InterpResult;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor};
use rustc_middle::ty::{
self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitable, TypeVisitor,
};
use std::convert::TryInto;
use std::ops::ControlFlow;
......@@ -10,7 +12,7 @@
/// case these parameters are unused.
pub(crate) fn ensure_monomorphic_enough<'tcx, T>(tcx: TyCtxt<'tcx>, ty: T) -> InterpResult<'tcx>
where
T: TypeFoldable<'tcx>,
T: TypeVisitable<'tcx>,
{
debug!("ensure_monomorphic_enough: ty={:?}", ty);
if !ty.needs_subst() {
......
......@@ -5,7 +5,7 @@
use crate::infer::TyCtxt;
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::{self, Binder, DefIdTree, Region, Ty, TypeFoldable};
use rustc_middle::ty::{self, Binder, DefIdTree, Region, Ty, TypeFoldable, TypeVisitable};
use rustc_span::Span;
/// Information about the anonymous region we are searching for.
......@@ -142,7 +142,7 @@ pub(super) fn is_return_type_anon(
fn includes_region(
&self,
ty: Binder<'tcx, impl TypeFoldable<'tcx>>,
ty: Binder<'tcx, impl TypeVisitable<'tcx>>,
region: ty::BoundRegionKind,
) -> bool {
let late_bound_regions = self.tcx().collect_referenced_late_bound_regions(&ty);
......
......@@ -25,6 +25,7 @@
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::relate::RelateResult;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
use rustc_middle::ty::visit::TypeVisitable;
pub use rustc_middle::ty::IntVarValue;
use rustc_middle::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
use rustc_middle::ty::{ConstVid, FloatVid, IntVid, TyVid};
......@@ -1438,7 +1439,7 @@ pub fn resolve_numeric_literals_with_default<T>(&self, value: T) -> T
/// `resolve_vars_if_possible()`.
pub fn unresolved_type_vars<T>(&self, value: &T) -> Option<(Ty<'tcx>, Option<Span>)>
where
T: TypeFoldable<'tcx>,
T: TypeVisitable<'tcx>,
{
value.visit_with(&mut resolve::UnresolvedTypeFinder::new(self)).break_value()
}
......
......@@ -29,6 +29,7 @@
use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::fold::{TypeFoldable, TypeSuperFoldable, TypeVisitor};
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt};
use rustc_span::Span;
use std::fmt::Debug;
......@@ -810,7 +811,7 @@ struct ScopeInstantiator<'me, 'tcx> {
}
impl<'me, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'me, 'tcx> {
fn visit_binder<T: TypeFoldable<'tcx>>(
fn visit_binder<T: TypeVisitable<'tcx>>(
&mut self,
t: &ty::Binder<'tcx, T>,
) -> ControlFlow<Self::BreakTy> {
......
......@@ -9,7 +9,8 @@
use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::subst::{GenericArgKind, Subst};
use rustc_middle::ty::{
self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor,
self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable,
TypeVisitable, TypeVisitor,
};
use rustc_span::Span;
......@@ -461,7 +462,7 @@ impl<'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor<OP>
where
OP: FnMut(ty::Region<'tcx>),
{
fn visit_binder<T: TypeFoldable<'tcx>>(
fn visit_binder<T: TypeVisitable<'tcx>>(
&mut self,
t: &ty::Binder<'tcx, T>,
) -> ControlFlow<Self::BreakTy> {
......
......@@ -3,8 +3,8 @@
use std::ops::ControlFlow;
use crate::ty::{
fold::TypeFoldable, Const, ConstKind, DefIdTree, ExistentialPredicate, InferTy,
PolyTraitPredicate, Ty, TyCtxt, TypeSuperFoldable, TypeVisitor,
fold::TypeFoldable, visit::TypeVisitable, Const, ConstKind, DefIdTree, ExistentialPredicate,
InferTy, PolyTraitPredicate, Ty, TyCtxt, TypeSuperFoldable, TypeVisitor,
};
use rustc_data_structures::fx::FxHashMap;
......@@ -87,7 +87,7 @@ pub trait IsSuggestable<'tcx> {
impl<'tcx, T> IsSuggestable<'tcx> for T
where
T: TypeFoldable<'tcx>,
T: TypeVisitable<'tcx>,
{
fn is_suggestable(self, tcx: TyCtxt<'tcx>) -> bool {
self.visit_with(&mut IsSuggestableVisitor { tcx }).is_continue()
......
......@@ -1514,7 +1514,7 @@ pub fn without_caller_bounds(self) -> Self {
/// `where Box<u32>: Copy`, which are clearly never
/// satisfiable. We generally want to behave as if they were true,
/// although the surrounding function is never reachable.
pub fn and<T: TypeFoldable<'tcx>>(self, value: T) -> ParamEnvAnd<'tcx, T> {
pub fn and<T: TypeVisitable<'tcx>>(self, value: T) -> ParamEnvAnd<'tcx, T> {
match self.reveal() {
Reveal::UserFacing => ParamEnvAnd { param_env: self, value },
......
......@@ -2,7 +2,7 @@
use crate::ty::subst::{GenericArg, GenericArgKind, Subst};
use crate::ty::{
self, ConstInt, DefIdTree, ParamConst, ScalarInt, Term, Ty, TyCtxt, TypeFoldable,
TypeSuperFoldable,
TypeSuperFoldable, TypeVisitable,
};
use rustc_apfloat::ieee::{Double, Single};
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
......@@ -2277,7 +2277,7 @@ pub fn pretty_wrap_binder<T, C: FnOnce(&T, Self) -> Result<Self, fmt::Error>>(
fn prepare_late_bound_region_info<T>(&mut self, value: &ty::Binder<'tcx, T>)
where
T: TypeFoldable<'tcx>,
T: TypeVisitable<'tcx>,
{
struct LateBoundRegionNameCollector<'a, 'tcx> {
used_region_names: &'a mut FxHashSet<Symbol>,
......
......@@ -453,7 +453,7 @@ fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
impl<'a, 'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<'a, T>
where
<T as Lift<'tcx>>::Lifted: TypeFoldable<'tcx>,
<T as Lift<'tcx>>::Lifted: TypeVisitable<'tcx>,
{
type Lifted = ty::Binder<'tcx, T::Lifted>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
......
......@@ -8,7 +8,7 @@
use crate::ty::InferTy::*;
use crate::ty::{
self, AdtDef, DefIdTree, Discr, Term, Ty, TyCtxt, TypeFlags, TypeFoldable, TypeSuperFoldable,
TypeVisitor,
TypeVisitable, TypeVisitor,
};
use crate::ty::{List, ParamEnv};
use polonius_engine::Atom;
......@@ -986,7 +986,7 @@ pub enum BoundVariableKind {
impl<'tcx, T> Binder<'tcx, T>
where
T: TypeFoldable<'tcx>,
T: TypeVisitable<'tcx>,
{
/// Wraps `value` in a binder, asserting that `value` does not
/// contain any bound vars that would be bound by the
......@@ -1050,14 +1050,14 @@ pub fn map_bound_ref_unchecked<F, U>(&self, f: F) -> Binder<'tcx, U>
Binder(value, self.1)
}
pub fn map_bound_ref<F, U: TypeFoldable<'tcx>>(&self, f: F) -> Binder<'tcx, U>
pub fn map_bound_ref<F, U: TypeVisitable<'tcx>>(&self, f: F) -> Binder<'tcx, U>
where
F: FnOnce(&T) -> U,
{
self.as_ref().map_bound(f)
}
pub fn map_bound<F, U: TypeFoldable<'tcx>>(self, f: F) -> Binder<'tcx, U>
pub fn map_bound<F, U: TypeVisitable<'tcx>>(self, f: F) -> Binder<'tcx, U>
where
F: FnOnce(T) -> U,
{
......@@ -1069,7 +1069,7 @@ pub fn map_bound<F, U: TypeFoldable<'tcx>>(self, f: F) -> Binder<'tcx, U>
Binder(value, self.1)
}
pub fn try_map_bound<F, U: TypeFoldable<'tcx>, E>(self, f: F) -> Result<Binder<'tcx, U>, E>
pub fn try_map_bound<F, U: TypeVisitable<'tcx>, E>(self, f: F) -> Result<Binder<'tcx, U>, E>
where
F: FnOnce(T) -> Result<U, E>,
{
......@@ -1092,7 +1092,7 @@ pub fn try_map_bound<F, U: TypeFoldable<'tcx>, E>(self, f: F) -> Result<Binder<'
/// in `bind`. This may be (debug) asserted in the future.
pub fn rebind<U>(&self, value: U) -> Binder<'tcx, U>
where
U: TypeFoldable<'tcx>,
U: TypeVisitable<'tcx>,
{
if cfg!(debug_assertions) {
let mut validator = ValidateBoundVars::new(self.bound_vars());
......@@ -1113,7 +1113,7 @@ pub fn rebind<U>(&self, value: U) -> Binder<'tcx, U>
/// would not be that useful.)
pub fn no_bound_vars(self) -> Option<T>
where
T: TypeFoldable<'tcx>,
T: TypeVisitable<'tcx>,
{
if self.0.has_escaping_bound_vars() { None } else { Some(self.skip_binder()) }
}
......
......@@ -27,7 +27,9 @@
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::InternalSubsts;
use rustc_middle::ty::{self, Const, DefIdTree, GenericParamDefKind};
use rustc_middle::ty::{TraitRef, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor};
use rustc_middle::ty::{
TraitRef, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitable, TypeVisitor,
};
use rustc_session::lint;
use rustc_span::hygiene::Transparency;
use rustc_span::symbol::{kw, Ident};
......@@ -80,7 +82,7 @@ fn skeleton(&mut self) -> DefIdVisitorSkeleton<'_, 'tcx, Self> {
dummy: Default::default(),
}
}
fn visit(&mut self, ty_fragment: impl TypeFoldable<'tcx>) -> ControlFlow<Self::BreakTy> {
fn visit(&mut self, ty_fragment: impl TypeVisitable<'tcx>) -> ControlFlow<Self::BreakTy> {
ty_fragment.visit_with(&mut self.skeleton())
}
fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow<Self::BreakTy> {
......
......@@ -9,7 +9,7 @@
use rustc_middle::ty::print::{Print, Printer};
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
use rustc_middle::ty::{
self, EarlyBinder, FloatTy, Instance, IntTy, Ty, TyCtxt, TypeFoldable, UintTy,
self, EarlyBinder, FloatTy, Instance, IntTy, Ty, TyCtxt, TypeFoldable, TypeVisitable, UintTy,
};
use rustc_span::symbol::kw;
use rustc_target::abi::call::FnAbi;
......@@ -240,7 +240,7 @@ fn in_binder<'a, T>(
print_value: impl FnOnce(&'a mut Self, &T) -> Result<&'a mut Self, !>,
) -> Result<&'a mut Self, !>
where
T: TypeFoldable<'tcx>,
T: TypeVisitable<'tcx>,
{
let regions = if value.has_late_bound_regions() {
self.tcx.collect_referenced_late_bound_regions(value)
......
......@@ -19,7 +19,7 @@
use rustc_hir::def_id::DefId;
use rustc_middle::ty::subst::{GenericArg, InternalSubsts, Subst};
use rustc_middle::ty::{
self, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor,
self, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitable, TypeVisitor,
};
use rustc_middle::ty::{Predicate, ToPredicate};
use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY;
......@@ -731,7 +731,7 @@ fn receiver_is_dispatchable<'tcx>(
})
}
fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
fn contains_illegal_self_type_reference<'tcx, T: TypeVisitable<'tcx>>(
tcx: TyCtxt<'tcx>,
trait_def_id: DefId,
value: T,
......
......@@ -31,6 +31,7 @@
use rustc_middle::traits::select::OverflowError;
use rustc_middle::ty::fold::{MaxUniverse, TypeFoldable, TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{self, EarlyBinder, Term, ToPredicate, Ty, TyCtxt};
use rustc_span::symbol::sym;
......@@ -359,7 +360,7 @@ pub fn try_normalize_with_depth_to<'a, 'b, 'tcx, T>(
result
}
pub(crate) fn needs_normalization<'tcx, T: TypeFoldable<'tcx>>(value: &T, reveal: Reveal) -> bool {
pub(crate) fn needs_normalization<'tcx, T: TypeVisitable<'tcx>>(value: &T, reveal: Reveal) -> bool {
match reveal {
Reveal::UserFacing => value
.has_type_flags(ty::TypeFlags::HAS_TY_PROJECTION | ty::TypeFlags::HAS_CT_PROJECTION),
......
......@@ -14,6 +14,7 @@
use rustc_middle::mir;
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
use std::ops::ControlFlow;
......@@ -108,7 +109,7 @@ struct MaxEscapingBoundVarVisitor {
}
impl<'tcx> TypeVisitor<'tcx> for MaxEscapingBoundVarVisitor {
fn visit_binder<T: TypeFoldable<'tcx>>(
fn visit_binder<T: TypeVisitable<'tcx>>(
&mut self,
t: &ty::Binder<'tcx, T>,
) -> ControlFlow<Self::BreakTy> {
......
......@@ -35,7 +35,8 @@
use rustc_middle::traits::{ChalkEnvironmentAndGoal, ChalkRustInterner as RustInterner};
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
use rustc_middle::ty::{
self, Binder, Region, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitor,
self, Binder, Region, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable,
TypeVisitor,
};
use rustc_span::def_id::DefId;
......@@ -896,7 +897,7 @@ pub(crate) fn new() -> Self {
}
impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
fn visit_binder<T: TypeFoldable<'tcx>>(
fn visit_binder<T: TypeVisitable<'tcx>>(
&mut self,
t: &Binder<'tcx, T>,
) -> ControlFlow<Self::BreakTy> {
......
......@@ -4,7 +4,7 @@
use rustc_middle::traits::CodegenObligationError;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{
self, Binder, Instance, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor,
self, Binder, Instance, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitable, TypeVisitor,
};
use rustc_span::{sym, DUMMY_SP};
use rustc_trait_selection::traits;
......@@ -56,7 +56,7 @@ fn into_vars(self, tcx: TyCtxt<'tcx>) -> &'tcx ty::List<ty::BoundVariableKind> {
impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
type BreakTy = ();
fn visit_binder<T: TypeFoldable<'tcx>>(
fn visit_binder<T: TypeVisitable<'tcx>>(
&mut self,
t: &Binder<'tcx, T>,
) -> ControlFlow<Self::BreakTy> {
......
......@@ -23,6 +23,7 @@
use rustc_middle::ty::subst::{
self, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSelfTy, UserSubsts,
};
use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{
self, AdtKind, CanonicalUserType, DefIdTree, EarlyBinder, GenericParamDefKind, ToPolyTraitRef,
ToPredicate, Ty, UserType,
......@@ -557,7 +558,7 @@ pub fn const_arg_to_const(
// sufficiently enforced with erased regions. =)
fn can_contain_user_lifetime_bounds<T>(t: T) -> bool
where
T: TypeFoldable<'tcx>,
T: TypeVisitable<'tcx>,
{
t.has_free_regions() || t.has_projections() || t.has_infer_types()
}
......
......@@ -18,7 +18,7 @@
use rustc_middle::ty::trait_def::TraitSpecializationKind;
use rustc_middle::ty::{
self, AdtKind, DefIdTree, EarlyBinder, GenericParamDefKind, ToPredicate, Ty, TyCtxt,
TypeFoldable, TypeSuperFoldable, TypeVisitor,
TypeFoldable, TypeVisitable, TypeVisitor,
};
use rustc_session::parse::feature_err;
use rustc_span::symbol::{sym, Ident, Symbol};
......
use rustc_data_structures::fx::FxHashSet;
use rustc_middle::ty::fold::{TypeFoldable, TypeSuperFoldable, TypeVisitor};
use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::source_map::Span;
use std::ops::ControlFlow;
......@@ -43,7 +44,7 @@ pub fn parameters_for_impl<'tcx>(
/// of parameters whose values are needed in order to constrain `ty` - these
/// differ, with the latter being a superset, in the presence of projections.
pub fn parameters_for<'tcx>(
t: &impl TypeFoldable<'tcx>,
t: &impl TypeVisitable<'tcx>,
include_nonconstraining: bool,
) -> Vec<Parameter> {
let mut collector = ParameterCollector { parameters: vec![], include_nonconstraining };
......
......@@ -15,7 +15,7 @@
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
use rustc_middle::ty::{
self, AdtDef, Binder, BoundRegion, DefIdTree, FnSig, IntTy, ParamEnv, Predicate, PredicateKind, ProjectionTy,
Region, RegionKind, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor, UintTy, VariantDef, VariantDiscr,
Region, RegionKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, VariantDef, VariantDiscr,
};
use rustc_span::symbol::Ident;
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
......@@ -765,7 +765,7 @@ fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
ControlFlow::Continue(())
}
}
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<'tcx, T>) -> ControlFlow<Self::BreakTy> {
fn visit_binder<T: TypeVisitable<'tcx>>(&mut self, t: &Binder<'tcx, T>) -> ControlFlow<Self::BreakTy> {
self.index += 1;
let res = t.super_visit_with(self);
self.index -= 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册