Skip to content

Commit

Permalink
Remove more unused Lift impls.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Sep 17, 2023
1 parent af7d3e5 commit abe2a68
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 128 deletions.
9 changes: 1 addition & 8 deletions compiler/rustc_infer/src/infer/free_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! and use that to decide when one free region outlives another, and so forth.
use rustc_data_structures::transitive_relation::TransitiveRelation;
use rustc_middle::ty::{Lift, Region, TyCtxt};
use rustc_middle::ty::{Region, TyCtxt};

/// Combines a `FreeRegionMap` and a `TyCtxt`.
///
Expand Down Expand Up @@ -101,10 +101,3 @@ impl<'tcx> FreeRegionMap<'tcx> {
result
}
}

impl<'a, 'tcx> Lift<'tcx> for FreeRegionMap<'a> {
type Lifted = FreeRegionMap<'tcx>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<FreeRegionMap<'tcx>> {
self.relation.maybe_map(|fr| tcx.lift(fr)).map(|relation| FreeRegionMap { relation })
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/infer/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl<'tcx, V> Canonical<'tcx, V> {
pub type QueryOutlivesConstraint<'tcx> =
(ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>, ConstraintCategory<'tcx>);

TrivialTypeTraversalAndLiftImpls! {
TrivialTypeTraversalImpls! {
crate::infer::canonical::Certainty,
crate::infer::canonical::CanonicalTyVarKind,
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/basic_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<'tcx> graph::WithPredecessors for BasicBlocks<'tcx> {
}
}

TrivialTypeTraversalAndLiftImpls! { Cache }
TrivialTypeTraversalImpls! { Cache }

impl<S: Encoder> Encodable<S> for Cache {
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Into<ErrorGuaranteed> for ReportedErrorInfo {
}
}

TrivialTypeTraversalAndLiftImpls! { ErrorHandled }
TrivialTypeTraversalImpls! { ErrorHandled }

pub type EvalToAllocationRawResult<'tcx> = Result<ConstAlloc<'tcx>, ErrorHandled>;
pub type EvalToConstValueResult<'tcx> = Result<ConstValue<'tcx>, ErrorHandled>;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ pub enum BindingForm<'tcx> {
RefForGuard,
}

TrivialTypeTraversalAndLiftImpls! { BindingForm<'tcx> }
TrivialTypeTraversalImpls! { BindingForm<'tcx> }

mod binding_form_impl {
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/type_foldable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_ast::InlineAsmTemplatePiece;
use super::*;
use crate::ty;

TrivialTypeTraversalAndLiftImpls! {
TrivialTypeTraversalImpls! {
BlockTailInfo,
MirPhase,
SourceInfo,
Expand Down
11 changes: 2 additions & 9 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::infer::canonical::Canonical;
use crate::mir::ConstraintCategory;
use crate::ty::abstract_const::NotConstEvaluatable;
use crate::ty::GenericArgsRef;
use crate::ty::{self, AdtKind, Ty, TyCtxt};
use crate::ty::{self, AdtKind, Ty};

use rustc_data_structures::sync::Lrc;
use rustc_errors::{Applicability, Diagnostic};
Expand Down Expand Up @@ -524,13 +524,6 @@ pub enum StatementAsExpression {
NeedsBoxing,
}

impl<'tcx> ty::Lift<'tcx> for StatementAsExpression {
type Lifted = StatementAsExpression;
fn lift_to_tcx(self, _tcx: TyCtxt<'tcx>) -> Option<StatementAsExpression> {
Some(self)
}
}

#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
#[derive(TypeVisitable, TypeFoldable)]
pub struct MatchExpressionArmCause<'tcx> {
Expand Down Expand Up @@ -736,7 +729,7 @@ pub enum BuiltinImplSource {
TupleUnsizing,
}

TrivialTypeTraversalAndLiftImpls! { BuiltinImplSource }
TrivialTypeTraversalImpls! { BuiltinImplSource }

#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
pub enum ObjectSafetyViolation {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl From<ErrorGuaranteed> for OverflowError {
}
}

TrivialTypeTraversalAndLiftImpls! { OverflowError }
TrivialTypeTraversalImpls! { OverflowError }

impl<'tcx> From<OverflowError> for SelectionError<'tcx> {
fn from(overflow_error: OverflowError) -> SelectionError<'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/abstract_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl From<ErrorGuaranteed> for NotConstEvaluatable {
}
}

TrivialTypeTraversalAndLiftImpls! { NotConstEvaluatable }
TrivialTypeTraversalImpls! { NotConstEvaluatable }

pub type BoundAbstractConst<'tcx> = Result<Option<EarlyBinder<ty::Const<'tcx>>>, ErrorGuaranteed>;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub enum BindingMode {
BindByValue(Mutability),
}

TrivialTypeTraversalAndLiftImpls! { BindingMode }
TrivialTypeTraversalImpls! { BindingMode }

impl BindingMode {
pub fn convert(BindingAnnotation(by_ref, mutbl): BindingAnnotation) -> BindingMode {
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::definitions::Definitions;
use rustc_hir::intravisit::Visitor;
use rustc_hir::lang_items::LangItem;
use rustc_hir::{Constness, HirId, Node, TraitCandidate};
use rustc_hir::{HirId, Node, TraitCandidate};
use rustc_index::IndexVec;
use rustc_macros::HashStable;
use rustc_query_system::dep_graph::DepNodeIndex;
Expand Down Expand Up @@ -1251,19 +1251,13 @@ nop_lift! {predicate; Clause<'a> => Clause<'tcx>}

nop_list_lift! {type_lists; Ty<'a> => Ty<'tcx>}
nop_list_lift! {poly_existential_predicates; PolyExistentialPredicate<'a> => PolyExistentialPredicate<'tcx>}
nop_list_lift! {clauses; Clause<'a> => Clause<'tcx>}
nop_list_lift! {canonical_var_infos; CanonicalVarInfo<'a> => CanonicalVarInfo<'tcx>}
nop_list_lift! {projs; ProjectionKind => ProjectionKind}
nop_list_lift! {bound_variable_kinds; ty::BoundVariableKind => ty::BoundVariableKind}

// This is the impl for `&'a GenericArgs<'a>`.
nop_list_lift! {args; GenericArg<'a> => GenericArg<'tcx>}

TrivialLiftImpls! {
Constness,
traits::WellFormedLoc,
ImplPolarity,
crate::mir::ReturnConstraint,
}

macro_rules! sty_debug_print {
Expand Down
121 changes: 25 additions & 96 deletions compiler/rustc_middle/src/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer};
use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor};
use crate::ty::{self, AliasTy, InferConst, Lift, Term, TermKind, Ty, TyCtxt};
use rustc_hir::def::Namespace;
use rustc_index::{Idx, IndexVec};
use rustc_target::abi::TyAndLayout;
use rustc_type_ir::{ConstKind, DebugWithInfcx, InferCtxtLike, OptWithInfcx};

use std::fmt::{self, Debug};
use std::ops::ControlFlow;
use std::rc::Rc;
use std::sync::Arc;

use super::print::PrettyPrinter;
use super::{GenericArg, GenericArgKind, Region};
Expand Down Expand Up @@ -457,21 +454,15 @@ impl<'tcx, T: DebugWithInfcx<TyCtxt<'tcx>>> DebugWithInfcx<TyCtxt<'tcx>> for ty:
// For things for which the type library provides traversal implementations
// for all Interners, we only need to provide a Lift implementation:
TrivialLiftImpls! {
(),
bool,
usize,
u16,
u32,
u64,
String,
rustc_type_ir::DebruijnIndex,
}

// For things about which the type library does not know, or does not
// provide any traversal implementations, we need to provide both a Lift
// implementation and traversal implementations (the latter only for
// TyCtxt<'_> interners).
TrivialTypeTraversalAndLiftImpls! {
(),
bool,
usize,
}

// For some things about which the type library does not know, or does not
// provide any traversal implementations, we need to provide a traversal
// implementation (only for TyCtxt<'_> interners).
TrivialTypeTraversalImpls! {
::rustc_target::abi::FieldIdx,
::rustc_target::abi::VariantIdx,
crate::middle::region::Scope,
Expand All @@ -481,14 +472,10 @@ TrivialTypeTraversalAndLiftImpls! {
::rustc_ast::NodeId,
::rustc_span::symbol::Symbol,
::rustc_hir::def::Res,
::rustc_hir::def_id::DefId,
::rustc_hir::def_id::LocalDefId,
::rustc_hir::HirId,
::rustc_hir::MatchSource,
::rustc_hir::Mutability,
::rustc_hir::Unsafety,
::rustc_target::asm::InlineAsmRegOrRegClass,
::rustc_target::spec::abi::Abi,
crate::mir::coverage::CounterId,
crate::mir::coverage::ExpressionId,
crate::mir::coverage::MappedExpressionIndex,
Expand All @@ -506,50 +493,43 @@ TrivialTypeTraversalAndLiftImpls! {
crate::ty::AssocItem,
crate::ty::AssocKind,
crate::ty::AliasKind,
crate::ty::AliasRelationDirection,
crate::ty::Placeholder<crate::ty::BoundRegion>,
crate::ty::Placeholder<crate::ty::BoundTy>,
crate::ty::Placeholder<ty::BoundVar>,
crate::ty::ClosureKind,
crate::ty::FreeRegion,
crate::ty::InferTy,
crate::ty::IntVarValue,
crate::ty::ParamConst,
crate::ty::ParamTy,
crate::ty::adjustment::PointerCoercion,
crate::ty::RegionVid,
crate::ty::UniverseIndex,
crate::ty::Variance,
::rustc_span::Span,
::rustc_span::symbol::Ident,
::rustc_errors::ErrorGuaranteed,
interpret::Scalar,
interpret::AllocId,
rustc_target::abi::Size,
ty::BoundVar,
ty::ValTree<'tcx>,
}

// For some things about which the type library does not know, or does not
// provide any traversal implementations, we need to provide a traversal
// implementation and a lift implementation (the former only for TyCtxt<'_>
// interners).
TrivialTypeTraversalAndLiftImpls! {
ty::ValTree<'tcx>,
::rustc_hir::def_id::DefId,
::rustc_hir::Mutability,
::rustc_hir::Unsafety,
::rustc_target::spec::abi::Abi,
crate::ty::AliasRelationDirection,
crate::ty::ClosureKind,
crate::ty::ParamConst,
crate::ty::ParamTy,
interpret::Scalar,
interpret::AllocId,
rustc_target::abi::Size,
}

///////////////////////////////////////////////////////////////////////////
// Lift implementations

impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>> Lift<'tcx> for (A, B) {
type Lifted = (A::Lifted, B::Lifted);
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
Some((tcx.lift(self.0)?, tcx.lift(self.1)?))
}
}

impl<'tcx, A: Lift<'tcx>, B: Lift<'tcx>, C: Lift<'tcx>> Lift<'tcx> for (A, B, C) {
type Lifted = (A::Lifted, B::Lifted, C::Lifted);
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
Some((tcx.lift(self.0)?, tcx.lift(self.1)?, tcx.lift(self.2)?))
}
}

impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
type Lifted = Option<T::Lifted>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
Expand All @@ -560,50 +540,6 @@ impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
}
}

impl<'tcx, T: Lift<'tcx>, E: Lift<'tcx>> Lift<'tcx> for Result<T, E> {
type Lifted = Result<T::Lifted, E::Lifted>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
match self {
Ok(x) => tcx.lift(x).map(Ok),
Err(e) => tcx.lift(e).map(Err),
}
}
}

impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Box<T> {
type Lifted = Box<T::Lifted>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
Some(Box::new(tcx.lift(*self)?))
}
}

impl<'tcx, T: Lift<'tcx> + Clone> Lift<'tcx> for Rc<T> {
type Lifted = Rc<T::Lifted>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
Some(Rc::new(tcx.lift(self.as_ref().clone())?))
}
}

impl<'tcx, T: Lift<'tcx> + Clone> Lift<'tcx> for Arc<T> {
type Lifted = Arc<T::Lifted>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
Some(Arc::new(tcx.lift(self.as_ref().clone())?))
}
}
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Vec<T> {
type Lifted = Vec<T::Lifted>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
self.into_iter().map(|v| tcx.lift(v)).collect()
}
}

impl<'tcx, I: Idx, T: Lift<'tcx>> Lift<'tcx> for IndexVec<I, T> {
type Lifted = IndexVec<I, T::Lifted>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
self.into_iter().map(|e| tcx.lift(e)).collect()
}
}

impl<'a, 'tcx> Lift<'tcx> for Term<'a> {
type Lifted = ty::Term<'tcx>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
Expand All @@ -616,13 +552,6 @@ impl<'a, 'tcx> Lift<'tcx> for Term<'a> {
)
}
}
impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
type Lifted = ty::ParamEnv<'tcx>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(self.caller_bounds())
.map(|caller_bounds| ty::ParamEnv::new(caller_bounds, self.reveal()))
}
}

///////////////////////////////////////////////////////////////////////////
// Traversal implementations.
Expand Down

0 comments on commit abe2a68

Please sign in to comment.