Skip to content

Commit 168096f

Browse files
committed
rustc_type_ir: derivative -> derive-where
1 parent 70a11c7 commit 168096f

24 files changed

+140
-425
lines changed

Diff for: Cargo.lock

+1-12
Original file line numberDiff line numberDiff line change
@@ -1046,17 +1046,6 @@ dependencies = [
10461046
"powerfmt",
10471047
]
10481048

1049-
[[package]]
1050-
name = "derivative"
1051-
version = "2.2.0"
1052-
source = "registry+https://github.com/rust-lang/crates.io-index"
1053-
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
1054-
dependencies = [
1055-
"proc-macro2",
1056-
"quote",
1057-
"syn 1.0.109",
1058-
]
1059-
10601049
[[package]]
10611050
name = "derive-where"
10621051
version = "1.2.7"
@@ -4878,7 +4867,7 @@ name = "rustc_type_ir"
48784867
version = "0.0.0"
48794868
dependencies = [
48804869
"bitflags 2.5.0",
4881-
"derivative",
4870+
"derive-where",
48824871
"indexmap",
48834872
"rustc_ast_ir",
48844873
"rustc_data_structures",

Diff for: compiler/rustc_type_ir/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
[dependencies]
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
9-
derivative = "2.2.0"
9+
derive-where = "1.2.7"
1010
indexmap = "2.0.0"
1111
rustc_ast_ir = { path = "../rustc_ast_ir", default-features = false }
1212
rustc_data_structures = { path = "../rustc_data_structures", optional = true }

Diff for: compiler/rustc_type_ir/src/binder.rs

+16-21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::hash::Hash;
33
use std::marker::PhantomData;
44
use std::ops::{ControlFlow, Deref};
55

6+
use derive_where::derive_where;
67
#[cfg(feature = "nightly")]
78
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
89
#[cfg(feature = "nightly")]
@@ -25,15 +26,12 @@ use crate::{self as ty, Interner};
2526
/// e.g., `liberate_late_bound_regions`).
2627
///
2728
/// `Decodable` and `Encodable` are implemented for `Binder<T>` using the `impl_binder_encode_decode!` macro.
28-
#[derive(derivative::Derivative)]
29-
#[derivative(
30-
Clone(bound = "T: Clone"),
31-
Copy(bound = "T: Copy"),
32-
Hash(bound = "T: Hash"),
33-
PartialEq(bound = "T: PartialEq"),
34-
Eq(bound = "T: Eq"),
35-
Debug(bound = "T: Debug")
36-
)]
29+
#[derive_where(Clone; I: Interner, T: Clone)]
30+
#[derive_where(Copy; I: Interner, T: Copy)]
31+
#[derive_where(Hash; I: Interner, T: Hash)]
32+
#[derive_where(PartialEq; I: Interner, T: PartialEq)]
33+
#[derive_where(Eq; I: Interner, T: Eq)]
34+
#[derive_where(Debug; I: Interner, T: Debug)]
3735
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
3836
pub struct Binder<I: Interner, T> {
3937
value: T,
@@ -351,21 +349,18 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> {
351349
///
352350
/// If you don't have anything to `instantiate`, you may be looking for
353351
/// [`instantiate_identity`](EarlyBinder::instantiate_identity) or [`skip_binder`](EarlyBinder::skip_binder).
354-
#[derive(derivative::Derivative)]
355-
#[derivative(
356-
Clone(bound = "T: Clone"),
357-
Copy(bound = "T: Copy"),
358-
PartialEq(bound = "T: PartialEq"),
359-
Eq(bound = "T: Eq"),
360-
Ord(bound = "T: Ord"),
361-
PartialOrd(bound = "T: Ord"),
362-
Hash(bound = "T: Hash"),
363-
Debug(bound = "T: Debug")
364-
)]
352+
#[derive_where(Clone; I: Interner, T: Clone)]
353+
#[derive_where(Copy; I: Interner, T: Copy)]
354+
#[derive_where(PartialEq; I: Interner, T: PartialEq)]
355+
#[derive_where(Eq; I: Interner, T: Eq)]
356+
#[derive_where(Ord; I: Interner, T: Ord)]
357+
#[derive_where(PartialOrd; I: Interner, T: Ord)]
358+
#[derive_where(Hash; I: Interner, T: Hash)]
359+
#[derive_where(Debug; I: Interner, T: Debug)]
365360
#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))]
366361
pub struct EarlyBinder<I: Interner, T> {
367362
value: T,
368-
#[derivative(Debug = "ignore")]
363+
#[derive_where(skip(Debug))]
369364
_tcx: PhantomData<I>,
370365
}
371366

