Skip to content

Commit 2f26b2a

Browse files
committed
Auto merge of rust-lang#127042 - GrigorenkoPV:derivative, r=compiler-errors
Switch from `derivative` to `derive-where` This is a part of the effort to get rid of `syn 1.*` in compiler's dependencies: rust-lang#109302 Derivative has not been maintained in nearly 3 years[^1]. It also depends on `syn 1.*`. This PR replaces `derivative` with `derive-where`[^2], a not dead alternative, which uses `syn 2.*`. A couple of `Debug` formats have changed around the skipped fields[^3], but I doubt this is an issue. [^1]: mcarton/rust-derivative#117 [^2]: https://lib.rs/crates/derive-where [^3]: See the changes in `tests/ui`
2 parents 7120fda + 59f88d3 commit 2f26b2a

35 files changed

+192
-462
lines changed

Diff for: Cargo.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -986,14 +986,14 @@ dependencies = [
986986
]
987987

988988
[[package]]
989-
name = "derivative"
990-
version = "2.2.0"
989+
name = "derive-where"
990+
version = "1.2.7"
991991
source = "registry+https://github.com/rust-lang/crates.io-index"
992-
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
992+
checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25"
993993
dependencies = [
994994
"proc-macro2",
995995
"quote",
996-
"syn 1.0.109",
996+
"syn 2.0.67",
997997
]
998998

