From 70a11c7ba9d486fdf429dc50770db2dbc37b9eed Mon Sep 17 00:00:00 2001 From: Pavel Grigorenko Date: Thu, 27 Jun 2024 01:59:30 +0300 Subject: [PATCH] rustc_next_trait_solver: derivative -> derive-where --- Cargo.lock | 2 +- compiler/rustc_next_trait_solver/Cargo.toml | 2 +- .../rustc_next_trait_solver/src/coherence.rs | 7 +++--- .../src/solve/assembly/mod.rs | 4 ++-- .../src/solve/assembly/structural_traits.rs | 4 ++-- .../src/solve/eval_ctxt/mod.rs | 4 ++-- .../src/solve/inspect/build.rs | 22 +++++++------------ 7 files changed, 19 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 43010908fb0..e5b19ed5b55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4488,7 +4488,7 @@ name = "rustc_next_trait_solver" version = "0.0.0" dependencies = [ "bitflags 2.5.0", - "derivative", + "derive-where", "rustc_ast_ir", "rustc_data_structures", "rustc_index", diff --git a/compiler/rustc_next_trait_solver/Cargo.toml b/compiler/rustc_next_trait_solver/Cargo.toml index 07cd4ae68d9..cb0730e8673 100644 --- a/compiler/rustc_next_trait_solver/Cargo.toml +++ b/compiler/rustc_next_trait_solver/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start bitflags = "2.4.1" -derivative = "2.2.0" +derive-where = "1.2.7" rustc_ast_ir = { path = "../rustc_ast_ir", default-features = false } rustc_data_structures = { path = "../rustc_data_structures", optional = true } rustc_index = { path = "../rustc_index", default-features = false } diff --git a/compiler/rustc_next_trait_solver/src/coherence.rs b/compiler/rustc_next_trait_solver/src/coherence.rs index 55f602d907b..f22ea41c512 100644 --- a/compiler/rustc_next_trait_solver/src/coherence.rs +++ b/compiler/rustc_next_trait_solver/src/coherence.rs @@ -1,6 +1,7 @@ use std::fmt::Debug; use std::ops::ControlFlow; +use derive_where::derive_where; use rustc_type_ir::inherent::*; use rustc_type_ir::visit::{TypeVisitable, TypeVisitableExt, TypeVisitor}; use rustc_type_ir::{self as ty, InferCtxtLike, Interner}; @@ -108,15 +109,13 @@ fn from(b: bool) -> IsFirstInputType { } } -#[derive(derivative::Derivative)] -#[derivative(Debug(bound = "T: Debug"))] +#[derive_where(Debug; I: Interner, T: Debug)] pub enum OrphanCheckErr { NonLocalInputType(Vec<(I::Ty, IsFirstInputType)>), UncoveredTyParams(UncoveredTyParams), } -#[derive(derivative::Derivative)] -#[derivative(Debug(bound = "T: Debug"))] +#[derive_where(Debug; I: Interner, T: Debug)] pub struct UncoveredTyParams { pub uncovered: T, pub local_ty: Option, diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index 01dde9ca587..f74597fcb39 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -2,6 +2,7 @@ pub(super) mod structural_traits; +use derive_where::derive_where; use rustc_type_ir::elaborate; use rustc_type_ir::fold::TypeFoldable; use rustc_type_ir::inherent::*; @@ -21,8 +22,7 @@ /// /// It consists of both the `source`, which describes how that goal would be proven, /// and the `result` when using the given `source`. -#[derive(derivative::Derivative)] -#[derivative(Debug(bound = ""), Clone(bound = ""))] +#[derive_where(Clone, Debug; I: Interner)] pub(super) struct Candidate { pub(super) source: CandidateSource, pub(super) result: CanonicalResponse, diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index 7df14e81ab5..770ac9a929e 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -1,6 +1,7 @@ //! Code which is used by built-in goals that match "structurally", such a auto //! traits, `Copy`/`Clone`. +use derive_where::derive_where; use rustc_ast_ir::{Movability, Mutability}; use rustc_type_ir::data_structures::HashMap; use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; @@ -384,8 +385,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable { pub tupled_inputs_ty: I::Ty, diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index c23bc8f09ad..e328284c001 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -1,5 +1,6 @@ use std::ops::ControlFlow; +use derive_where::derive_where; #[cfg(feature = "nightly")] use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable}; use rustc_type_ir::data_structures::ensure_sufficient_stack; @@ -87,8 +88,7 @@ pub struct EvalCtxt<'a, D, I = ::Interner> pub(super) inspect: ProofTreeBuilder, } -#[derive(derivative::Derivative)] -#[derivative(Clone(bound = ""), Debug(bound = ""), Default(bound = ""))] +#[derive_where(Clone, Debug, Default; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))] // FIXME: This can be made crate-private once `EvalCtxt` also lives in this crate. diff --git a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs index 3e266ddac71..36e13cc97d6 100644 --- a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs +++ b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs @@ -7,6 +7,7 @@ use std::marker::PhantomData; use std::mem; +use derive_where::derive_where; use rustc_type_ir::inherent::*; use rustc_type_ir::{self as ty, search_graph, Interner}; @@ -51,8 +52,7 @@ pub(crate) struct ProofTreeBuilder::Interner> /// in the code, only one or two variants are actually possible. /// /// We simply ICE in case that assumption is broken. -#[derive(derivative::Derivative)] -#[derivative(Debug(bound = ""))] +#[derive_where(Debug; I: Interner)] enum DebugSolver { Root, GoalEvaluation(WipGoalEvaluation), @@ -78,8 +78,7 @@ fn from(g: WipCanonicalGoalEvaluationStep) -> DebugSolver { } } -#[derive(derivative::Derivative)] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))] +#[derive_where(PartialEq, Eq, Debug; I: Interner)] struct WipGoalEvaluation { pub uncanonicalized_goal: Goal, pub orig_values: Vec, @@ -96,8 +95,7 @@ fn finalize(self) -> inspect::GoalEvaluation { } } -#[derive(derivative::Derivative)] -#[derivative(PartialEq(bound = ""), Eq(bound = ""))] +#[derive_where(PartialEq, Eq; I: Interner)] pub(in crate::solve) enum WipCanonicalGoalEvaluationKind { Overflow, CycleInStack, @@ -118,8 +116,7 @@ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { } } -#[derive(derivative::Derivative)] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))] +#[derive_where(PartialEq, Eq, Debug; I: Interner)] struct WipCanonicalGoalEvaluation { goal: CanonicalInput, kind: Option>, @@ -153,8 +150,7 @@ fn finalize(self) -> inspect::CanonicalGoalEvaluation { } } -#[derive(derivative::Derivative)] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))] +#[derive_where(PartialEq, Eq, Debug; I: Interner)] struct WipCanonicalGoalEvaluationStep { /// Unlike `EvalCtxt::var_values`, we append a new /// generic arg here whenever we create a new inference @@ -193,8 +189,7 @@ fn finalize(self) -> inspect::CanonicalGoalEvaluationStep { } } -#[derive(derivative::Derivative)] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))] +#[derive_where(PartialEq, Eq, Debug; I: Interner)] struct WipProbe { initial_num_var_values: usize, steps: Vec>, @@ -212,8 +207,7 @@ fn finalize(self) -> inspect::Probe { } } -#[derive(derivative::Derivative)] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Debug(bound = ""))] +#[derive_where(PartialEq, Eq, Debug; I: Interner)] enum WipProbeStep { AddGoal(GoalSource, inspect::CanonicalState>), NestedProbe(WipProbe),