Diff for: compiler/rustc_type_ir/src/canonical.rs

+10-29
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use derive_where::derive_where;
12
#[cfg(feature = "nightly")]
23
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
34
use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic};
@@ -11,15 +12,12 @@ use crate::{self as ty, Interner, UniverseIndex};
1112
/// A "canonicalized" type `V` is one where all free inference
1213
/// variables have been rewritten to "canonical vars". These are
1314
/// numbered starting from 0 in order of first appearance.
14-
#[derive(derivative::Derivative)]
15-
#[derivative(
16-
Clone(bound = "V: Clone"),
17-
Hash(bound = "V: Hash"),
18-
PartialEq(bound = "V: PartialEq"),
19-
Eq(bound = "V: Eq"),
20-
Debug(bound = "V: fmt::Debug"),
21-
Copy(bound = "V: Copy")
22-
)]
15+
#[derive_where(Clone; I: Interner, V: Clone)]
16+
#[derive_where(Hash; I: Interner, V: Hash)]
17+
#[derive_where(PartialEq; I: Interner, V: PartialEq)]
18+
#[derive_where(Eq; I: Interner, V: Eq)]
19+
#[derive_where(Debug; I: Interner, V: fmt::Debug)]
20+
#[derive_where(Copy; I: Interner, V: Copy)]
2321
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
2422
#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))]
2523
pub struct Canonical<I: Interner, V> {
@@ -84,15 +82,7 @@ impl<I: Interner, V: fmt::Display> fmt::Display for Canonical<I, V> {
8482
/// canonical value. This is sufficient information for code to create
8583
/// a copy of the canonical value in some other inference context,
8684
/// with fresh inference variables replacing the canonical values.
87-
#[derive(derivative::Derivative)]
88-
#[derivative(
89-
Clone(bound = ""),
90-
Copy(bound = ""),
91-
Hash(bound = ""),
92-
Debug(bound = ""),
93-
Eq(bound = ""),
94-
PartialEq(bound = "")
95-
)]
85+
#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
9686
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
9787
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
9888
pub struct CanonicalVarInfo<I: Interner> {
@@ -149,8 +139,7 @@ impl<I: Interner> CanonicalVarInfo<I> {
149139
/// Describes the "kind" of the canonical variable. This is a "kind"
150140
/// in the type-theory sense of the term -- i.e., a "meta" type system
151141
/// that analyzes type-like values.
152-
#[derive(derivative::Derivative)]
153-
#[derivative(Clone(bound = ""), Copy(bound = ""), Hash(bound = ""), Debug(bound = ""))]
142+
#[derive_where(Clone, Copy, Hash, Eq, Debug; I: Interner)]
154143
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
155144
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
156145
pub enum CanonicalVarKind<I: Interner> {
@@ -266,15 +255,7 @@ pub enum CanonicalTyVarKind {
266255
/// vectors with the original values that were replaced by canonical
267256
/// variables. You will need to supply it later to instantiate the
268257
/// canonicalized query response.
269-
#[derive(derivative::Derivative)]
270-
#[derivative(
271-
Clone(bound = ""),
272-
Copy(bound = ""),
273-
PartialEq(bound = ""),
274-
Eq(bound = ""),
275-
Hash(bound = ""),
276-
Debug(bound = "")
277-
)]
258+
#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
278259
#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))]
279260
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
280261
pub struct CanonicalVarValues<I: Interner> {

Diff for: compiler/rustc_type_ir/src/const_kind.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use derive_where::derive_where;
12
#[cfg(feature = "nightly")]
23
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
34
#[cfg(feature = "nightly")]
@@ -10,8 +11,7 @@ use crate::{self as ty, DebruijnIndex, Interner};
1011
use self::ConstKind::*;
1112

1213
/// Represents a constant in Rust.
13-
#[derive(derivative::Derivative)]
14-
#[derivative(Clone(bound = ""), Copy(bound = ""), Hash(bound = ""), Eq(bound = ""))]
14+
#[derive_where(Clone, Copy, Hash, Eq; I: Interner)]
1515
#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))]
1616
pub enum ConstKind<I: Interner> {
1717
/// A const generic parameter.
@@ -79,14 +79,7 @@ impl<I: Interner> fmt::Debug for ConstKind<I> {
7979
}
8080

8181
/// An unevaluated (potentially generic) constant used in the type-system.
82-
#[derive(derivative::Derivative)]
83-
#[derivative(
84-
Clone(bound = ""),
85-
Copy(bound = ""),
86-
Hash(bound = ""),
87-
PartialEq(bound = ""),
88-
Eq(bound = "")
89-
)]
82+
#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)]
9083
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
9184
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
9285
pub struct UnevaluatedConst<I: Interner> {

Diff for: compiler/rustc_type_ir/src/error.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use derive_where::derive_where;
12
use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic};
23

34
use crate::solve::NoSolution;
@@ -21,14 +22,7 @@ impl<T> ExpectedFound<T> {
2122
}
2223

2324
// Data structures used in type unification
24-
#[derive(derivative::Derivative)]
25-
#[derivative(
26-
Clone(bound = ""),
27-
Copy(bound = ""),
28-
PartialEq(bound = ""),
29-
Eq(bound = ""),
30-
Debug(bound = "")
31-
)]
25+
#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)]
3226
#[derive(TypeVisitable_Generic)]
3327
#[cfg_attr(feature = "nightly", rustc_pass_by_value)]
3428
pub enum TypeError<I: Interner> {

Diff for: compiler/rustc_type_ir/src/generic_arg.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
1+
use derive_where::derive_where;
12
#[cfg(feature = "nightly")]
23
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
34

45
use crate::Interner;
56

6-
#[derive(derivative::Derivative)]
7-
#[derivative(
8-
Clone(bound = ""),
9-
Copy(bound = ""),
10-
Debug(bound = ""),
11-
Eq(bound = ""),
12-
PartialEq(bound = "")
13-
)]
7+
#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)]
148
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
159
pub enum GenericArgKind<I: Interner> {
1610
Lifetime(I::Region),
1711
Type(I::Ty),
1812
Const(I::Const),
1913
}
2014

