Rollup merge of #110838 - nnethercote:more-Folder-Visitable-cleanups, r=lcnr
More `Typefoldable`/`TypeVisitable` cleanups r? ``@lcnr``
This commit is contained in:
commit
57e9a4be48
13 changed files with 19 additions and 83 deletions
|
@ -20,7 +20,7 @@ pub struct MismatchedProjectionTypes<'tcx> {
|
||||||
pub err: ty::error::TypeError<'tcx>,
|
pub err: ty::error::TypeError<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, TypeFoldable, TypeVisitable)]
|
#[derive(Clone)]
|
||||||
pub struct Normalized<'tcx, T> {
|
pub struct Normalized<'tcx, T> {
|
||||||
pub value: T,
|
pub value: T,
|
||||||
pub obligations: Vec<PredicateObligation<'tcx>>,
|
pub obligations: Vec<PredicateObligation<'tcx>>,
|
||||||
|
|
|
@ -66,7 +66,6 @@ pub struct Place<'tcx> {
|
||||||
///
|
///
|
||||||
/// This is an HIR version of [`rustc_middle::mir::Place`].
|
/// This is an HIR version of [`rustc_middle::mir::Place`].
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
|
||||||
#[derive(TypeFoldable, TypeVisitable)]
|
|
||||||
pub struct PlaceWithHirId<'tcx> {
|
pub struct PlaceWithHirId<'tcx> {
|
||||||
/// `HirId` of the expression or pattern producing this value.
|
/// `HirId` of the expression or pattern producing this value.
|
||||||
pub hir_id: HirId,
|
pub hir_id: HirId,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::mir::visit::MirVisitable;
|
||||||
use crate::ty::codec::{TyDecoder, TyEncoder};
|
use crate::ty::codec::{TyDecoder, TyEncoder};
|
||||||
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable};
|
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable};
|
||||||
use crate::ty::print::{FmtPrinter, Printer};
|
use crate::ty::print::{FmtPrinter, Printer};
|
||||||
use crate::ty::visit::{TypeVisitable, TypeVisitableExt, TypeVisitor};
|
use crate::ty::visit::TypeVisitableExt;
|
||||||
use crate::ty::{self, List, Ty, TyCtxt};
|
use crate::ty::{self, List, Ty, TyCtxt};
|
||||||
use crate::ty::{AdtDef, InstanceDef, ScalarInt, UserTypeAnnotationIndex};
|
use crate::ty::{AdtDef, InstanceDef, ScalarInt, UserTypeAnnotationIndex};
|
||||||
use crate::ty::{GenericArg, InternalSubsts, SubstsRef};
|
use crate::ty::{GenericArg, InternalSubsts, SubstsRef};
|
||||||
|
@ -36,7 +36,7 @@ use either::Either;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fmt::{self, Debug, Display, Formatter, Write};
|
use std::fmt::{self, Debug, Display, Formatter, Write};
|
||||||
use std::ops::{ControlFlow, Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
use std::{iter, mem};
|
use std::{iter, mem};
|
||||||
|
|
||||||
pub use self::query::*;
|
pub use self::query::*;
|
||||||
|
@ -2722,6 +2722,7 @@ impl<'tcx> UserTypeProjections {
|
||||||
/// `field[0]` (aka `.0`), indicating that the type of `s` is
|
/// `field[0]` (aka `.0`), indicating that the type of `s` is
|
||||||
/// determined by finding the type of the `.0` field from `T`.
|
/// determined by finding the type of the `.0` field from `T`.
|
||||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
|
#[derive(Clone, Debug, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
|
||||||
|
#[derive(TypeFoldable, TypeVisitable)]
|
||||||
pub struct UserTypeProjection {
|
pub struct UserTypeProjection {
|
||||||
pub base: UserTypeAnnotationIndex,
|
pub base: UserTypeAnnotationIndex,
|
||||||
pub projs: Vec<ProjectionKind>,
|
pub projs: Vec<ProjectionKind>,
|
||||||
|
@ -2765,28 +2766,6 @@ impl UserTypeProjection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for UserTypeProjection {
|
|
||||||
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
|
|
||||||
self,
|
|
||||||
folder: &mut F,
|
|
||||||
) -> Result<Self, F::Error> {
|
|
||||||
Ok(UserTypeProjection {
|
|
||||||
base: self.base.try_fold_with(folder)?,
|
|
||||||
projs: self.projs.try_fold_with(folder)?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for UserTypeProjection {
|
|
||||||
fn visit_with<Vs: TypeVisitor<TyCtxt<'tcx>>>(
|
|
||||||
&self,
|
|
||||||
visitor: &mut Vs,
|
|
||||||
) -> ControlFlow<Vs::BreakTy> {
|
|
||||||
self.base.visit_with(visitor)
|
|
||||||
// Note: there's nothing in `self.proj` to visit.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rustc_index::newtype_index! {
|
rustc_index::newtype_index! {
|
||||||
#[derive(HashStable)]
|
#[derive(HashStable)]
|
||||||
#[debug_format = "promoted[{}]"]
|
#[debug_format = "promoted[{}]"]
|
||||||
|
|
|
@ -234,7 +234,6 @@ pub enum StmtKind<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
|
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
|
||||||
#[derive(TypeFoldable, TypeVisitable)]
|
|
||||||
pub struct LocalVarId(pub hir::HirId);
|
pub struct LocalVarId(pub hir::HirId);
|
||||||
|
|
||||||
/// A THIR expression.
|
/// A THIR expression.
|
||||||
|
|
|
@ -569,7 +569,7 @@ pub struct DerivedObligationCause<'tcx> {
|
||||||
pub parent_code: InternedObligationCauseCode<'tcx>,
|
pub parent_code: InternedObligationCauseCode<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, TypeFoldable, TypeVisitable, Lift)]
|
#[derive(Clone, Debug, TypeVisitable, Lift)]
|
||||||
pub enum SelectionError<'tcx> {
|
pub enum SelectionError<'tcx> {
|
||||||
/// The trait is not implemented.
|
/// The trait is not implemented.
|
||||||
Unimplemented,
|
Unimplemented,
|
||||||
|
|
|
@ -103,7 +103,7 @@ pub type EvaluationCache<'tcx> = Cache<
|
||||||
/// required for associated types to work in default impls, as the bounds
|
/// required for associated types to work in default impls, as the bounds
|
||||||
/// are visible both as projection bounds and as where-clauses from the
|
/// are visible both as projection bounds and as where-clauses from the
|
||||||
/// parameter environment.
|
/// parameter environment.
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, TypeFoldable, TypeVisitable)]
|
#[derive(PartialEq, Eq, Debug, Clone, TypeVisitable)]
|
||||||
pub enum SelectionCandidate<'tcx> {
|
pub enum SelectionCandidate<'tcx> {
|
||||||
/// A builtin implementation for some specific traits, used in cases
|
/// A builtin implementation for some specific traits, used in cases
|
||||||
/// where we cannot rely an ordinary library implementations.
|
/// where we cannot rely an ordinary library implementations.
|
||||||
|
|
|
@ -120,7 +120,7 @@ impl<'tcx> std::ops::Deref for ExternalConstraints<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Additional constraints returned on success.
|
/// Additional constraints returned on success.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Hash, Default, TypeFoldable, TypeVisitable)]
|
#[derive(Debug, PartialEq, Eq, Clone, Hash, Default)]
|
||||||
pub struct ExternalConstraintsData<'tcx> {
|
pub struct ExternalConstraintsData<'tcx> {
|
||||||
// FIXME: implement this.
|
// FIXME: implement this.
|
||||||
pub region_constraints: QueryRegionConstraints<'tcx>,
|
pub region_constraints: QueryRegionConstraints<'tcx>,
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl<T> ExpectedFound<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data structures used in type unification
|
// Data structures used in type unification
|
||||||
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, Lift, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, TypeVisitable, Lift, PartialEq, Eq)]
|
||||||
#[rustc_pass_by_value]
|
#[rustc_pass_by_value]
|
||||||
pub enum TypeError<'tcx> {
|
pub enum TypeError<'tcx> {
|
||||||
Mismatch,
|
Mismatch,
|
||||||
|
|
|
@ -2690,7 +2690,7 @@ impl<'tcx> ty::PolyTraitPredicate<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, TypeFoldable, TypeVisitable, Lift)]
|
#[derive(Debug, Copy, Clone, Lift)]
|
||||||
pub struct PrintClosureAsImpl<'tcx> {
|
pub struct PrintClosureAsImpl<'tcx> {
|
||||||
pub closure: ty::ClosureSubsts<'tcx>,
|
pub closure: ty::ClosureSubsts<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
//! to help with the tedium.
|
//! to help with the tedium.
|
||||||
|
|
||||||
use crate::mir::interpret;
|
use crate::mir::interpret;
|
||||||
use crate::mir::ProjectionKind;
|
|
||||||
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
|
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable};
|
||||||
use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer};
|
use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer};
|
||||||
use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
|
use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
|
||||||
|
@ -373,16 +372,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Traversal implementations.
|
// Traversal implementations.
|
||||||
|
|
||||||
/// AdtDefs are basically the same as a DefId.
|
|
||||||
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ty::AdtDef<'tcx> {
|
|
||||||
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
|
|
||||||
self,
|
|
||||||
_folder: &mut F,
|
|
||||||
) -> Result<Self, F::Error> {
|
|
||||||
Ok(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::AdtDef<'tcx> {
|
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::AdtDef<'tcx> {
|
||||||
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(
|
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(
|
||||||
&self,
|
&self,
|
||||||
|
@ -445,15 +434,6 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<ty::Const<'tcx>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx ty::List<ProjectionKind> {
|
|
||||||
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
|
|
||||||
self,
|
|
||||||
folder: &mut F,
|
|
||||||
) -> Result<Self, F::Error> {
|
|
||||||
ty::util::fold_list(self, folder, |tcx, v| tcx.mk_projs(v))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
|
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
|
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -631,7 +631,7 @@ impl<'tcx> UpvarSubsts<'tcx> {
|
||||||
/// type of the constant. The reason that `R` is represented as an extra type parameter
|
/// type of the constant. The reason that `R` is represented as an extra type parameter
|
||||||
/// is the same reason that [`ClosureSubsts`] have `CS` and `U` as type parameters:
|
/// is the same reason that [`ClosureSubsts`] have `CS` and `U` as type parameters:
|
||||||
/// inline const can reference lifetimes that are internal to the creating function.
|
/// inline const can reference lifetimes that are internal to the creating function.
|
||||||
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct InlineConstSubsts<'tcx> {
|
pub struct InlineConstSubsts<'tcx> {
|
||||||
/// Generic parameters from the enclosing item,
|
/// Generic parameters from the enclosing item,
|
||||||
/// concatenated with the inferred type of the constant.
|
/// concatenated with the inferred type of the constant.
|
||||||
|
|
|
@ -62,7 +62,7 @@ mod rustc {
|
||||||
|
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_macros::{TypeFoldable, TypeVisitable};
|
use rustc_macros::TypeVisitable;
|
||||||
use rustc_middle::traits::ObligationCause;
|
use rustc_middle::traits::ObligationCause;
|
||||||
use rustc_middle::ty::Const;
|
use rustc_middle::ty::Const;
|
||||||
use rustc_middle::ty::ParamEnv;
|
use rustc_middle::ty::ParamEnv;
|
||||||
|
@ -70,7 +70,7 @@ mod rustc {
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
|
||||||
/// The source and destination types of a transmutation.
|
/// The source and destination types of a transmutation.
|
||||||
#[derive(TypeFoldable, TypeVisitable, Debug, Clone, Copy)]
|
#[derive(TypeVisitable, Debug, Clone, Copy)]
|
||||||
pub struct Types<'tcx> {
|
pub struct Types<'tcx> {
|
||||||
/// The source type.
|
/// The source type.
|
||||||
pub src: Ty<'tcx>,
|
pub src: Ty<'tcx>,
|
||||||
|
|
|
@ -6,11 +6,10 @@ use crate::fold::{FallibleTypeFolder, TypeFoldable};
|
||||||
use crate::visit::{TypeVisitable, TypeVisitor};
|
use crate::visit::{TypeVisitable, TypeVisitor};
|
||||||
use crate::Interner;
|
use crate::Interner;
|
||||||
use rustc_data_structures::functor::IdFunctor;
|
use rustc_data_structures::functor::IdFunctor;
|
||||||
|
use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_index::{Idx, IndexVec};
|
use rustc_index::{Idx, IndexVec};
|
||||||
|
|
||||||
use std::ops::ControlFlow;
|
use std::ops::ControlFlow;
|
||||||
use std::rc::Rc;
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Atomic structs
|
// Atomic structs
|
||||||
|
@ -106,25 +105,13 @@ impl<I: Interner, T: TypeVisitable<I>, E: TypeVisitable<I>> TypeVisitable<I> for
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Rc<T> {
|
impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Lrc<T> {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||||
self.try_map_id(|value| value.try_fold_with(folder))
|
self.try_map_id(|value| value.try_fold_with(folder))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Rc<T> {
|
impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Lrc<T> {
|
||||||
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
|
||||||
(**self).visit_with(visitor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Arc<T> {
|
|
||||||
fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
|
||||||
self.try_map_id(|value| value.try_fold_with(folder))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Arc<T> {
|
|
||||||
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||||
(**self).visit_with(visitor)
|
(**self).visit_with(visitor)
|
||||||
}
|
}
|
||||||
|
@ -154,24 +141,16 @@ impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Vec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `TypeFoldable` isn't impl'd for `&[T]`. It doesn't make sense in the general
|
||||||
|
// case, because we can't return a new slice. But note that there are a couple
|
||||||
|
// of trivial impls of `TypeFoldable` for specific slice types elsewhere.
|
||||||
|
|
||||||
impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for &[T] {
|
impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for &[T] {
|
||||||
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
||||||
self.iter().try_for_each(|t| t.visit_with(visitor))
|
self.iter().try_for_each(|t| t.visit_with(visitor))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I: Interner, T: TypeFoldable<I>> TypeFoldable<I> for Box<[T]> {
|
|
||||||
fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
|
||||||
self.try_map_id(|t| t.try_fold_with(folder))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Box<[T]> {
|
|
||||||
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
|
||||||
self.iter().try_for_each(|t| t.visit_with(visitor))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I: Interner, T: TypeFoldable<I>, Ix: Idx> TypeFoldable<I> for IndexVec<Ix, T> {
|
impl<I: Interner, T: TypeFoldable<I>, Ix: Idx> TypeFoldable<I> for IndexVec<Ix, T> {
|
||||||
fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
fn try_fold_with<F: FallibleTypeFolder<I>>(self, folder: &mut F) -> Result<Self, F::Error> {
|
||||||
self.try_map_id(|x| x.try_fold_with(folder))
|
self.try_map_id(|x| x.try_fold_with(folder))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue