Skip to content

Commit d4e986c

Browse files
committed
derive various Lift impl instead of hand rolling them
1 parent 00fcc82 commit d4e986c

File tree

10 files changed

+32
-385
lines changed

10 files changed

+32
-385
lines changed

compiler/rustc_middle/src/mir/interpret/value.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_apfloat::{
88
use rustc_macros::HashStable;
99
use rustc_target::abi::{HasDataLayout, Size};
1010

11-
use crate::ty::{Lift, ParamEnv, ScalarInt, Ty, TyCtxt};
11+
use crate::ty::{ParamEnv, ScalarInt, Ty, TyCtxt};
1212

1313
use super::{
1414
AllocId, AllocRange, ConstAllocation, InterpResult, Pointer, PointerArithmetic, Provenance,
@@ -27,7 +27,7 @@ pub struct ConstAlloc<'tcx> {
2727
/// Represents a constant value in Rust. `Scalar` and `Slice` are optimizations for
2828
/// array length computations, enum discriminants and the pattern matching logic.
2929
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, TyEncodable, TyDecodable, Hash)]
30-
#[derive(HashStable)]
30+
#[derive(HashStable, Lift)]
3131
pub enum ConstValue<'tcx> {
3232
/// Used only for types with `layout::abi::Scalar` ABI.
3333
///
@@ -53,22 +53,6 @@ pub enum ConstValue<'tcx> {
5353
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
5454
static_assert_size!(ConstValue<'_>, 32);
5555

56-
impl<'a, 'tcx> Lift<'tcx> for ConstValue<'a> {
57-
type Lifted = ConstValue<'tcx>;
58-
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ConstValue<'tcx>> {
59-
Some(match self {
60-
ConstValue::Scalar(s) => ConstValue::Scalar(s),
61-
ConstValue::ZeroSized => ConstValue::ZeroSized,
62-
ConstValue::Slice { data, start, end } => {
63-
ConstValue::Slice { data: tcx.lift(data)?, start, end }
64-
}
65-
ConstValue::ByRef { alloc, offset } => {
66-
ConstValue::ByRef { alloc: tcx.lift(alloc)?, offset }
67-
}
68-
})
69-
}
70-
}
71-
7256
impl<'tcx> ConstValue<'tcx> {
7357
#[inline]
7458
pub fn try_to_scalar(&self) -> Option<Scalar<AllocId>> {

compiler/rustc_middle/src/mir/type_foldable.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,6 @@ impl<'tcx> TypeFoldable<'tcx> for PlaceElem<'tcx> {
192192
}
193193
}
194194

195-
impl<'tcx> TypeFoldable<'tcx> for Field {
196-
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _: &mut F) -> Result<Self, F::Error> {
197-
Ok(self)
198-
}
199-
}
200-
201195
impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal {
202196
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, _: &mut F) -> Result<Self, F::Error> {
203197
Ok(self)

compiler/rustc_middle/src/mir/type_visitable.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ impl<'tcx> TypeVisitable<'tcx> for PlaceElem<'tcx> {
149149
}
150150
}
151151

152-
impl<'tcx> TypeVisitable<'tcx> for Field {
153-
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
154-
ControlFlow::CONTINUE
155-
}
156-
}
157-
158152
impl<'tcx> TypeVisitable<'tcx> for GeneratorSavedLocal {
159153
fn visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<V::BreakTy> {
160154
ControlFlow::CONTINUE

compiler/rustc_middle/src/ty/adjustment.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub enum PointerCast {
7777
/// At some point, of course, `Box` should move out of the compiler, in which
7878
/// case this is analogous to transforming a struct. E.g., `Box<[i32; 4]>` ->
7979
/// `Box<[i32]>` is an `Adjust::Unsize` with the target `Box<[i32]>`.
80-
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
80+
#[derive(Clone, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable, Lift)]
8181
pub struct Adjustment<'tcx> {
8282
pub kind: Adjust<'tcx>,
8383
pub target: Ty<'tcx>,
@@ -89,7 +89,7 @@ impl<'tcx> Adjustment<'tcx> {
8989
}
9090
}
9191

92-
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
92+
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable, Lift)]
9393
pub enum Adjust<'tcx> {
9494
/// Go from ! to any type.
9595
NeverToAny,
@@ -108,7 +108,7 @@ pub enum Adjust<'tcx> {
108108
/// The target type is `U` in both cases, with the region and mutability
109109
/// being those shared by both the receiver and the returned reference.
110110
#[derive(Copy, Clone, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)]
111-
#[derive(TypeFoldable, TypeVisitable)]
111+
#[derive(TypeFoldable, TypeVisitable, Lift)]
112112
pub struct OverloadedDeref<'tcx> {
113113
pub region: ty::Region<'tcx>,
114114
pub mutbl: hir::Mutability,
@@ -167,7 +167,7 @@ impl From<AutoBorrowMutability> for hir::Mutability {
167167
}
168168

