Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 3 pull requests #110401

Merged
merged 7 commits into from
Apr 16, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove TypeSuper{Foldable,Visitable} impls for Region.
These traits exist so that folders/visitors can recurse into types of
interest: binders, types, regions, predicates, and consts. But `Region`
is non-recursive and cannot contain other types of interest, so its
methods in these traits are trivial.

This commit inlines and removes those trivial methods.
nnethercote committed Apr 15, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 4460a1dc28a10cd74a6e5636d6e2cd8c8f06ba4b
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/variance/mod.rs
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
if let ty::RegionKind::ReEarlyBound(ebr) = r.kind() {
self.variances[ebr.index as usize] = ty::Invariant;
}
r.super_visit_with(self)
ControlFlow::Continue(())
}

#[instrument(level = "trace", skip(self), ret)]
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ use rustc_hir::intravisit::Visitor;
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::error::ExpectedFound;
use rustc_middle::ty::print::RegionHighlightMode;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor};
use rustc_span::Span;

use std::ops::ControlFlow;
@@ -81,7 +81,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
self.highlight.highlighting_region(r, self.counter);
self.counter += 1;
}
r.super_visit_with(self)
ControlFlow::Continue(())
}
}

3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/ty/fold.rs
Original file line number Diff line number Diff line change
@@ -37,7 +37,8 @@ where
}

fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
let r = r.super_fold_with(self);
// This one is a little different, because `super_fold_with` is not
// implemented on non-recursive `Region`.
(self.lt_op)(r)
}

2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
@@ -2518,7 +2518,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
self.used_region_names.insert(name);
}

r.super_visit_with(self)
ControlFlow::Continue(())
}

// We collect types in order to prevent really large types from compiling for
18 changes: 0 additions & 18 deletions compiler/rustc_middle/src/ty/structural_impls.rs
Original file line number Diff line number Diff line change
@@ -583,24 +583,6 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::Region<'tcx> {
}
}

impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Region<'tcx> {
fn try_super_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
self,
_folder: &mut F,
) -> Result<Self, F::Error> {
Ok(self)
}
}

impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Region<'tcx> {
fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(
&self,
_visitor: &mut V,
) -> ControlFlow<V::BreakTy> {
ControlFlow::Continue(())
}
}

impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ty::Predicate<'tcx> {
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
self,
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/visit.rs
Original file line number Diff line number Diff line change
@@ -364,7 +364,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ValidateBoundVars<'tcx> {
_ => (),
};

r.super_visit_with(self)
ControlFlow::Continue(())
}
}

2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -450,7 +450,7 @@ fn is_impossible_method(tcx: TyCtxt<'_>, (impl_def_id, trait_item_def_id): (DefI
{
return ControlFlow::Break(());
}
r.super_visit_with(self)
ControlFlow::Continue(())
}
fn visit_const(&mut self, ct: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::ConstKind::Param(param) = ct.kind()
8 changes: 4 additions & 4 deletions compiler/rustc_traits/src/chalk/lowering.rs
Original file line number Diff line number Diff line change
@@ -998,7 +998,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for BoundVarsCollector<'tcx> {
_ => (),
};

r.super_visit_with(self)
ControlFlow::Continue(())
}
}

@@ -1048,7 +1048,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for NamedBoundVarSubstitutor<'a, 'tcx> {
_ => (),
};

r.super_fold_with(self)
r
}
}

@@ -1142,7 +1142,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ParamsSubstitutor<'tcx> {
}
},

_ => r.super_fold_with(self),
_ => r,
}
}
}
@@ -1223,6 +1223,6 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for PlaceholdersCollector {
_ => (),
};

