Skip to content

Commit 5aa7c1e

Browse files
committed
Add more Copy implementations
This is mainly so that `QuantifiedWhereClause` can be put in a `rustc_middle::ty::List` (rustc's interned slice type), the other impls are added in case they're useful.
1 parent b643b21 commit 5aa7c1e

File tree

1 file changed

+121
-2
lines changed

1 file changed

+121
-2
lines changed

chalk-ir/src/lib.rs

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ pub struct Environment<I: Interner> {
7171
pub clauses: ProgramClauses<I>,
7272
}
7373

74+
impl<I: Interner> Copy for Environment<I> where I::InternedProgramClauses: Copy {}
75+
7476
impl<I: Interner> Environment<I> {
7577
/// Creates a new environment.
7678
pub fn new(interner: &I) -> Self {
@@ -99,6 +101,11 @@ pub struct InEnvironment<G: HasInterner> {
99101
pub goal: G,
100102
}
101103

104+
impl<G: HasInterner<Interner = I> + Copy, I: Interner> Copy for InEnvironment<G> where
105+
I::InternedProgramClauses: Copy
106+
{
107+
}
108+
102109
impl<G: HasInterner> InEnvironment<G> {
103110
/// Creates a new environment/goal pair.
104111
pub fn new(environment: &Environment<G::Interner>, goal: G) -> Self {
@@ -482,6 +489,15 @@ pub enum TyData<I: Interner> {
482489
InferenceVar(InferenceVar, TyKind),
483490
}
484491

492+
impl<I: Interner> Copy for TyData<I>
493+
where
494+
I::InternedLifetime: Copy,
495+
I::InternedSubstitution: Copy,
496+
I::InternedVariableKinds: Copy,
497+
I::InternedQuantifiedWhereClauses: Copy,
498+
{
499+
}
500+
485501
impl<I: Interner> TyData<I> {
486502
/// Casts the type data to a type.
487503
pub fn intern(self, interner: &I) -> Ty<I> {
@@ -770,6 +786,14 @@ pub struct DynTy<I: Interner> {
770786
pub lifetime: Lifetime<I>,
771787
}
772788

789+
impl<I: Interner> Copy for DynTy<I>
790+
where
791+
I::InternedLifetime: Copy,
792+
I::InternedQuantifiedWhereClauses: Copy,
793+
I::InternedVariableKinds: Copy,
794+
{
795+
}
796+
773797
/// A type, lifetime or constant whose value is being inferred.
774798
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
775799
pub struct InferenceVar {
@@ -817,8 +841,10 @@ pub struct Fn<I: Interner> {
817841
pub substitution: Substitution<I>,
818842
}
819843

844+
impl<I: Interner> Copy for Fn<I> where I::InternedSubstitution: Copy {}
845+
820846
/// Constants.
821-
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, HasInterner)]
847+
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, HasInterner)]
822848
pub struct Const<I: Interner> {
823849
interned: I::InternedConst,
824850
}
@@ -893,6 +919,8 @@ pub enum ConstValue<I: Interner> {
893919
Concrete(ConcreteConst<I>),
894920
}
895921

922+
impl<I: Interner> Copy for ConstValue<I> where I::InternedConcreteConst: Copy {}
923+
896924
impl<I: Interner> ConstData<I> {
897925
/// Wraps the constant data in a `Const`.
898926
pub fn intern(self, interner: &I) -> Const<I> {
@@ -902,7 +930,7 @@ impl<I: Interner> ConstData<I> {
902930

903931
/// Concrete constant, whose value is known (as opposed to
904932
/// inferred constants and placeholders).
905-
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, HasInterner)]
933+
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, HasInterner)]
906934
pub struct ConcreteConst<I: Interner> {
907935
/// The interned constant.
908936
pub interned: I::InternedConcreteConst,
@@ -1032,6 +1060,8 @@ pub struct ApplicationTy<I: Interner> {
10321060
pub substitution: Substitution<I>,
10331061
}
10341062

1063+
impl<I: Interner> Copy for ApplicationTy<I> where I::InternedSubstitution: Copy {}
1064+
10351065
impl<I: Interner> ApplicationTy<I> {
10361066
/// Create an interned type from this application type.
10371067
pub fn intern(self, interner: &I) -> Ty<I> {
@@ -1084,6 +1114,8 @@ pub enum VariableKind<I: Interner> {
10841114
Const(Ty<I>),
10851115
}
10861116

1117+
impl<I: Interner> Copy for VariableKind<I> where I::InternedType: Copy {}
1118+
10871119
impl<I: Interner> VariableKind<I> {
10881120
fn to_bound_variable(&self, interner: &I, bound_var: BoundVar) -> GenericArg<I> {
10891121
match self {
@@ -1189,6 +1221,14 @@ pub enum GenericArgData<I: Interner> {
11891221
Const(Const<I>),
11901222
}
11911223

1224+
impl<I: Interner> Copy for GenericArgData<I>
1225+
where
1226+
I::InternedType: Copy,
1227+
I::InternedLifetime: Copy,
1228+
I::InternedConst: Copy,
1229+
{
1230+
}
1231+
11921232
impl<I: Interner> GenericArgData<I> {
11931233
/// Create an interned type.
11941234
pub fn intern(self, interner: &I) -> GenericArg<I> {
@@ -1205,6 +1245,8 @@ pub struct WithKind<I: Interner, T> {
12051245
value: T,
12061246
}
12071247

1248+
impl<I: Interner, T: Copy> Copy for WithKind<I, T> where I::InternedType: Copy {}
1249+
12081250
impl<I: Interner, T> HasInterner for WithKind<I, T> {
12091251
type Interner = I;
12101252
}
@@ -1262,6 +1304,8 @@ pub enum AliasTy<I: Interner> {
12621304
Opaque(OpaqueTy<I>),
12631305
}
12641306

1307+
impl<I: Interner> Copy for AliasTy<I> where I::InternedSubstitution: Copy {}
1308+
12651309
impl<I: Interner> AliasTy<I> {
12661310
/// Create an interned type for this alias.
12671311
pub fn intern(self, interner: &I) -> Ty<I> {
@@ -1291,6 +1335,8 @@ pub struct ProjectionTy<I: Interner> {
12911335
pub substitution: Substitution<I>,
12921336
}
12931337

1338+
impl<I: Interner> Copy for ProjectionTy<I> where I::InternedSubstitution: Copy {}
1339+
12941340
/// An opaque type `opaque type T<..>: Trait = HiddenTy`.
12951341
#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)]
12961342
pub struct OpaqueTy<I: Interner> {
@@ -1300,6 +1346,8 @@ pub struct OpaqueTy<I: Interner> {
13001346
pub substitution: Substitution<I>,
13011347
}
13021348

1349+
impl<I: Interner> Copy for OpaqueTy<I> where I::InternedSubstitution: Copy {}
1350+
13031351
/// A trait reference describes the relationship between a type and a trait.
13041352
/// This can be used in two forms:
13051353
/// - `P0: Trait<P1..Pn>` (e.g. `i32: Copy`), which mentions that the type
@@ -1314,6 +1362,8 @@ pub struct TraitRef<I: Interner> {
13141362
pub substitution: Substitution<I>,
13151363
}
13161364

1365+
impl<I: Interner> Copy for TraitRef<I> where I::InternedSubstitution: Copy {}
1366+
13171367
impl<I: Interner> TraitRef<I> {
13181368
/// Gets all type parameters in this trait ref, including `Self`.
13191369
pub fn type_parameters<'a>(&'a self, interner: &'a I) -> impl Iterator<Item = Ty<I>> + 'a {
@@ -1347,6 +1397,9 @@ pub struct LifetimeOutlives<I: Interner> {
13471397
pub a: Lifetime<I>,
13481398
pub b: Lifetime<I>,
13491399
}
1400+
1401+
impl<I: Interner> Copy for LifetimeOutlives<I> where I::InternedLifetime: Copy {}
1402+
13501403
/// Where clauses that can be written by a Rust programmer.
13511404
#[derive(Clone, PartialEq, Eq, Hash, Fold, SuperVisit, HasInterner, Zip)]
13521405
pub enum WhereClause<I: Interner> {
@@ -1358,6 +1411,14 @@ pub enum WhereClause<I: Interner> {
13581411
LifetimeOutlives(LifetimeOutlives<I>),
13591412
}
13601413

1414+
impl<I: Interner> Copy for WhereClause<I>
1415+
where
1416+
I::InternedSubstitution: Copy,
1417+
I::InternedLifetime: Copy,
1418+
I::InternedType: Copy,
1419+
{
1420+
}
1421+
13611422
/// Checks whether a type or trait ref is well-formed.
13621423
#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)]
13631424
pub enum WellFormed<I: Interner> {
@@ -1389,6 +1450,13 @@ pub enum WellFormed<I: Interner> {
13891450
Ty(Ty<I>),
13901451
}
13911452

1453+
impl<I: Interner> Copy for WellFormed<I>
1454+
where
1455+
I::InternedType: Copy,
1456+
I::InternedSubstitution: Copy,
1457+
{
1458+
}
1459+
13921460
/// Checks whether a type or trait ref can be derived from the contents of the environment.
13931461
#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, HasInterner, Zip)]
13941462
pub enum FromEnv<I: Interner> {
@@ -1419,6 +1487,13 @@ pub enum FromEnv<I: Interner> {
14191487
Ty(Ty<I>),
14201488
}
14211489

1490+
impl<I: Interner> Copy for FromEnv<I>
1491+
where
1492+
I::InternedType: Copy,
1493+
I::InternedSubstitution: Copy,
1494+
{
1495+
}
1496+
14221497
/// A "domain goal" is a goal that is directly about Rust, rather than a pure
14231498
/// logical statement. As much as possible, the Chalk solver should avoid
14241499
/// decomposing this enum, and instead treat its values opaquely.
@@ -1496,6 +1571,14 @@ pub enum DomainGoal<I: Interner> {
14961571
ObjectSafe(TraitId<I>),
14971572
}
14981573

1574+
impl<I: Interner> Copy for DomainGoal<I>
1575+
where
1576+
I::InternedSubstitution: Copy,
1577+
I::InternedLifetime: Copy,
1578+
I::InternedType: Copy,
1579+
{
1580+
}
1581+
14991582
/// A where clause that can contain `forall<>` or `exists<>` quantifiers.
15001583
pub type QuantifiedWhereClause<I> = Binders<WhereClause<I>>;
15011584

@@ -1647,6 +1730,8 @@ pub struct EqGoal<I: Interner> {
16471730
pub b: GenericArg<I>,
16481731
}
16491732

1733+
impl<I: Interner> Copy for EqGoal<I> where I::InternedGenericArg: Copy {}
1734+
16501735
/// Proves that the given type alias **normalizes** to the given
16511736
/// type. A projection `T::Foo` normalizes to the type `U` if we can
16521737
/// **match it to an impl** and that impl has a `type Foo = V` where
@@ -1658,6 +1743,13 @@ pub struct Normalize<I: Interner> {
16581743
pub ty: Ty<I>,
16591744
}
16601745

1746+
impl<I: Interner> Copy for Normalize<I>
1747+
where
1748+
I::InternedSubstitution: Copy,
1749+
I::InternedType: Copy,
1750+
{
1751+
}
1752+
16611753
/// Proves **equality** between an alias and a type.
16621754
#[derive(Clone, PartialEq, Eq, Hash, Fold, Visit, Zip)]
16631755
#[allow(missing_docs)]
@@ -1666,6 +1758,13 @@ pub struct AliasEq<I: Interner> {
16661758
pub ty: Ty<I>,
16671759
}
16681760

1761+
impl<I: Interner> Copy for AliasEq<I>
1762+
where
1763+
I::InternedSubstitution: Copy,
1764+
I::InternedType: Copy,
1765+
{
1766+
}
1767+
16691768
impl<I: Interner> HasInterner for AliasEq<I> {
16701769
type Interner = I;
16711770
}
@@ -1686,6 +1785,11 @@ pub struct Binders<T: HasInterner> {
16861785
value: T,
16871786
}
16881787

1788+
impl<T: HasInterner + Copy> Copy for Binders<T> where
1789+
<T::Interner as Interner>::InternedVariableKinds: Copy
1790+
{
1791+
}
1792+
16891793
impl<T: HasInterner> HasInterner for Binders<T> {
16901794
type Interner = T::Interner;
16911795
}
@@ -2457,6 +2561,19 @@ pub enum GoalData<I: Interner> {
24572561
CannotProve(()),
24582562
}
24592563

2564+
impl<I: Interner> Copy for GoalData<I>
2565+
where
2566+
I::InternedType: Copy,
2567+
I::InternedLifetime: Copy,
2568+
I::InternedGenericArg: Copy,
2569+
I::InternedSubstitution: Copy,
2570+
I::InternedGoal: Copy,
2571+
I::InternedGoals: Copy,
2572+
I::InternedProgramClauses: Copy,
2573+
I::InternedVariableKinds: Copy,
2574+
{
2575+
}
2576+
24602577
impl<I: Interner> GoalData<I> {
24612578
/// Create an interned goal.
24622579
pub fn intern(self, interner: &I) -> Goal<I> {
@@ -2498,6 +2615,8 @@ pub enum Constraint<I: Interner> {
24982615
Outlives(Lifetime<I>, Lifetime<I>),
24992616
}
25002617

2618+
impl<I: Interner> Copy for Constraint<I> where I::InternedLifetime: Copy {}
2619+
25012620
/// A mapping of inference variables to instantiations thereof.
25022621
#[derive(Copy, Clone, PartialEq, Eq, Hash, HasInterner)]
25032622
pub struct Substitution<I: Interner> {

0 commit comments

Comments
 (0)