Skip to content

Commit 27d8a57

Browse files
committed
Auto merge of rust-lang#118841 - compiler-errors:always-copy, r=jackh726
Make most `rustc_type_ir` kinds `Copy` by default 1. There's no reason why `TyKind` and `ConstKind`/`ConstData` can't be `Copy`. This allows us to avoid needing a typed arena for the two types. 2. Simplify some impls into derives.
2 parents 5b8bc56 + f3218b2 commit 27d8a57

File tree

7 files changed

+15
-60
lines changed

7 files changed

+15
-60
lines changed

compiler/rustc_middle/src/arena.rs

-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ macro_rules! arena_types {
9292
[] name_set: rustc_data_structures::unord::UnordSet<rustc_span::symbol::Symbol>,
9393
[] ordered_name_set: rustc_data_structures::fx::FxIndexSet<rustc_span::symbol::Symbol>,
9494

95-
// Interned types
96-
[] tys: rustc_type_ir::WithCachedTypeInfo<rustc_middle::ty::TyKind<'tcx>>,
97-
[] consts: rustc_type_ir::WithCachedTypeInfo<rustc_middle::ty::ConstData<'tcx>>,
98-
9995
// Note that this deliberately duplicates items in the `rustc_hir::arena`,
10096
// since we need to allocate this type on both the `rustc_hir` arena
10197
// (during lowering) and the `librustc_middle` arena (for decoding MIR)

compiler/rustc_middle/src/ty/consts.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ impl<'tcx> ConstTy<TyCtxt<'tcx>> for Const<'tcx> {
4141
}
4242

4343
/// Typed constant value.
44-
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, TyEncodable, TyDecodable)]
44+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
45+
#[derive(HashStable, TyEncodable, TyDecodable)]
4546
pub struct ConstData<'tcx> {
4647
pub ty: Ty<'tcx>,
4748
pub kind: ConstKind<'tcx>,