999999
[[package]]
@@ -4248,7 +4248,7 @@ name = "rustc_middle"
42484248
version = "0.0.0"
42494249
dependencies = [
42504250
"bitflags 2.5.0",
4251-
"derivative",
4251+
"derive-where",
42524252
"either",
42534253
"field-offset",
42544254
"gsgdt",
@@ -4378,7 +4378,7 @@ name = "rustc_next_trait_solver"
43784378
version = "0.0.0"
43794379
dependencies = [
43804380
"bitflags 2.5.0",
4381-
"derivative",
4381+
"derive-where",
43824382
"rustc_ast_ir",
43834383
"rustc_data_structures",
43844384
"rustc_index",
@@ -4628,7 +4628,7 @@ dependencies = [
46284628
name = "rustc_span"
46294629
version = "0.0.0"
46304630
dependencies = [
4631-
"derivative",
4631+
"derive-where",
46324632
"indexmap",
46334633
"itoa",
46344634
"md-5",
@@ -4768,7 +4768,7 @@ name = "rustc_type_ir"
47684768
version = "0.0.0"
47694769
dependencies = [
47704770
"bitflags 2.5.0",
4771-
"derivative",
4771+
"derive-where",
47724772
"indexmap",
47734773
"rustc_ast_ir",
47744774
"rustc_data_structures",

Diff for: compiler/rustc_middle/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
either = "1.5.0"
1111
field-offset = "0.3.5"
1212
gsgdt = "0.1.2"

Diff for: compiler/rustc_middle/src/mir/query.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::mir;
44
use crate::ty::{self, CoroutineArgsExt, OpaqueHiddenType, Ty, TyCtxt};
5+
use derive_where::derive_where;
56
use rustc_data_structures::fx::FxIndexMap;
67
use rustc_errors::ErrorGuaranteed;
78
use rustc_hir::def_id::LocalDefId;
@@ -224,13 +225,7 @@ rustc_data_structures::static_assert_size!(ConstraintCategory<'_>, 16);
224225
/// See also `rustc_const_eval::borrow_check::constraints`.
225226
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
226227
#[derive(TyEncodable, TyDecodable, HashStable, TypeVisitable, TypeFoldable)]
227-
#[derive(derivative::Derivative)]
228-
#[derivative(
229-
PartialOrd,
230-
Ord,
231-
PartialOrd = "feature_allow_slow_enum",
232-
Ord = "feature_allow_slow_enum"
233-
)]
228+
#[derive_where(PartialOrd, Ord)]
234229
pub enum ConstraintCategory<'tcx> {
235230
Return(ReturnConstraint),
236231
Yield,
@@ -240,7 +235,7 @@ pub enum ConstraintCategory<'tcx> {
240235
Cast {
241236
/// Whether this is an unsizing cast and if yes, this contains the target type.
242237
/// Region variables are erased to ReErased.
243-
#[derivative(PartialOrd = "ignore", Ord = "ignore")]
238+
#[derive_where(skip)]
244239
unsize_to: Option<Ty<'tcx>>,
245240
},
246241

@@ -250,7 +245,7 @@ pub enum ConstraintCategory<'tcx> {
250245
ClosureBounds,
251246

252247
/// Contains the function type if available.
253-
CallArgument(#[derivative(PartialOrd = "ignore", Ord = "ignore")] Option<Ty<'tcx>>),
248+
CallArgument(#[derive_where(skip)] Option<Ty<'tcx>>),
254249
CopyBound,
255250
SizedBound,
256251
Assignment,

Diff for: compiler/rustc_next_trait_solver/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
rustc_ast_ir = { path = "../rustc_ast_ir", default-features = false }
1111
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
1212
rustc_index = { path = "../rustc_index", default-features = false }

Diff for: compiler/rustc_next_trait_solver/src/coherence.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fmt::Debug;
22
use std::ops::ControlFlow;
33

4+
use derive_where::derive_where;
45
use rustc_type_ir::inherent::*;
56
use rustc_type_ir::visit::{TypeVisitable, TypeVisitableExt, TypeVisitor};
67
use rustc_type_ir::{self as ty, InferCtxtLike, Interner};
@@ -108,15 +109,13 @@ impl From<bool> for IsFirstInputType {
108109
}
109110
}
110111

111-
#[derive(derivative::Derivative)]
112-
#[derivative(Debug(bound = "T: Debug"))]
112+
#[derive_where(Debug; I: Interner, T: Debug)]
113113
pub enum OrphanCheckErr<I: Interner, T> {
114114
NonLocalInputType(Vec<(I::Ty, IsFirstInputType)>),
115115
UncoveredTyParams(UncoveredTyParams<I, T>),
116116
}
117117

118-
#[derive(derivative::Derivative)]
119-
#[derivative(Debug(bound = "T: Debug"))]
118+
#[derive_where(Debug; I: Interner, T: Debug)]
120119
pub struct UncoveredTyParams<I: Interner, T> {
121120
pub uncovered: T,
122121
pub local_ty: Option<I::Ty>,

Diff for: compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
pub(super) mod structural_traits;
44

5+
use derive_where::derive_where;
56
use rustc_type_ir::elaborate;
67
use rustc_type_ir::fold::TypeFoldable;
78
use rustc_type_ir::inherent::*;
@@ -21,8 +22,7 @@ use crate::solve::{
2122
///
2223
/// It consists of both the `source`, which describes how that goal would be proven,
2324
/// and the `result` when using the given `source`.
24-
#[derive(derivative::Derivative)]
25-
#[derivative(Debug(bound = ""), Clone(bound = ""))]
25+
#[derive_where(Clone, Debug; I: Interner)]
2626
pub(super) struct Candidate<I: Interner> {
2727
pub(super) source: CandidateSource<I>,
2828
pub(super) result: CanonicalResponse<I>,

Diff for: compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Code which is used by built-in goals that match "structurally", such a auto
22
//! traits, `Copy`/`Clone`.
33
4+
use derive_where::derive_where;
45
use rustc_ast_ir::{Movability, Mutability};
56
use rustc_type_ir::data_structures::HashMap;
67
use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
@@ -384,8 +385,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
384385

385386
/// Relevant types for an async callable, including its inputs, output,
386387
/// and the return type you get from awaiting the output.
387-
#[derive(derivative::Derivative)]
388-
#[derivative(Clone(bound = ""), Copy(bound = ""), Debug(bound = ""))]
388+
#[derive_where(Clone, Copy, Debug; I: Interner)]
389389
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
390390
pub(in crate::solve) struct AsyncCallableRelevantTypes<I: Interner> {
391391
pub tupled_inputs_ty: I::Ty,

Diff for: compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ops::ControlFlow;
22

3+
use derive_where::derive_where;
34
#[cfg(feature = "nightly")]
45
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
56
use rustc_type_ir::data_structures::ensure_sufficient_stack;
@@ -87,8 +88,7 @@ where
8788
pub(super) inspect: ProofTreeBuilder<D>,
8889
}
8990

90-
#[derive(derivative::Derivative)]
91-
#[derivative(Clone(bound = ""), Debug(bound = ""), Default(bound = ""))]
91+
#[derive_where(Clone, Debug, Default; I: Interner)]
9292
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)]
9393
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
9494
// FIXME: This can be made crate-private once `EvalCtxt` also lives in this crate.

Diff for: compiler/rustc_next_trait_solver/src/solve/inspect/build.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use std::marker::PhantomData;
88
use std::mem;
99

10+
use derive_where::derive_where;
1011
use rustc_type_ir::inherent::*;
1112
use rustc_type_ir::{self as ty, search_graph, Interner};
1213

@@ -51,8 +52,7 @@ where
5152
/// in the code, only one or two variants are actually possible.
5253
///
5354
/// We simply ICE in case that assumption is broken.
54-
#[derive(derivative::Derivative)]
55-
#[derivative(Debug(bound = ""))]
55+
#[derive_where(Debug; I: Interner)]
5656
enum DebugSolver<I: Interner> {
5757
Root,
5858
GoalEvaluation(WipGoalEvaluation<I>),
@@ -78,8 +78,7 @@ impl<I: Interner> From<WipCanonicalGoalEvaluationStep<I>> for DebugSolver<I> {
7878
}
7979
}
8080

81-
#[derive(derivative::Derivative)]
82-
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
81+
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
8382
struct WipGoalEvaluation<I: Interner> {
8483
pub uncanonicalized_goal: Goal<I, I::Predicate>,
8584
pub orig_values: Vec<I::GenericArg>,
@@ -96,8 +95,7 @@ impl<I: Interner> WipGoalEvaluation<I> {
9695
}
9796
}
9897

99-
#[derive(derivative::Derivative)]
100-
#[derivative(PartialEq(bound = ""), Eq(bound = ""))]
98+
#[derive_where(PartialEq, Eq; I: Interner)]
10199
pub(in crate::solve) enum WipCanonicalGoalEvaluationKind<I: Interner> {
102100
Overflow,
103101
CycleInStack,
@@ -118,8 +116,7 @@ impl<I: Interner> std::fmt::Debug for WipCanonicalGoalEvaluationKind<I> {
118116
}
119117
}
120118

121-
#[derive(derivative::Derivative)]
122-
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
119+
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
123120
struct WipCanonicalGoalEvaluation<I: Interner> {
124121
goal: CanonicalInput<I>,
125122
kind: Option<WipCanonicalGoalEvaluationKind<I>>,
@@ -153,8 +150,7 @@ impl<I: Interner> WipCanonicalGoalEvaluation<I> {
153150
}
154151
}
155152

156-
#[derive(derivative::Derivative)]
157-
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
153+
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
158154
struct WipCanonicalGoalEvaluationStep<I: Interner> {
159155
/// Unlike `EvalCtxt::var_values`, we append a new
160156
/// generic arg here whenever we create a new inference
@@ -193,8 +189,7 @@ impl<I: Interner> WipCanonicalGoalEvaluationStep<I> {
193189
}
194190
}
195191

196-
#[derive(derivative::Derivative)]
197-
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
192+
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
198193
struct WipProbe<I: Interner> {
199194
initial_num_var_values: usize,
200195
steps: Vec<WipProbeStep<I>>,
@@ -212,8 +207,7 @@ impl<I: Interner> WipProbe<I> {
212207
}
213208
}
214209

215-
#[derive(derivative::Derivative)]
216-
#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))]
210+
#[derive_where(PartialEq, Eq, Debug; I: Interner)]
217211
enum WipProbeStep<I: Interner> {
218212
AddGoal(GoalSource, inspect::CanonicalState<I, Goal<I, I::Predicate>>),
219213
NestedProbe(WipProbe<I>),

Diff for: compiler/rustc_span/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
derivative = "2.2.0"
8+
derive-where = "1.2.7"
99
indexmap = { version = "2.0.0" }
1010
itoa = "1.0"
1111
md5 = { package = "md-5", version = "0.10.0" }

Diff for: compiler/rustc_span/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
// this crate without this line making `rustc_span` available.
3939
extern crate self as rustc_span;
4040

41+
use derive_where::derive_where;
4142
use rustc_data_structures::{outline, AtomicRef};
4243
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
4344
use rustc_serialize::opaque::{FileEncoder, MemDecoder};
@@ -467,18 +468,18 @@ impl FileName {
467468
/// `SpanData` is public because `Span` uses a thread-local interner and can't be
468469
/// sent to other threads, but some pieces of performance infra run in a separate thread.
469470
/// Using `Span` is generally preferred.
470-
#[derive(Clone, Copy, Hash, PartialEq, Eq, derivative::Derivative)]
471-
#[derivative(PartialOrd, Ord)]
471+
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
472+
#[derive_where(PartialOrd, Ord)]
472473
pub struct SpanData {
473474
pub lo: BytePos,
474475
pub hi: BytePos,
475476
/// Information about where the macro came from, if this piece of
476477
/// code was created by a macro expansion.
477-
#[derivative(PartialOrd = "ignore", Ord = "ignore")]
478+
#[derive_where(skip)]
478479
// `SyntaxContext` does not implement `Ord`.
479480
// The other fields are enough to determine in-file order.
480481
pub ctxt: SyntaxContext,
481-
#[derivative(PartialOrd = "ignore", Ord = "ignore")]
482+
#[derive_where(skip)]
482483
// `LocalDefId` does not implement `Ord`.
483484
// The other fields are enough to determine in-file order.
484485
pub parent: Option<LocalDefId>,

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

0 commit comments

Comments
 (0)