r.super_visit_with(self)
ControlFlow::Continue(())
}
}
37 changes: 18 additions & 19 deletions compiler/rustc_type_ir/src/fold.rs
Original file line number Diff line number Diff line change
@@ -16,8 +16,10 @@
//! - Types of interest, for which the methods delegate to the folder.
//! - All other types, including generic containers like `Vec` and `Option`.
//! It defines a "skeleton" of how they should be folded.
//! - `TypeSuperFoldable`. This is implemented only for each type of interest,
//! and defines the folding "skeleton" for these types.
//! - `TypeSuperFoldable`. This is implemented only for recursive types of
//! interest, and defines the folding "skeleton" for these types. (This
//! excludes `Region` because it is non-recursive, i.e. it never contains
//! other types of interest.)
//! - `TypeFolder`/`FallibleTypeFolder`. One of these is implemented for each
//! folder. This defines how types of interest are folded.
//!
@@ -72,9 +74,9 @@ pub trait TypeFoldable<I: Interner>: TypeVisitable<I> {

// This trait is implemented for types of interest.
pub trait TypeSuperFoldable<I: Interner>: TypeFoldable<I> {
/// 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.
/// Provides a default fold for a recursive 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)`.
@@ -118,11 +120,11 @@ pub trait TypeFolder<I: Interner>: FallibleTypeFolder<I, Error = !> {
t.super_fold_with(self)
}

fn fold_region(&mut self, r: I::Region) -> I::Region
where
I::Region: TypeSuperFoldable<I>,
{
r.super_fold_with(self)
// The default region folder is a no-op because `Region` is non-recursive
// and has no `super_visit_with` method to call. That also explains the
// lack of `I::Region: TypeSuperFoldable<I>` bound on this method.
fn fold_region(&mut self, r: I::Region) -> I::Region {
r
}

fn fold_const(&mut self, c: I::Const) -> I::Const
@@ -167,11 +169,11 @@ pub trait FallibleTypeFolder<I: Interner>: Sized {
t.try_super_fold_with(self)
}

fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, Self::Error>
where
I::Region: TypeSuperFoldable<I>,
{
r.try_super_fold_with(self)
// The default region folder is a no-op because `Region` is non-recursive
// and has no `super_visit_with` method to call. That also explains the
// lack of `I::Region: TypeSuperFoldable<I>` bound on this method.
fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, Self::Error> {
Ok(r)
}

fn try_fold_const(&mut self, c: I::Const) -> Result<I::Const, Self::Error>
@@ -216,10 +218,7 @@ where
Ok(self.fold_ty(t))
}

fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, !>
where
I::Region: TypeSuperFoldable<I>,
{
fn try_fold_region(&mut self, r: I::Region) -> Result<I::Region, !> {
Ok(self.fold_region(r))
}

28 changes: 16 additions & 12 deletions compiler/rustc_type_ir/src/visit.rs
Original file line number Diff line number Diff line change
@@ -13,8 +13,11 @@
//! - Types of interest, for which the methods delegate to the visitor.
//! - All other types, including generic containers like `Vec` and `Option`.
//! It defines a "skeleton" of how they should be visited.
//! - `TypeSuperVisitable`. This is implemented only for each type of interest,
//! and defines the visiting "skeleton" for these types.
//! - `TypeSuperVisitable`. This is implemented only for recursive types of
//! interest, and defines the visiting "skeleton" for these types. (This
//! excludes `Region` because it is non-recursive, i.e. it never contains
//! other types of interest.)
//!
//! - `TypeVisitor`. This is implemented for each visitor. This defines how
//! types of interest are visited.
//!
@@ -62,12 +65,13 @@ pub trait TypeVisitable<I: Interner>: fmt::Debug + Clone {
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy>;
}

// This trait is implemented for types of interest.
pub trait TypeSuperVisitable<I: Interner>: TypeVisitable<I> {
/// 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
/// Provides a default visit for a recursive 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<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy>;
}
@@ -92,11 +96,11 @@ pub trait TypeVisitor<I: Interner>: Sized {
t.super_visit_with(self)
}

fn visit_region(&mut self, r: I::Region) -> ControlFlow<Self::BreakTy>
where
I::Region: TypeSuperVisitable<I>,
{
r.super_visit_with(self)
// The default region visitor is a no-op because `Region` is non-recursive
// and has no `super_visit_with` method to call. That also explains the
// lack of `I::Region: TypeSuperVisitable<I>` bound.
fn visit_region(&mut self, _r: I::Region) -> ControlFlow<Self::BreakTy> {
ControlFlow::Continue(())
}

fn visit_const(&mut self, c: I::Const) -> ControlFlow<Self::BreakTy>
11 changes: 5 additions & 6 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
@@ -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, TypeSuperFoldable};
use rustc_middle::ty::{self, Region, RegionVid, TypeFoldable};
use rustc_trait_selection::traits::auto_trait::{self, AutoTraitResult};
use thin_vec::ThinVec;

@@ -740,10 +740,9 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for RegionReplacer<'a, 'tcx> {
}

fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
(match *r {
ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned(),
_ => None,
})
.unwrap_or_else(|| r.super_fold_with(self))
match *r {
ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned().unwrap_or(r),
_ => r,
}
}
}