compiler/rustc_type_ir/src/canonical.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,7 @@ where
119119
/// a copy of the canonical value in some other inference context,
120120
/// with fresh inference variables replacing the canonical values.
121121
#[derive(derivative::Derivative)]
122-
#[derivative(
123-
Clone(bound = ""),
124-
Hash(bound = ""),
125-
Copy(bound = "CanonicalVarKind<I>: Copy"),
126-
Debug(bound = "")
127-
)]
122+
#[derivative(Clone(bound = ""), Copy(bound = ""), Hash(bound = ""), Debug(bound = ""))]
128123
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
129124
pub struct CanonicalVarInfo<I: Interner> {
130125
pub kind: CanonicalVarKind<I>,
@@ -207,7 +202,7 @@ impl<I: Interner> CanonicalVarInfo<I> {
207202
/// in the type-theory sense of the term -- i.e., a "meta" type system
208203
/// that analyzes type-like values.
209204
#[derive(derivative::Derivative)]
210-
#[derivative(Clone(bound = ""), Hash(bound = ""), Debug(bound = ""))]
205+
#[derivative(Clone(bound = ""), Copy(bound = ""), Hash(bound = ""), Debug(bound = ""))]
211206
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
212207
pub enum CanonicalVarKind<I: Interner> {
213208
/// Some kind of type inference variable.
@@ -234,15 +229,6 @@ pub enum CanonicalVarKind<I: Interner> {
234229
PlaceholderConst(I::PlaceholderConst, I::Ty),
235230
}
236231

237-
impl<I: Interner> Copy for CanonicalVarKind<I>
238-
where
239-
I::PlaceholderTy: Copy,
240-
I::PlaceholderRegion: Copy,
241-
I::PlaceholderConst: Copy,
242-
I::Ty: Copy,
243-
{
244-
}
245-
246232
impl<I: Interner> PartialEq for CanonicalVarKind<I> {
247233
fn eq(&self, other: &Self) -> bool {
248234
match (self, other) {

compiler/rustc_type_ir/src/const_kind.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use self::ConstKind::*;
1010
#[derive(derivative::Derivative)]
1111
#[derivative(
1212
Clone(bound = ""),
13+
Copy(bound = ""),
1314
PartialOrd(bound = ""),
1415
PartialOrd = "feature_allow_slow_enum",
1516
Ord(bound = ""),

compiler/rustc_type_ir/src/predicate_kind.rs

+8-27
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::Interner;
88
/// A clause is something that can appear in where bounds or be inferred
99
/// by implied bounds.
1010
#[derive(derivative::Derivative)]
11-
#[derivative(Clone(bound = ""), Hash(bound = ""))]
11+
#[derivative(Clone(bound = ""), Copy(bound = ""), Hash(bound = ""))]
1212
#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))]
1313
pub enum ClauseKind<I: Interner> {
1414
/// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
@@ -37,18 +37,6 @@ pub enum ClauseKind<I: Interner> {
3737
ConstEvaluatable(I::Const),
3838
}
3939

40-
impl<I: Interner> Copy for ClauseKind<I>
41-
where
42-
I::Ty: Copy,
43-
I::Const: Copy,
44-
I::GenericArg: Copy,
45-
I::TraitPredicate: Copy,
46-
I::ProjectionPredicate: Copy,
47-
I::TypeOutlivesPredicate: Copy,
48-
I::RegionOutlivesPredicate: Copy,
49-
{
50-
}
51-
5240
impl<I: Interner> PartialEq for ClauseKind<I> {
5341
fn eq(&self, other: &Self) -> bool {
5442
match (self, other) {
@@ -120,7 +108,13 @@ where
120108
}
121109

122110
#[derive(derivative::Derivative)]
123-
#[derivative(Clone(bound = ""), Hash(bound = ""), PartialEq(bound = ""), Eq(bound = ""))]
111+
#[derivative(
112+
Clone(bound = ""),
113+
Copy(bound = ""),
114+
Hash(bound = ""),
115+
PartialEq(bound = ""),
116+
Eq(bound = "")
117+
)]
124118
#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))]
125119
pub enum PredicateKind<I: Interner> {
126120
/// Prove a clause
@@ -169,19 +163,6 @@ pub enum PredicateKind<I: Interner> {
169163
AliasRelate(I::Term, I::Term, AliasRelationDirection),
170164
}
171165

172-
impl<I: Interner> Copy for PredicateKind<I>
173-
where
174-
I::DefId: Copy,
175-
I::Const: Copy,
176-
I::GenericArgs: Copy,
177-
I::Term: Copy,
178-
I::CoercePredicate: Copy,
179-
I::SubtypePredicate: Copy,
180-
I::NormalizesTo: Copy,
181-
ClauseKind<I>: Copy,
182-
{
183-
}
184-
185166
impl<I: Interner> TypeFoldable<I> for PredicateKind<I>
186167
where
187168
I::DefId: TypeFoldable<I>,

compiler/rustc_type_ir/src/region_kind.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ use self::RegionKind::*;
115115
#[derive(derivative::Derivative)]
116116
#[derivative(
117117
Clone(bound = ""),
118+
Copy(bound = ""),
118119
PartialOrd(bound = ""),
119120
PartialOrd = "feature_allow_slow_enum",
120121
Ord(bound = ""),
@@ -189,18 +190,6 @@ const fn regionkind_discriminant<I: Interner>(value: &RegionKind<I>) -> usize {
189190
}
190191
}
191192

192-
// This is manually implemented because a derive would require `I: Copy`
193-
impl<I: Interner> Copy for RegionKind<I>
194-
where
195-
I::EarlyParamRegion: Copy,
196-
I::BoundRegion: Copy,
197-
I::LateParamRegion: Copy,
198-
I::InferRegion: Copy,
199-
I::PlaceholderRegion: Copy,
200-
I::ErrorGuaranteed: Copy,
201-
{
202-
}
203-
204193
// This is manually implemented because a derive would require `I: PartialEq`
205194
impl<I: Interner> PartialEq for RegionKind<I> {
206195
#[inline]

compiler/rustc_type_ir/src/ty_kind.rs

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub enum AliasKind {
111111
#[derive(derivative::Derivative)]
112112
#[derivative(
113113
Clone(bound = ""),
114+
Copy(bound = ""),
114115
PartialOrd(bound = ""),
115116
PartialOrd = "feature_allow_slow_enum",
116117
Ord(bound = ""),

0 commit comments

Comments
 (0)