21-
#[derive(derivative::Derivative)]
22-
#[derivative(
23-
Clone(bound = ""),
24-
Copy(bound = ""),
25-
Debug(bound = ""),
26-
Eq(bound = ""),
27-
PartialEq(bound = "")
28-
)]
15+
#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)]
2916
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
3017
pub enum TermKind<I: Interner> {
3118
Ty(I::Ty),

Diff for: compiler/rustc_type_ir/src/opaque_ty.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1+
use derive_where::derive_where;
12
#[cfg(feature = "nightly")]
23
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
34
use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic};
45

56
use crate::inherent::*;
67
use crate::{self as ty, Interner};
78

8-
#[derive(derivative::Derivative)]
9-
#[derivative(
10-
Clone(bound = ""),
11-
Hash(bound = ""),
12-
PartialEq(bound = ""),
13-
Eq(bound = ""),
14-
Debug(bound = ""),
15-
Copy(bound = "")
16-
)]
9+
#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)]
1710
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
1811
#[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))]
1912
pub struct OpaqueTypeKey<I: Interner> {

Diff for: compiler/rustc_type_ir/src/outlives.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
//! refers to rules defined in RFC 1214 (`OutlivesFooBar`), so see that
33
//! RFC for reference.
44
5+
use derive_where::derive_where;
56
use smallvec::{smallvec, SmallVec};
67

78
use crate::data_structures::SsoHashSet;
89
use crate::inherent::*;
910
use crate::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt as _, TypeVisitor};
1011
use crate::{self as ty, Interner};
1112

12-
#[derive(derivative::Derivative)]
13-
#[derivative(Debug(bound = ""))]
13+
#[derive_where(Debug; I: Interner)]
1414
pub enum Component<I: Interner> {
1515
Region(I::Region),
1616
Param(I::ParamTy),

0 commit comments

Comments
 (0)