From 465d198c74537d1b33b3bafa6a19676ee22d125d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 31 May 2022 15:07:28 +1000 Subject: [PATCH 1/7] Rename `TypeVisitor::visit_unevaluated_const`. To match the corresponding type name. --- compiler/rustc_middle/src/ty/fold.rs | 4 ++-- compiler/rustc_middle/src/ty/structural_impls.rs | 4 ++-- compiler/rustc_trait_selection/src/traits/object_safety.rs | 5 +---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index a2a450d76f18a..c995ea965af43 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -385,7 +385,7 @@ pub trait TypeVisitor<'tcx>: Sized { c.super_visit_with(self) } - fn visit_unevaluated_const(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow { + fn visit_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow { uv.super_visit_with(self) } @@ -1280,7 +1280,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { #[inline] #[instrument(level = "trace")] - fn visit_unevaluated_const(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow { + fn visit_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow { let flags = FlagComputation::for_unevaluated_const(uv); trace!(r.flags=?flags); if flags.intersects(self.flags) { diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 2c8cd4f933d04..adb4766492ef7 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -1248,7 +1248,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> { } fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - visitor.visit_unevaluated_const(*self) + visitor.visit_unevaluated(*self) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { @@ -1269,7 +1269,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx, ()> { } fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - visitor.visit_unevaluated_const(self.expand()) + visitor.visit_unevaluated(self.expand()) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 5c09e5d7be16a..9f1cd1b253af9 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -814,10 +814,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>( } } - fn visit_unevaluated_const( - &mut self, - uv: ty::Unevaluated<'tcx>, - ) -> ControlFlow { + fn visit_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ControlFlow { // Constants can only influence object safety if they reference `Self`. // This is only possible for unevaluated constants, so we walk these here. // From 28be201d2f23435e3ab3a21cc52030871a5ec04c Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 1 Jun 2022 09:38:07 +1000 Subject: [PATCH 2/7] Use `super_visit_with` in a couple of `visit_binder` methods. Because it's equivalent but simpler to what's currently there. --- compiler/rustc_infer/src/infer/opaque_types.rs | 2 +- compiler/rustc_middle/src/ty/fold.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 92c0ed84057a6..00b61874a50dc 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -470,7 +470,7 @@ where &mut self, t: &ty::Binder<'tcx, T>, ) -> ControlFlow { - t.as_ref().skip_binder().visit_with(self); + t.super_visit_with(self); ControlFlow::CONTINUE } diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index c995ea965af43..5cf40ad3b8ec1 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -514,7 +514,7 @@ impl<'tcx> TyCtxt<'tcx> { t: &Binder<'tcx, T>, ) -> ControlFlow { self.outer_index.shift_in(1); - let result = t.as_ref().skip_binder().visit_with(self); + let result = t.super_visit_with(self); self.outer_index.shift_out(1); result } From ca7585ab9a5c770eacf22dfcdbbe1ad72d8eab34 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 1 Jun 2022 10:25:56 +1000 Subject: [PATCH 3/7] Remove `EarlyBinder::{try_fold_with,visit_with}`. For most types the default impls of these methods are good enough, and `EarlyBinder` is one such type. --- compiler/rustc_middle/src/ty/structural_impls.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index adb4766492ef7..1390907d805ad 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -868,17 +868,9 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::EarlyBinder { self.try_map_bound(|ty| ty.try_fold_with(folder)) } - fn try_fold_with>(self, folder: &mut F) -> Result { - self.try_map_bound(|ty| ty.try_fold_with(folder)) - } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { self.as_ref().0.visit_with(visitor) } - - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.as_ref().0.visit_with(visitor) - } } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<'tcx, T> { From 6ba2dfd3305e44af7ab3a1a7f6085a236c009caa Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 1 Jun 2022 10:48:34 +1000 Subject: [PATCH 4/7] Add `TypeVisitor::visit_mir_const`. Because `TypeFoldable::try_fold_mir_const` exists, and even though `visit_mir_const` isn't needed right now, the consistency makes the code easier to understand. --- compiler/rustc_middle/src/mir/type_foldable.rs | 4 ++++ compiler/rustc_middle/src/ty/fold.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/compiler/rustc_middle/src/mir/type_foldable.rs b/compiler/rustc_middle/src/mir/type_foldable.rs index 14d4cb2c3302e..8f50ec4fe0852 100644 --- a/compiler/rustc_middle/src/mir/type_foldable.rs +++ b/compiler/rustc_middle/src/mir/type_foldable.rs @@ -406,4 +406,8 @@ impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> { ConstantKind::Val(_, t) => t.visit_with(visitor), } } + + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + visitor.visit_mir_const(*self) + } } diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 5cf40ad3b8ec1..c2d640009c4ff 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -392,6 +392,10 @@ pub trait TypeVisitor<'tcx>: Sized { fn visit_predicate(&mut self, p: ty::Predicate<'tcx>) -> ControlFlow { p.super_visit_with(self) } + + fn visit_mir_const(&mut self, c: mir::ConstantKind<'tcx>) -> ControlFlow { + c.super_visit_with(self) + } } /////////////////////////////////////////////////////////////////////////// From 23880a058bd9e3c482deaa8f6e6d6a5d3d6f7112 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 1 Jun 2022 17:20:56 +1000 Subject: [PATCH 5/7] Add `try_fold_uenevaluted`. We already have `visit_unevaluated`, so this improves consistency. Also, define `TypeFoldable for Unevaluated<'tcx, ()>` in terms of `TypeFoldable for Unevaluated<'tcx>`, which is neater. --- compiler/rustc_middle/src/ty/fold.rs | 14 ++++++++++++++ compiler/rustc_middle/src/ty/structural_impls.rs | 16 ++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index c2d640009c4ff..4b3ab62f27f78 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -263,6 +263,13 @@ pub trait TypeFolder<'tcx>: Sized { c.super_fold_with(self) } + fn fold_unevaluated(&mut self, uv: ty::Unevaluated<'tcx>) -> ty::Unevaluated<'tcx> + where + Self: TypeFolder<'tcx, Error = !>, + { + uv.super_fold_with(self) + } + fn fold_predicate(&mut self, p: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> where Self: TypeFolder<'tcx, Error = !>, @@ -305,6 +312,13 @@ pub trait FallibleTypeFolder<'tcx>: TypeFolder<'tcx> { c.try_super_fold_with(self) } + fn try_fold_unevaluated( + &mut self, + c: ty::Unevaluated<'tcx>, + ) -> Result, Self::Error> { + c.try_super_fold_with(self) + } + fn try_fold_predicate( &mut self, p: ty::Predicate<'tcx>, diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 1390907d805ad..53e058f205abf 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -1228,6 +1228,10 @@ impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> { + fn try_fold_with>(self, folder: &mut F) -> Result { + folder.try_fold_unevaluated(self) + } + fn try_super_fold_with>( self, folder: &mut F, @@ -1253,19 +1257,11 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx, ()> { self, folder: &mut F, ) -> Result { - Ok(ty::Unevaluated { - def: self.def, - substs: self.substs.try_fold_with(folder)?, - promoted: self.promoted, - }) - } - - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - visitor.visit_unevaluated(self.expand()) + Ok(self.expand().try_fold_with(folder)?.shrink()) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.substs.visit_with(visitor) + self.expand().visit_with(visitor) } } From 7480b501b4073cb38bacb64f22d7b09fb3f652d8 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 2 Jun 2022 11:31:23 +1000 Subject: [PATCH 6/7] Avoid some unnecessary `return`s. --- compiler/rustc_infer/src/infer/freshen.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index 0a11a81c29425..64c0c0f4f6415 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -228,12 +228,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> { .probe_value(v) .val .known(); - return self.freshen_const( - opt_ct, - ty::InferConst::Var(v), - ty::InferConst::Fresh, - ct.ty(), - ); + self.freshen_const(opt_ct, ty::InferConst::Var(v), ty::InferConst::Fresh, ct.ty()) } ty::ConstKind::Infer(ty::InferConst::Fresh(i)) => { if i >= self.const_freshen_count { @@ -244,7 +239,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> { self.const_freshen_count, ); } - return ct; + ct } ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(_) => { @@ -254,9 +249,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> { ty::ConstKind::Param(_) | ty::ConstKind::Value(_) | ty::ConstKind::Unevaluated(..) - | ty::ConstKind::Error(_) => {} + | ty::ConstKind::Error(_) => ct.super_fold_with(self), } - - ct.super_fold_with(self) } } From 90db033955eaa000f8eea5691ea4297687a4dbef Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 2 Jun 2022 11:38:15 +1000 Subject: [PATCH 7/7] Folding revamp. This commit makes type folding more like the way chalk does it. Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods. - `fold_with` is the standard entry point, and defaults to calling `super_fold_with`. - `super_fold_with` does the actual work of traversing a type. - For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead calls into a `TypeFolder`, which can then call back into `super_fold_with`. With the new approach, `TypeFoldable` has `fold_with` and `TypeSuperFoldable` has `super_fold_with`. - `fold_with` is still the standard entry point, *and* it does the actual work of traversing a type, for all types except types of interest. - `super_fold_with` is only implemented for the types of interest. Benefits of the new model. - I find it easier to understand. The distinction between types of interest and other types is clearer, and `super_fold_with` doesn't exist for most types. - With the current model is easy to get confused and implement a `super_fold_with` method that should be left defaulted. (Some of the precursor commits fixed such cases.) - With the current model it's easy to call `super_fold_with` within `TypeFolder` impls where `fold_with` should be called. The new approach makes this mistake impossible, and this commit fixes a number of such cases. - It's potentially faster, because it avoids the `fold_with` -> `super_fold_with` call in all cases except types of interest. A lot of the time the compile would inline those away, but not necessarily always. --- .../rustc_const_eval/src/interpret/util.rs | 4 +- .../src/infer/canonical/canonicalizer.rs | 2 +- .../src/infer/error_reporting/mod.rs | 2 +- .../nice_region_error/static_impl_trait.rs | 2 +- .../trait_impl_difference.rs | 2 +- compiler/rustc_infer/src/infer/freshen.rs | 2 +- compiler/rustc_infer/src/infer/fudge.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 2 +- .../rustc_infer/src/infer/nll_relate/mod.rs | 2 +- .../rustc_infer/src/infer/opaque_types.rs | 2 +- compiler/rustc_infer/src/infer/resolve.rs | 2 +- .../src/traits/structural_impls.rs | 7 +- compiler/rustc_lint/src/types.rs | 2 +- compiler/rustc_macros/src/type_foldable.rs | 4 +- compiler/rustc_middle/src/macros.rs | 8 +- compiler/rustc_middle/src/mir/mod.rs | 12 +- .../rustc_middle/src/mir/type_foldable.rs | 78 +++---- compiler/rustc_middle/src/ty/erase_regions.rs | 2 +- compiler/rustc_middle/src/ty/fold.rs | 132 ++++++----- compiler/rustc_middle/src/ty/instance.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 8 +- compiler/rustc_middle/src/ty/print/pretty.rs | 5 +- .../rustc_middle/src/ty/structural_impls.rs | 218 ++++++++---------- compiler/rustc_middle/src/ty/sty.rs | 3 +- compiler/rustc_middle/src/ty/subst.rs | 25 +- compiler/rustc_middle/src/ty/util.rs | 5 +- .../rustc_monomorphize/src/polymorphize.rs | 2 +- compiler/rustc_privacy/src/lib.rs | 6 +- .../rustc_trait_selection/src/opaque_types.rs | 2 +- .../src/traits/auto_trait.rs | 2 +- .../src/traits/error_reporting/mod.rs | 2 +- .../src/traits/object_safety.rs | 4 +- .../src/traits/project.rs | 13 +- .../src/traits/query/normalize.rs | 14 +- .../src/traits/structural_match.rs | 2 +- compiler/rustc_traits/src/chalk/db.rs | 2 +- compiler/rustc_traits/src/chalk/lowering.rs | 5 +- compiler/rustc_ty_utils/src/instance.rs | 4 +- compiler/rustc_typeck/src/check/check.rs | 3 +- compiler/rustc_typeck/src/check/op.rs | 5 +- compiler/rustc_typeck/src/check/wfcheck.rs | 2 +- compiler/rustc_typeck/src/check/writeback.rs | 2 +- compiler/rustc_typeck/src/coherence/orphan.rs | 6 +- compiler/rustc_typeck/src/collect/type_of.rs | 2 +- .../src/constrained_generic_params.rs | 2 +- src/librustdoc/clean/auto_trait.rs | 2 +- .../src/unit_types/let_unit_value.rs | 2 +- 47 files changed, 287 insertions(+), 332 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index 1940b573db0d6..0fddafbee7960 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -1,5 +1,5 @@ use rustc_middle::mir::interpret::InterpResult; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor}; use std::convert::TryInto; use std::ops::ControlFlow; @@ -47,7 +47,7 @@ where match (is_used, subst.needs_subst()) { // Just in case there are closures or generators within this subst, // recurse. - (true, true) => return subst.super_visit_with(self), + (true, true) => return subst.visit_with(self), // Confirm that polymorphization replaced the parameter with // `ty::Param`/`ty::ConstKind::Param`. (false, true) if cfg!(debug_assertions) => match subst.unpack() { diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 07e51afd90441..076825771971a 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -11,7 +11,7 @@ use crate::infer::canonical::{ }; use crate::infer::InferCtxt; use rustc_middle::ty::flags::FlagComputation; -use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; +use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::subst::GenericArg; use rustc_middle::ty::{self, BoundVar, InferConst, List, Ty, TyCtxt, TypeFlags}; use std::sync::atomic::Ordering; diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 97deb9d986d46..18fc1158b042d 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -70,7 +70,7 @@ use rustc_middle::ty::{ self, error::TypeError, subst::{GenericArgKind, Subst, SubstsRef}, - Binder, EarlyBinder, List, Region, Ty, TyCtxt, TypeFoldable, + Binder, EarlyBinder, List, Region, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, }; use rustc_span::{sym, symbol::kw, BytePos, DesugaringKind, Pos, Span}; use rustc_target::spec::abi; diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index 1081f888f7ff3..b856198cf3f7b 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -10,7 +10,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_ty, Visitor}; use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind}; use rustc_middle::ty::{ - self, AssocItemContainer, StaticLifetimeVisitor, Ty, TyCtxt, TypeFoldable, TypeVisitor, + self, AssocItemContainer, StaticLifetimeVisitor, Ty, TyCtxt, TypeSuperFoldable, TypeVisitor, }; use rustc_span::symbol::Ident; use rustc_span::Span; diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs index 1788eb8628a0a..17d4bb1bcbe35 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs @@ -11,7 +11,7 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::Visitor; use rustc_middle::hir::nested_filter; use rustc_middle::ty::print::RegionHighlightMode; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperFoldable, TypeVisitor}; use rustc_span::{Span, Symbol}; use std::ops::ControlFlow; diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index 64c0c0f4f6415..edafee2df5765 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -34,7 +34,7 @@ use super::InferCtxt; use rustc_data_structures::fx::FxHashMap; use rustc_middle::infer::unify_key::ToType; use rustc_middle::ty::fold::TypeFolder; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable}; use std::collections::hash_map::Entry; pub struct TypeFreshener<'a, 'tcx> { diff --git a/compiler/rustc_infer/src/infer/fudge.rs b/compiler/rustc_infer/src/infer/fudge.rs index c5b90f79dc284..1e6995db2698f 100644 --- a/compiler/rustc_infer/src/infer/fudge.rs +++ b/compiler/rustc_infer/src/infer/fudge.rs @@ -1,4 +1,4 @@ -use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; +use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::{self, ConstVid, FloatVid, IntVid, RegionVid, Ty, TyCtxt, TyVid}; use super::type_variable::TypeVariableOrigin; diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 24a9b399eac6b..21208933d4340 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -23,7 +23,7 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin use rustc_middle::mir::interpret::{ErrorHandled, EvalToConstValueResult}; use rustc_middle::traits::select; use rustc_middle::ty::error::{ExpectedFound, TypeError}; -use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; +use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::relate::RelateResult; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef}; pub use rustc_middle::ty::IntVarValue; diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index 6592e0ae8ec8f..9b6e5c8a347af 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -27,7 +27,7 @@ use crate::infer::{ConstVarValue, ConstVariableValue}; use crate::infer::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_data_structures::fx::FxHashMap; use rustc_middle::ty::error::TypeError; -use rustc_middle::ty::fold::{TypeFoldable, TypeVisitor}; +use rustc_middle::ty::fold::{TypeFoldable, TypeSuperFoldable, TypeVisitor}; use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation}; use rustc_middle::ty::{self, InferConst, Ty, TyCtxt}; use rustc_span::Span; diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 00b61874a50dc..80f6abbab3447 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -9,7 +9,7 @@ use rustc_middle::traits::ObligationCause; use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::subst::{GenericArgKind, Subst}; use rustc_middle::ty::{ - self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeVisitor, + self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor, }; use rustc_span::Span; diff --git a/compiler/rustc_infer/src/infer/resolve.rs b/compiler/rustc_infer/src/infer/resolve.rs index cf9345142afa7..ce3c7328e2da2 100644 --- a/compiler/rustc_infer/src/infer/resolve.rs +++ b/compiler/rustc_infer/src/infer/resolve.rs @@ -1,7 +1,7 @@ use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use super::{FixupError, FixupResult, InferCtxt, Span}; use rustc_middle::mir; -use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFolder, TypeVisitor}; +use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable, TypeVisitor}; use rustc_middle::ty::{self, Const, InferConst, Ty, TyCtxt, TypeFoldable}; use std::ops::ControlFlow; diff --git a/compiler/rustc_infer/src/traits/structural_impls.rs b/compiler/rustc_infer/src/traits/structural_impls.rs index 20453eeb1474e..82ee4bb29e88b 100644 --- a/compiler/rustc_infer/src/traits/structural_impls.rs +++ b/compiler/rustc_infer/src/traits/structural_impls.rs @@ -60,10 +60,7 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> { // TypeFoldable implementations. impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { Ok(traits::Obligation { cause: self.cause, recursion_depth: self.recursion_depth, @@ -72,7 +69,7 @@ impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx }) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.predicate.visit_with(visitor)?; self.param_env.visit_with(visitor) } diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 55b1ba9cd964a..2a2dc6822ce16 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -8,7 +8,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{is_range_literal, Expr, ExprKind, Node}; use rustc_middle::ty::layout::{IntegerExt, LayoutOf, SizeSkeleton}; use rustc_middle::ty::subst::SubstsRef; -use rustc_middle::ty::{self, AdtKind, DefIdTree, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{self, AdtKind, DefIdTree, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable}; use rustc_span::source_map; use rustc_span::symbol::sym; use rustc_span::{Span, Symbol, DUMMY_SP}; diff --git a/compiler/rustc_macros/src/type_foldable.rs b/compiler/rustc_macros/src/type_foldable.rs index bc8213a18eacc..9e834d3ba1c2d 100644 --- a/compiler/rustc_macros/src/type_foldable.rs +++ b/compiler/rustc_macros/src/type_foldable.rs @@ -30,14 +30,14 @@ pub fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:: s.bound_impl( quote!(::rustc_middle::ty::fold::TypeFoldable<'tcx>), quote! { - fn try_super_fold_with<__F: ::rustc_middle::ty::fold::FallibleTypeFolder<'tcx>>( + fn try_fold_with<__F: ::rustc_middle::ty::fold::FallibleTypeFolder<'tcx>>( self, __folder: &mut __F ) -> Result { Ok(match self { #body_fold }) } - fn super_visit_with<__F: ::rustc_middle::ty::fold::TypeVisitor<'tcx>>( + fn visit_with<__F: ::rustc_middle::ty::fold::TypeVisitor<'tcx>>( &self, __folder: &mut __F ) -> ::std::ops::ControlFlow<__F::BreakTy> { diff --git a/compiler/rustc_middle/src/macros.rs b/compiler/rustc_middle/src/macros.rs index 4e927f00acd5e..33b4dff977eb0 100644 --- a/compiler/rustc_middle/src/macros.rs +++ b/compiler/rustc_middle/src/macros.rs @@ -52,14 +52,14 @@ macro_rules! TrivialTypeFoldableImpls { (for <$tcx:lifetime> { $($ty:ty,)+ }) => { $( impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty { - fn try_super_fold_with>( + fn try_fold_with>( self, _: &mut F ) -> ::std::result::Result<$ty, F::Error> { Ok(self) } - fn super_visit_with>( + fn visit_with>( &self, _: &mut F) -> ::std::ops::ControlFlow @@ -95,14 +95,14 @@ macro_rules! EnumTypeFoldableImpl { impl<$($p),*> $crate::ty::fold::TypeFoldable<$tcx> for $s $(where $($wc)*)* { - fn try_super_fold_with>( + fn try_fold_with>( self, folder: &mut V, ) -> ::std::result::Result { EnumTypeFoldableImpl!(@FoldVariants(self, folder) input($($variants)*) output()) } - fn super_visit_with>( + fn visit_with>( &self, visitor: &mut V, ) -> ::std::ops::ControlFlow { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index f3db359ec3348..07ba3ce04089b 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -7,7 +7,7 @@ use crate::mir::interpret::{ConstAllocation, ConstValue, GlobalAlloc, LitToConst use crate::mir::visit::MirVisitable; use crate::ty::adjustment::PointerCast; use crate::ty::codec::{TyDecoder, TyEncoder}; -use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeVisitor}; +use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable, TypeVisitor}; use crate::ty::print::{FmtPrinter, Printer}; use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef}; use crate::ty::{self, List, Ty, TyCtxt}; @@ -3399,20 +3399,14 @@ impl UserTypeProjection { TrivialTypeFoldableAndLiftImpls! { ProjectionKind, } impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { Ok(UserTypeProjection { base: self.base.try_fold_with(folder)?, projs: self.projs.try_fold_with(folder)?, }) } - fn super_visit_with>( - &self, - visitor: &mut Vs, - ) -> ControlFlow { + fn visit_with>(&self, visitor: &mut Vs) -> ControlFlow { self.base.visit_with(visitor) // Note: there's nothing in `self.proj` to visit. } diff --git a/compiler/rustc_middle/src/mir/type_foldable.rs b/compiler/rustc_middle/src/mir/type_foldable.rs index 8f50ec4fe0852..4201b2d11ce2a 100644 --- a/compiler/rustc_middle/src/mir/type_foldable.rs +++ b/compiler/rustc_middle/src/mir/type_foldable.rs @@ -16,10 +16,7 @@ TrivialTypeFoldableAndLiftImpls! { } impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { use crate::mir::TerminatorKind::*; let kind = match self.kind { @@ -93,7 +90,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { Ok(Terminator { source_info: self.source_info, kind }) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { use crate::mir::TerminatorKind::*; match self.kind { @@ -144,50 +141,41 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for GeneratorKind { - fn try_super_fold_with>(self, _: &mut F) -> Result { + fn try_fold_with>(self, _: &mut F) -> Result { Ok(self) } - fn super_visit_with>(&self, _: &mut V) -> ControlFlow { + fn visit_with>(&self, _: &mut V) -> ControlFlow { ControlFlow::CONTINUE } } impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { Ok(Place { local: self.local.try_fold_with(folder)?, projection: self.projection.try_fold_with(folder)?, }) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.local.visit_with(visitor)?; self.projection.visit_with(visitor) } } impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { ty::util::fold_list(self, folder, |tcx, v| tcx.intern_place_elems(v)) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.iter().try_for_each(|t| t.visit_with(visitor)) } } impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { use crate::mir::Rvalue::*; Ok(match self { Use(op) => Use(op.try_fold_with(folder)?), @@ -237,7 +225,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> { }) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { use crate::mir::Rvalue::*; match *self { Use(ref op) => op.visit_with(visitor), @@ -288,10 +276,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { Ok(match self { Operand::Copy(place) => Operand::Copy(place.try_fold_with(folder)?), Operand::Move(place) => Operand::Move(place.try_fold_with(folder)?), @@ -299,7 +284,7 @@ impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> { }) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { match *self { Operand::Copy(ref place) | Operand::Move(ref place) => place.visit_with(visitor), Operand::Constant(ref c) => c.visit_with(visitor), @@ -308,10 +293,7 @@ impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { use crate::mir::ProjectionElem::*; Ok(match self { @@ -326,10 +308,7 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> { }) } - fn super_visit_with>( - &self, - visitor: &mut Vs, - ) -> ControlFlow { + fn visit_with>(&self, visitor: &mut Vs) -> ControlFlow { use crate::mir::ProjectionElem::*; match self { @@ -341,44 +320,41 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for Field { - fn try_super_fold_with>(self, _: &mut F) -> Result { + fn try_fold_with>(self, _: &mut F) -> Result { Ok(self) } - fn super_visit_with>(&self, _: &mut V) -> ControlFlow { + fn visit_with>(&self, _: &mut V) -> ControlFlow { ControlFlow::CONTINUE } } impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal { - fn try_super_fold_with>(self, _: &mut F) -> Result { + fn try_fold_with>(self, _: &mut F) -> Result { Ok(self) } - fn super_visit_with>(&self, _: &mut V) -> ControlFlow { + fn visit_with>(&self, _: &mut V) -> ControlFlow { ControlFlow::CONTINUE } } impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix { - fn try_super_fold_with>(self, _: &mut F) -> Result { + fn try_fold_with>(self, _: &mut F) -> Result { Ok(self) } - fn super_visit_with>(&self, _: &mut V) -> ControlFlow { + fn visit_with>(&self, _: &mut V) -> ControlFlow { ControlFlow::CONTINUE } } impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { Ok(Constant { span: self.span, user_ty: self.user_ty.try_fold_with(folder)?, literal: self.literal.try_fold_with(folder)?, }) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.literal.visit_with(visitor)?; self.user_ty.visit_with(visitor) } @@ -390,6 +366,12 @@ impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> { folder.try_fold_mir_const(self) } + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + visitor.visit_mir_const(*self) + } +} + +impl<'tcx> TypeSuperFoldable<'tcx> for ConstantKind<'tcx> { fn try_super_fold_with>( self, folder: &mut F, @@ -406,8 +388,4 @@ impl<'tcx> TypeFoldable<'tcx> for ConstantKind<'tcx> { ConstantKind::Val(_, t) => t.visit_with(visitor), } } - - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - visitor.visit_mir_const(*self) - } } diff --git a/compiler/rustc_middle/src/ty/erase_regions.rs b/compiler/rustc_middle/src/ty/erase_regions.rs index ef4f77c8a69e1..6d7e60ecc31be 100644 --- a/compiler/rustc_middle/src/ty/erase_regions.rs +++ b/compiler/rustc_middle/src/ty/erase_regions.rs @@ -1,5 +1,5 @@ use crate::mir; -use crate::ty::fold::{TypeFoldable, TypeFolder}; +use crate::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use crate::ty::{self, Ty, TyCtxt, TypeFlags}; pub(super) fn provide(providers: &mut ty::query::Providers) { diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 4b3ab62f27f78..5469aeb4c2ce0 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -15,16 +15,20 @@ //! the ones containing the most important type-related information, such as //! `Ty`, `Predicate`, `Region`, and `Const`. //! -//! There are two traits involved in each traversal type. -//! - The first trait is `TypeFoldable`, which is implemented once for many -//! types. This includes both (a) types of interest, and (b) all other -//! relevant types, including generic containers like `Vec` and `Option`. It -//! defines a "skeleton" of how they should be traversed, for both folding -//! and visiting. -//! - The second trait is `TypeFolder`/`FallibleTypeFolder` (for -//! infallible/fallible folding traversals) or `TypeVisitor` (for visiting -//! traversals). One of these is implemented for each folder/visitor. This -//! defines how types of interest are handled. +//! There are three traits involved in each traversal type. +//! - `TypeFoldable`. This is implemented once for many types. This includes +//! both: +//! - Types of interest, for which the the methods delegate to the +//! folder/visitor. +//! - All other types, including generic containers like `Vec` and `Option`. +//! It defines a "skeleton" of how they should be traversed, for both +//! folding and visiting. +//! - `TypeSuperFoldable`. This is implemented only for each type of interest, +//! and defines the traversal "skeleton" for these types. +//! - `TypeFolder`/`FallibleTypeFolder` (for infallible/fallible folding +//! traversals) or `TypeVisitor` (for visiting traversals). One of these is +//! implemented for each folder/visitor. This defines how types of interest +//! are folded/visited. //! //! This means each traversal is a mixture of (a) generic traversal operations, //! and (b) custom fold/visit operations that are specific to the @@ -32,22 +36,23 @@ //! - The `TypeFoldable` impls handle most of the traversal, and call into //! `TypeFolder`/`FallibleTypeFolder`/`TypeVisitor` when they encounter a //! type of interest. -//! - A `TypeFolder`/`FallibleTypeFolder`/`TypeVisitor` may also call back into -//! a `TypeFoldable` impl, because (a) the types of interest are recursive -//! and can contain other types of interest, and (b) each folder/visitor -//! might provide custom handling only for some types of interest, or only -//! for some variants of each type of interest, and then use default -//! traversal for the remaining cases. +//! - A `TypeFolder`/`FallibleTypeFolder`/`TypeVisitor` may call into another +//! `TypeFoldable` impl, because some of the types of interest are recursive +//! and can contain other types of interest. +//! - A `TypeFolder`/`FallibleTypeFolder`/`TypeVisitor` may also call into +//! a `TypeSuperFoldable` impl, because each folder/visitor might provide +//! custom handling only for some types of interest, or only for some +//! variants of each type of interest, and then use default traversal for the +//! remaining cases. //! //! For example, if you have `struct S(Ty, U)` where `S: TypeFoldable` and `U: -//! TypeFoldable`, and an instance `S(ty, u)`, it would be visited like so: +//! TypeFoldable`, and an instance `s = S(ty, u)`, it would be visited like so: //! ```text //! s.visit_with(visitor) calls -//! - s.super_visit_with(visitor) calls -//! - ty.visit_with(visitor) calls -//! - visitor.visit_ty(ty) may call -//! - ty.super_visit_with(visitor) -//! - u.visit_with(visitor) +//! - ty.visit_with(visitor) calls +//! - visitor.visit_ty(ty) may call +//! - ty.super_visit_with(visitor) +//! - u.visit_with(visitor) //! ``` use crate::mir; use crate::ty::{self, flags::FlagComputation, Binder, Ty, TyCtxt, TypeFlags}; @@ -66,18 +71,17 @@ use std::ops::ControlFlow; /// To implement this conveniently, use the derive macro located in /// `rustc_macros`. pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { - /// The main entry point for folding. To fold a value `t` with a folder `f` + /// The entry point for folding. To fold a value `t` with a folder `f` /// call: `t.try_fold_with(f)`. /// - /// For types of interest (such as `Ty`), this default is overridden with a - /// method that calls a folder method specifically for that type (such as + /// For most types, this just traverses the value, calling `try_fold_with` + /// on each field/element. + /// + /// For types of interest (such as `Ty`), the implementation of method + /// calls a folder method specifically for that type (such as /// `F::try_fold_ty`). This is where control transfers from `TypeFoldable` /// to `TypeFolder`. - /// - /// For other types, this default is used. - fn try_fold_with>(self, folder: &mut F) -> Result { - self.try_super_fold_with(folder) - } + fn try_fold_with>(self, folder: &mut F) -> Result; /// A convenient alternative to `try_fold_with` for use with infallible /// folders. Do not override this method, to ensure coherence with @@ -86,40 +90,17 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { self.try_fold_with(folder).into_ok() } - /// Traverses the type in question, typically by calling `try_fold_with` on - /// each field/element. This is true even for types of interest such as - /// `Ty`. This should only be called within `TypeFolder` methods, when - /// non-custom traversals are desired for types of interest. - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result; - - /// A convenient alternative to `try_super_fold_with` for use with - /// infallible folders. Do not override this method, to ensure coherence - /// with `try_super_fold_with`. - fn super_fold_with>(self, folder: &mut F) -> Self { - self.try_super_fold_with(folder).into_ok() - } - /// The entry point for visiting. To visit a value `t` with a visitor `v` /// call: `t.visit_with(v)`. /// - /// For types of interest (such as `Ty`), this default is overridden with a - /// method that calls a visitor method specifically for that type (such as + /// For most types, this just traverses the value, calling `visit_with` on + /// each field/element. + /// + /// For types of interest (such as `Ty`), the implementation of this method + /// that calls a visitor method specifically for that type (such as /// `V::visit_ty`). This is where control transfers from `TypeFoldable` to /// `TypeVisitor`. - /// - /// For other types, this default is used. - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.super_visit_with(visitor) - } - - /// Traverses the type in question, typically by calling `visit_with` on - /// each field/element. This is true even for types of interest such as - /// `Ty`. This should only be called within `TypeVisitor` methods, when - /// non-custom traversals are desired for types of interest. - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow; + fn visit_with>(&self, visitor: &mut V) -> ControlFlow; /// Returns `true` if `self` has any late-bound regions that are either /// bound by `binder` or bound by some binder outside of `binder`. @@ -219,9 +200,40 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone { } } +// This trait is implemented for types of interest. +pub trait TypeSuperFoldable<'tcx>: TypeFoldable<'tcx> { + /// Provides a default fold for a type of interest. This should only be + /// called within `TypeFolder` methods, when a non-custom traversal is + /// desired for the value of the type of interest passed to that method. + /// For example, in `MyFolder::try_fold_ty(ty)`, it is valid to call + /// `ty.try_super_fold_with(self)`, but any other folding should be done + /// with `xyz.try_fold_with(self)`. + fn try_super_fold_with>( + self, + folder: &mut F, + ) -> Result; + + /// A convenient alternative to `try_super_fold_with` for use with + /// infallible folders. Do not override this method, to ensure coherence + /// with `try_super_fold_with`. + fn super_fold_with>(self, folder: &mut F) -> Self { + self.try_super_fold_with(folder).into_ok() + } + + /// Provides a default visit for a type of interest. This should only be + /// called within `TypeVisitor` methods, when a non-custom traversal is + /// desired for the value of the type of interest passed to that method. + /// For example, in `MyVisitor::visit_ty(ty)`, it is valid to call + /// `ty.super_visit_with(self)`, but any other visiting should be done + /// with `xyz.visit_with(self)`. + fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow; +} + /// This trait is implemented for every folding traversal. There is a fold /// method defined for every type of interest. Each such method has a default -/// that does an "identity" fold. +/// that does an "identity" fold. Implementations of these methods often fall +/// back to a `super_fold_with` method if the primary argument doesn't +/// satisfy a particular condition. /// /// If this folder is fallible (and therefore its [`Error`][`TypeFolder::Error`] /// associated type is something other than the default `!`) then diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index f088db00d02a1..b7130e69f3501 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::subst::{InternalSubsts, Subst}; -use crate::ty::{self, EarlyBinder, SubstsRef, Ty, TyCtxt, TypeFoldable}; +use crate::ty::{self, EarlyBinder, SubstsRef, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable}; use rustc_errors::ErrorGuaranteed; use rustc_hir::def::Namespace; use rustc_hir::def_id::{CrateNum, DefId}; diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 3a2d3408b9d93..48ac7ecdf050f 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -9,7 +9,9 @@ //! //! ["The `ty` module: representing types"]: https://rustc-dev-guide.rust-lang.org/ty.html -pub use self::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeVisitor}; +pub use self::fold::{ + FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitor, +}; pub use self::AssocItemContainer::*; pub use self::BorrowKind::*; pub use self::IntVarValue::*; @@ -1434,7 +1436,7 @@ impl<'a, 'tcx> HashStable> for ParamEnv<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for ParamEnv<'tcx> { - fn try_super_fold_with>( + fn try_fold_with>( self, folder: &mut F, ) -> Result { @@ -1445,7 +1447,7 @@ impl<'tcx> TypeFoldable<'tcx> for ParamEnv<'tcx> { )) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.caller_bounds().visit_with(visitor)?; self.reveal().visit_with(visitor)?; self.constness().visit_with(visitor) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 08879afa64a0e..7328b18a3283a 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1,6 +1,9 @@ use crate::mir::interpret::{AllocRange, ConstValue, GlobalAlloc, Pointer, Provenance, Scalar}; use crate::ty::subst::{GenericArg, GenericArgKind, Subst}; -use crate::ty::{self, ConstInt, DefIdTree, ParamConst, ScalarInt, Term, Ty, TyCtxt, TypeFoldable}; +use crate::ty::{ + self, ConstInt, DefIdTree, ParamConst, ScalarInt, Term, Ty, TyCtxt, TypeFoldable, + TypeSuperFoldable, +}; use rustc_apfloat::ieee::{Double, Single}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sso::SsoHashSet; diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 53e058f205abf..9759bec996e96 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -4,7 +4,7 @@ use crate::mir::interpret; use crate::mir::ProjectionKind; -use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeVisitor}; +use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable, TypeVisitor}; use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer}; use crate::ty::{self, InferConst, Lift, Term, Ty, TyCtxt}; use rustc_data_structures::functor::IdFunctor; @@ -672,27 +672,24 @@ impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> { /// AdtDefs are basically the same as a DefId. impl<'tcx> TypeFoldable<'tcx> for ty::AdtDef<'tcx> { - fn try_super_fold_with>( - self, - _folder: &mut F, - ) -> Result { + fn try_fold_with>(self, _folder: &mut F) -> Result { Ok(self) } - fn super_visit_with>(&self, _visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, _visitor: &mut V) -> ControlFlow { ControlFlow::CONTINUE } } impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> TypeFoldable<'tcx> for (T, U) { - fn try_super_fold_with>( + fn try_fold_with>( self, folder: &mut F, ) -> Result<(T, U), F::Error> { Ok((self.0.try_fold_with(folder)?, self.1.try_fold_with(folder)?)) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.0.visit_with(visitor)?; self.1.visit_with(visitor) } @@ -701,7 +698,7 @@ impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> TypeFoldable<'tcx> for impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>> TypeFoldable<'tcx> for (A, B, C) { - fn try_super_fold_with>( + fn try_fold_with>( self, folder: &mut F, ) -> Result<(A, B, C), F::Error> { @@ -712,7 +709,7 @@ impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>> )) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.0.visit_with(visitor)?; self.1.visit_with(visitor)?; self.2.visit_with(visitor) @@ -734,7 +731,7 @@ EnumTypeFoldableImpl! { } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc { - fn try_super_fold_with>( + fn try_fold_with>( mut self, folder: &mut F, ) -> Result { @@ -772,13 +769,13 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Rc { } } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { (**self).visit_with(visitor) } } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc { - fn try_super_fold_with>( + fn try_fold_with>( mut self, folder: &mut F, ) -> Result { @@ -816,115 +813,96 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Arc { } } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { (**self).visit_with(visitor) } } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { self.try_map_id(|value| value.try_fold_with(folder)) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { (**self).visit_with(visitor) } } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { self.try_map_id(|t| t.try_fold_with(folder)) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.iter().try_for_each(|t| t.visit_with(visitor)) } } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { self.try_map_id(|t| t.try_fold_with(folder)) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.iter().try_for_each(|t| t.visit_with(visitor)) } } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::EarlyBinder { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { self.try_map_bound(|ty| ty.try_fold_with(folder)) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.as_ref().0.visit_with(visitor) } } impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<'tcx, T> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { - self.try_map_bound(|ty| ty.try_fold_with(folder)) - } - fn try_fold_with>(self, folder: &mut F) -> Result { folder.try_fold_binder(self) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.as_ref().skip_binder().visit_with(visitor) - } - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { visitor.visit_binder(self) } } -impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List>> { +impl<'tcx, T: TypeFoldable<'tcx>> TypeSuperFoldable<'tcx> for ty::Binder<'tcx, T> { fn try_super_fold_with>( self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.intern_poly_existential_predicates(v)) + self.try_map_bound(|ty| ty.try_fold_with(folder)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.as_ref().skip_binder().visit_with(visitor) + } +} + +impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List>> { + fn try_fold_with>(self, folder: &mut F) -> Result { + ty::util::fold_list(self, folder, |tcx, v| tcx.intern_poly_existential_predicates(v)) + } + + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.iter().try_for_each(|p| p.visit_with(visitor)) } } impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v)) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.iter().try_for_each(|t| t.visit_with(visitor)) } } impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { use crate::ty::InstanceDef::*; Ok(Self { substs: self.substs.try_fold_with(folder)?, @@ -950,7 +928,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> { }) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { use crate::ty::InstanceDef::*; self.substs.visit_with(visitor)?; match self.def { @@ -972,19 +950,26 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { Ok(Self { instance: self.instance.try_fold_with(folder)?, promoted: self.promoted }) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.instance.visit_with(visitor) } } impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { + fn try_fold_with>(self, folder: &mut F) -> Result { + folder.try_fold_ty(self) + } + + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + visitor.visit_ty(*self) + } +} + +impl<'tcx> TypeSuperFoldable<'tcx> for Ty<'tcx> { fn try_super_fold_with>( self, folder: &mut F, @@ -1029,10 +1014,6 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { Ok(if *self.kind() == kind { self } else { folder.tcx().mk_ty(kind) }) } - fn try_fold_with>(self, folder: &mut F) -> Result { - folder.try_fold_ty(self) - } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { match self.kind() { ty::RawPtr(ref tm) => tm.visit_with(visitor), @@ -1074,13 +1055,19 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { | ty::Foreign(..) => ControlFlow::CONTINUE, } } +} + +impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> { + fn try_fold_with>(self, folder: &mut F) -> Result { + folder.try_fold_region(self) + } fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - visitor.visit_ty(*self) + visitor.visit_region(*self) } } -impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> { +impl<'tcx> TypeSuperFoldable<'tcx> for ty::Region<'tcx> { fn try_super_fold_with>( self, _folder: &mut F, @@ -1088,17 +1075,9 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> { Ok(self) } - fn try_fold_with>(self, folder: &mut F) -> Result { - folder.try_fold_region(self) - } - fn super_visit_with>(&self, _visitor: &mut V) -> ControlFlow { ControlFlow::CONTINUE } - - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - visitor.visit_region(*self) - } } impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { @@ -1106,18 +1085,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { folder.try_fold_predicate(self) } - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { - let new = self.kind().try_fold_with(folder)?; - Ok(folder.tcx().reuse_or_mk_predicate(self, new)) - } - - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.kind().visit_with(visitor) - } - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { visitor.visit_predicate(*self) } @@ -1131,33 +1098,51 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { } } -impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { +impl<'tcx> TypeSuperFoldable<'tcx> for ty::Predicate<'tcx> { fn try_super_fold_with>( self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.intern_predicates(v)) + let new = self.kind().try_fold_with(folder)?; + Ok(folder.tcx().reuse_or_mk_predicate(self, new)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + self.kind().visit_with(visitor) + } +} + +impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { + fn try_fold_with>(self, folder: &mut F) -> Result { + ty::util::fold_list(self, folder, |tcx, v| tcx.intern_predicates(v)) + } + + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.iter().try_for_each(|p| p.visit_with(visitor)) } } impl<'tcx, T: TypeFoldable<'tcx>, I: Idx> TypeFoldable<'tcx> for IndexVec { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { self.try_map_id(|x| x.try_fold_with(folder)) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.iter().try_for_each(|t| t.visit_with(visitor)) } } impl<'tcx> TypeFoldable<'tcx> for ty::Const<'tcx> { + fn try_fold_with>(self, folder: &mut F) -> Result { + folder.try_fold_const(self) + } + + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + visitor.visit_const(*self) + } +} + +impl<'tcx> TypeSuperFoldable<'tcx> for ty::Const<'tcx> { fn try_super_fold_with>( self, folder: &mut F, @@ -1171,25 +1156,14 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Const<'tcx> { } } - fn try_fold_with>(self, folder: &mut F) -> Result { - folder.try_fold_const(self) - } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { self.ty().visit_with(visitor)?; self.val().visit_with(visitor) } - - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - visitor.visit_const(*self) - } } impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { Ok(match self { ty::ConstKind::Infer(ic) => ty::ConstKind::Infer(ic.try_fold_with(folder)?), ty::ConstKind::Param(p) => ty::ConstKind::Param(p.try_fold_with(folder)?), @@ -1201,7 +1175,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> { }) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { match *self { ty::ConstKind::Infer(ic) => ic.visit_with(visitor), ty::ConstKind::Param(p) => p.visit_with(visitor), @@ -1215,14 +1189,11 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ConstKind<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> { - fn try_super_fold_with>( - self, - _folder: &mut F, - ) -> Result { + fn try_fold_with>(self, _folder: &mut F) -> Result { Ok(self) } - fn super_visit_with>(&self, _visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, _visitor: &mut V) -> ControlFlow { ControlFlow::CONTINUE } } @@ -1232,6 +1203,12 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> { folder.try_fold_unevaluated(self) } + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { + visitor.visit_unevaluated(*self) + } +} + +impl<'tcx> TypeSuperFoldable<'tcx> for ty::Unevaluated<'tcx> { fn try_super_fold_with>( self, folder: &mut F, @@ -1243,34 +1220,27 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx> { }) } - fn visit_with>(&self, visitor: &mut V) -> ControlFlow { - visitor.visit_unevaluated(*self) - } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { self.substs.visit_with(visitor) } } impl<'tcx> TypeFoldable<'tcx> for ty::Unevaluated<'tcx, ()> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { Ok(self.expand().try_fold_with(folder)?.shrink()) } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.expand().visit_with(visitor) } } impl<'tcx> TypeFoldable<'tcx> for hir::Constness { - fn try_super_fold_with>(self, _: &mut F) -> Result { + fn try_fold_with>(self, _: &mut F) -> Result { Ok(self) } - fn super_visit_with>(&self, _: &mut V) -> ControlFlow { + fn visit_with>(&self, _: &mut V) -> ControlFlow { ControlFlow::CONTINUE } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 09fe8415652ac..cc85859e1cc0a 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -7,7 +7,8 @@ use crate::ty::fold::ValidateBoundVars; use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef}; use crate::ty::InferTy::*; use crate::ty::{ - self, AdtDef, DefIdTree, Discr, Term, Ty, TyCtxt, TypeFlags, TypeFoldable, TypeVisitor, + self, AdtDef, DefIdTree, Discr, Term, Ty, TyCtxt, TypeFlags, TypeFoldable, TypeSuperFoldable, + TypeVisitor, }; use crate::ty::{List, ParamEnv}; use polonius_engine::Atom; diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 290485ab5fe0f..88c88e357d9d9 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -2,7 +2,9 @@ use crate::mir; use crate::ty::codec::{TyDecoder, TyEncoder}; -use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeVisitor}; +use crate::ty::fold::{ + FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitor, +}; use crate::ty::sty::{ClosureSubsts, GeneratorSubsts, InlineConstSubsts}; use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt}; @@ -196,10 +198,7 @@ impl<'a, 'tcx> Lift<'tcx> for GenericArg<'a> { } impl<'tcx> TypeFoldable<'tcx> for GenericArg<'tcx> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { match self.unpack() { GenericArgKind::Lifetime(lt) => lt.try_fold_with(folder).map(Into::into), GenericArgKind::Type(ty) => ty.try_fold_with(folder).map(Into::into), @@ -207,7 +206,7 @@ impl<'tcx> TypeFoldable<'tcx> for GenericArg<'tcx> { } } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { match self.unpack() { GenericArgKind::Lifetime(lt) => lt.visit_with(visitor), GenericArgKind::Type(ty) => ty.visit_with(visitor), @@ -425,10 +424,7 @@ impl<'tcx> InternalSubsts<'tcx> { } impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { // This code is hot enough that it's worth specializing for the most // 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 @@ -454,16 +450,13 @@ impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> { } } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.iter().try_for_each(|t| t.visit_with(visitor)) } } impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { - fn try_super_fold_with>( - self, - folder: &mut F, - ) -> Result { + fn try_fold_with>(self, folder: &mut F) -> Result { // This code is fairly hot, though not as hot as `SubstsRef`. // // When compiling stage 2, I get the following results: @@ -493,7 +486,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { } } - fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { + fn visit_with>(&self, visitor: &mut V) -> ControlFlow { self.iter().try_for_each(|t| t.visit_with(visitor)) } } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 809e7ce2e745b..22cb46a4cbcc2 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -1,11 +1,12 @@ //! Miscellaneous type-system utilities that are too small to deserve their own modules. use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; -use crate::ty::fold::{FallibleTypeFolder, TypeFolder}; use crate::ty::layout::IntegerExt; use crate::ty::query::TyCtxtAt; use crate::ty::subst::{GenericArgKind, Subst, SubstsRef}; -use crate::ty::{self, DefIdTree, Ty, TyCtxt, TypeFoldable}; +use crate::ty::{ + self, DefIdTree, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, +}; use rustc_apfloat::Float as _; use rustc_ast as ast; use rustc_attr::{self as attr, SignedInt, UnsignedInt}; diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index 3cfd935d8b0ae..dc1f1c9927d5d 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -13,7 +13,7 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::{ self, - fold::{TypeFoldable, TypeVisitor}, + fold::{TypeFoldable, TypeSuperFoldable, TypeVisitor}, query::Providers, subst::SubstsRef, Const, Ty, TyCtxt, diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 82ea78648c77d..e77e5a3ca022a 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -20,11 +20,10 @@ use rustc_middle::hir::nested_filter; use rustc_middle::middle::privacy::{AccessLevel, AccessLevels}; use rustc_middle::span_bug; use rustc_middle::thir::abstract_const::Node as ACNode; -use rustc_middle::ty::fold::TypeVisitor; 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}; +use rustc_middle::ty::{TraitRef, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor}; use rustc_session::lint; use rustc_span::hygiene::Transparency; use rustc_span::symbol::{kw, Ident}; @@ -181,7 +180,8 @@ where fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { let tcx = self.def_id_visitor.tcx(); - // InternalSubsts are not visited here because they are visited below in `super_visit_with`. + // InternalSubsts are not visited here because they are visited below + // in `super_visit_with`. match *ty.kind() { ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), ..) | ty::Foreign(def_id) diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index 452b0d73c97ca..c1faa15d43cbe 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -7,7 +7,7 @@ use rustc_hir::OpaqueTyOrigin; use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt as _}; use rustc_infer::traits::{Obligation, ObligationCause, TraitEngine}; -use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; +use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts}; use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, ToPredicate, Ty, TyCtxt}; use rustc_span::Span; diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 79e9635f90ef6..4bcd3bdd1ef45 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -6,7 +6,7 @@ use super::*; use crate::infer::region_constraints::{Constraint, RegionConstraintData}; use crate::infer::InferCtxt; use crate::traits::project::ProjectAndUnifyResult; -use rustc_middle::ty::fold::TypeFolder; +use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::{Region, RegionVid, Term}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 0cefa802c857d..255b52584edc6 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -27,7 +27,7 @@ use rustc_infer::traits::TraitEngine; use rustc_middle::thir::abstract_const::NotConstEvaluatable; use rustc_middle::traits::select::OverflowError; use rustc_middle::ty::error::ExpectedFound; -use rustc_middle::ty::fold::TypeFolder; +use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::{ self, SubtypePredicate, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeFoldable, }; diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 9f1cd1b253af9..132c335a7e65d 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -18,7 +18,9 @@ use rustc_errors::{FatalError, MultiSpan}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_middle::ty::subst::{GenericArg, InternalSubsts, Subst}; -use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{ + self, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor, +}; use rustc_middle::ty::{Predicate, ToPredicate}; use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY; use rustc_span::symbol::Symbol; diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 17e0fae985315..9f75bdb2533e6 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -29,7 +29,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::lang_items::LangItem; use rustc_infer::infer::resolve::OpportunisticRegionResolver; use rustc_middle::traits::select::OverflowError; -use rustc_middle::ty::fold::{MaxUniverse, TypeFoldable, TypeFolder}; +use rustc_middle::ty::fold::{MaxUniverse, TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{self, EarlyBinder, Term, ToPredicate, Ty, TyCtxt}; use rustc_span::symbol::sym; @@ -514,7 +514,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { self.selcx.infcx().report_overflow_error(&obligation, true); } - let substs = substs.super_fold_with(self); + let substs = substs.fold_with(self); let generic_ty = self.tcx().bound_type_of(def_id); let concrete_ty = generic_ty.subst(self.tcx(), substs); self.depth += 1; @@ -531,8 +531,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { // placeholders (see branch below). *Also*, we know that we can // register an obligation to *later* project, since we know // there won't be bound vars there. - - let data = data.super_fold_with(self); + let data = data.fold_with(self); let normalized_ty = if self.eager_inference_replacement { normalize_projection_type( self.selcx, @@ -581,7 +580,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { let infcx = self.selcx.infcx(); let (data, mapped_regions, mapped_types, mapped_consts) = BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, data); - let data = data.super_fold_with(self); + let data = data.fold_with(self); let normalized_ty = opt_normalize_projection_type( self.selcx, self.param_env, @@ -671,7 +670,7 @@ impl<'me, 'tcx> BoundVarReplacer<'me, 'tcx> { universe_indices, }; - let value = value.super_fold_with(&mut replacer); + let value = value.fold_with(&mut replacer); (value, replacer.mapped_regions, replacer.mapped_types, replacer.mapped_consts) } @@ -794,7 +793,7 @@ impl<'me, 'tcx> PlaceholderReplacer<'me, 'tcx> { universe_indices, current_index: ty::INNERMOST, }; - value.super_fold_with(&mut replacer) + value.fold_with(&mut replacer) } } diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 6a81a7764afd9..e9e2dca17e9e4 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -12,7 +12,7 @@ use rustc_data_structures::sso::SsoHashMap; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_infer::traits::Normalized; use rustc_middle::mir; -use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder}; +use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor}; @@ -205,7 +205,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { Reveal::UserFacing => ty.try_super_fold_with(self), Reveal::All => { - let substs = substs.try_super_fold_with(self)?; + let substs = substs.try_fold_with(self)?; let recursion_limit = self.tcx().recursion_limit(); if !recursion_limit.value_within_limit(self.anon_depth) { let obligation = Obligation::with_depth( @@ -242,7 +242,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { // we don't need to replace them with placeholders (see branch below). let tcx = self.infcx.tcx; - let data = data.try_super_fold_with(self)?; + let data = data.try_fold_with(self)?; let mut orig_values = OriginalQueryValues::default(); // HACK(matthewjasper) `'static` is special-cased in selection, @@ -281,7 +281,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { &mut self.universes, data, ); - let data = data.try_super_fold_with(self)?; + let data = data.try_fold_with(self)?; let mut orig_values = OriginalQueryValues::default(); // HACK(matthewjasper) `'static` is special-cased in selection, @@ -334,7 +334,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { &mut self, constant: mir::ConstantKind<'tcx>, ) -> Result, Self::Error> { - let constant_kind = match constant { + Ok(match constant { mir::ConstantKind::Ty(c) => { let const_folded = c.try_fold_with(self)?; match const_folded.val() { @@ -347,8 +347,6 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { } } mir::ConstantKind::Val(_, _) => constant.try_super_fold_with(self)?, - }; - - Ok(constant_kind) + }) } } diff --git a/compiler/rustc_trait_selection/src/traits/structural_match.rs b/compiler/rustc_trait_selection/src/traits/structural_match.rs index 5465395768c6b..bc2ce31df6d93 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_match.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_match.rs @@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::lang_items::LangItem; use rustc_middle::ty::query::Providers; -use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor}; use rustc_span::Span; use std::ops::ControlFlow; diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index 5b5b849919188..3de2fa2215bb2 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -9,7 +9,7 @@ use rustc_middle::traits::ChalkRustInterner as RustInterner; use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::{ - self, AssocItemContainer, AssocKind, EarlyBinder, Ty, TyCtxt, TypeFoldable, + self, AssocItemContainer, AssocKind, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, }; use rustc_ast::ast; diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 2b7ba22c4de38..4fd512d7b8de2 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -33,9 +33,10 @@ use rustc_ast::ast; use rustc_middle::traits::{ChalkEnvironmentAndGoal, ChalkRustInterner as RustInterner}; -use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef}; -use rustc_middle::ty::{self, Binder, Region, Ty, TyCtxt, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{ + self, Binder, Region, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitor, +}; use rustc_span::def_id::DefId; use chalk_ir::{FnSig, ForeignDefId}; diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 17eac2bb2c9e9..9c450fe1e32a6 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -3,7 +3,9 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::traits::CodegenObligationError; use rustc_middle::ty::subst::SubstsRef; -use rustc_middle::ty::{self, Binder, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{ + self, Binder, Instance, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor, +}; use rustc_span::{sym, DUMMY_SP}; use rustc_trait_selection::traits; use traits::{translate_substs, Reveal}; diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs index de5367ca27c3a..80abb28ee58c1 100644 --- a/compiler/rustc_typeck/src/check/check.rs +++ b/compiler/rustc_typeck/src/check/check.rs @@ -17,11 +17,10 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi use rustc_infer::infer::{RegionVariableOrigin, TyCtxtInferExt}; use rustc_infer::traits::Obligation; use rustc_middle::hir::nested_filter; -use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES}; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::util::{Discr, IntTypeExt}; -use rustc_middle::ty::{self, ParamEnv, ToPredicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable}; use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS}; use rustc_span::symbol::sym; use rustc_span::{self, Span}; diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index 3ae04706e4bc3..17a1f619ee160 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -9,8 +9,9 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi use rustc_middle::ty::adjustment::{ Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, }; -use rustc_middle::ty::fold::TypeFolder; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{ + self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitor, +}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{sym, Ident}; use rustc_span::Span; diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 20ef97c085f18..d506314eb939e 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -22,7 +22,7 @@ use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts, Subst}; use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::{ self, AdtKind, EarlyBinder, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, - TypeVisitor, + TypeSuperFoldable, TypeVisitor, }; use rustc_session::parse::feature_err; use rustc_span::symbol::{sym, Ident, Symbol}; diff --git a/compiler/rustc_typeck/src/check/writeback.rs b/compiler/rustc_typeck/src/check/writeback.rs index a295bcf408900..dc135f002f483 100644 --- a/compiler/rustc_typeck/src/check/writeback.rs +++ b/compiler/rustc_typeck/src/check/writeback.rs @@ -14,7 +14,7 @@ use rustc_infer::infer::InferCtxt; use rustc_middle::hir::place::Place as HirPlace; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast}; -use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; +use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::{self, ClosureSizeProfileData, Ty, TyCtxt}; use rustc_span::symbol::sym; use rustc_span::Span; diff --git a/compiler/rustc_typeck/src/coherence/orphan.rs b/compiler/rustc_typeck/src/coherence/orphan.rs index eb6217f117496..9ddfc8d5cc82b 100644 --- a/compiler/rustc_typeck/src/coherence/orphan.rs +++ b/compiler/rustc_typeck/src/coherence/orphan.rs @@ -9,7 +9,9 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::util::IgnoreRegions; -use rustc_middle::ty::{self, ImplPolarity, Ty, TyCtxt, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{ + self, ImplPolarity, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitor, +}; use rustc_session::lint; use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::Span; @@ -439,7 +441,7 @@ fn fast_reject_auto_impl<'tcx>(tcx: TyCtxt<'tcx>, trait_def_id: DefId, self_ty: } match t.kind() { - ty::Adt(def, substs) if def.is_phantom_data() => substs.super_visit_with(self), + ty::Adt(def, substs) if def.is_phantom_data() => substs.visit_with(self), ty::Adt(def, substs) => { // @lcnr: This is the only place where cycles can happen. We avoid this // by only visiting each `DefId` once. diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 2433401b7f0f5..451a953691bae 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -8,7 +8,7 @@ use rustc_hir::{HirId, Node}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::util::IntTypeExt; -use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt, TypeFoldable, TypeFolder}; +use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_span::symbol::Ident; use rustc_span::{Span, DUMMY_SP}; diff --git a/compiler/rustc_typeck/src/constrained_generic_params.rs b/compiler/rustc_typeck/src/constrained_generic_params.rs index 7f2e57e61098f..fc299057f4bf1 100644 --- a/compiler/rustc_typeck/src/constrained_generic_params.rs +++ b/compiler/rustc_typeck/src/constrained_generic_params.rs @@ -1,5 +1,5 @@ use rustc_data_structures::fx::FxHashSet; -use rustc_middle::ty::fold::{TypeFoldable, TypeVisitor}; +use rustc_middle::ty::fold::{TypeFoldable, TypeSuperFoldable, TypeVisitor}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::source_map::Span; use std::ops::ControlFlow; diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 79d7c414bd39b..fb178cbd95e7b 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -1,7 +1,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::lang_items::LangItem; -use rustc_middle::ty::{self, Region, RegionVid, TypeFoldable}; +use rustc_middle::ty::{self, Region, RegionVid, TypeFoldable, TypeSuperFoldable}; use rustc_trait_selection::traits::auto_trait::{self, AutoTraitResult}; use std::fmt::Debug; diff --git a/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs b/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs index d86002c926efe..27678c8ba3c46 100644 --- a/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs +++ b/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs @@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::{Expr, ExprKind, PatKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, Ty, TypeFoldable, TypeVisitor}; +use rustc_middle::ty::{self, Ty, TypeFoldable, TypeSuperFoldable, TypeVisitor}; use super::LET_UNIT_VALUE;