169169
#[derive(Copy, Clone, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)]
170-
#[derive(TypeFoldable, TypeVisitable)]
170+
#[derive(TypeFoldable, TypeVisitable, Lift)]
171171
pub enum AutoBorrow<'tcx> {
172172
/// Converts from T to &T.
173173
Ref(ty::Region<'tcx>, AutoBorrowMutability),

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,9 @@ nop_list_lift! {bound_variable_kinds; ty::BoundVariableKind => ty::BoundVariable
18201820
// This is the impl for `&'a InternalSubsts<'a>`.
18211821
nop_list_lift! {substs; GenericArg<'a> => GenericArg<'tcx>}
18221822

1823-
CloneLiftImpls! { for<'tcx> { Constness, traits::WellFormedLoc, } }
1823+
CloneLiftImpls! { for<'tcx> {
1824+
Constness, traits::WellFormedLoc, ImplPolarity, crate::mir::ReturnConstraint,
1825+
} }
18241826

18251827
pub mod tls {
18261828
use super::{ptr_eq, GlobalCtxt, TyCtxt};

compiler/rustc_middle/src/ty/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_target::spec::abi;
1414
use std::borrow::Cow;
1515
use std::fmt;
1616

17-
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable, TypeVisitable)]
17+
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable, TypeVisitable, Lift)]
1818
pub struct ExpectedFound<T> {
1919
pub expected: T,
2020
pub found: T,
@@ -31,7 +31,7 @@ impl<T> ExpectedFound<T> {
3131
}
3232

3333
// Data structures used in type unification
34-
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable)]
34+
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, Lift)]
3535
#[rustc_pass_by_value]
3636
pub enum TypeError<'tcx> {
3737
Mismatch,

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct Instance<'tcx> {
2727
}
2828

2929
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
30-
#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
30+
#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable, Lift)]
3131
pub enum InstanceDef<'tcx> {
3232
/// A user-defined callable item.
3333
///

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ impl rustc_errors::IntoDiagnosticArg for Predicate<'_> {
636636
}
637637

638638
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
639-
#[derive(HashStable, TypeFoldable, TypeVisitable)]
639+
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
640640
pub enum PredicateKind<'tcx> {
641641
/// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
642642
/// the `Self` type of the trait reference and `A`, `B`, and `C`
@@ -808,7 +808,7 @@ impl<'tcx> Predicate<'tcx> {
808808
}
809809

810810
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
811-
#[derive(HashStable, TypeFoldable, TypeVisitable)]
811+
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
812812
pub struct TraitPredicate<'tcx> {
813813
pub trait_ref: TraitRef<'tcx>,
814814

@@ -888,7 +888,7 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
888888
}
889889

890890
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
891-
#[derive(HashStable, TypeFoldable, TypeVisitable)]
891+
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
892892
pub struct OutlivesPredicate<A, B>(pub A, pub B); // `A: B`
893893
pub type RegionOutlivesPredicate<'tcx> = OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>;
894894
pub type TypeOutlivesPredicate<'tcx> = OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>;
@@ -899,7 +899,7 @@ pub type PolyTypeOutlivesPredicate<'tcx> = ty::Binder<'tcx, TypeOutlivesPredicat
899899
/// whether the `a` type is the type that we should label as "expected" when
900900
/// presenting user diagnostics.
901901
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)]
902-
#[derive(HashStable, TypeFoldable, TypeVisitable)]
902+
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
903903
pub struct SubtypePredicate<'tcx> {
904904
pub a_is_expected: bool,
905905
pub a: Ty<'tcx>,
@@ -909,7 +909,7 @@ pub type PolySubtypePredicate<'tcx> = ty::Binder<'tcx, SubtypePredicate<'tcx>>;
909909

910910
/// Encodes that we have to coerce *from* the `a` type to the `b` type.
911911
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)]
912-
#[derive(HashStable, TypeFoldable, TypeVisitable)]
912+
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
913913
pub struct CoercePredicate<'tcx> {
914914
pub a: Ty<'tcx>,
915915
pub b: Ty<'tcx>,
@@ -1058,7 +1058,7 @@ impl<'tcx> TermKind<'tcx> {
10581058
/// Form #2 eventually yields one of these `ProjectionPredicate`
10591059
/// instances to normalize the LHS.
10601060
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
1061-
#[derive(HashStable, TypeFoldable, TypeVisitable)]
1061+
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
10621062
pub struct ProjectionPredicate<'tcx> {
10631063
pub projection_ty: ProjectionTy<'tcx>,
10641064
pub term: Term<'tcx>,
@@ -1692,7 +1692,7 @@ impl<'tcx> PolyTraitRef<'tcx> {
16921692
}
16931693

16941694
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)]
1695-
#[derive(HashStable)]
1695+
#[derive(HashStable, Lift)]
16961696
pub struct ParamEnvAnd<'tcx, T> {
16971697
pub param_env: ParamEnv<'tcx>,
16981698
pub value: T,

0 commit comments

Comments
 (0)