Skip to content

Commit 23e91d4

Browse files
committed
Remove some unnecessary derives.
I was curious about how many `Encodable`/`Decodable` derives we have. Some grepping revealed that it's over 500 of each, but the number of `Encodable` ones was higher, which was weird. Most of the `Encodable`-only ones were in `hir.rs`. This commit removes them all, plus some other unnecessary derives in that file and others that I found via trial and error.
1 parent a676dfa commit 23e91d4

File tree

4 files changed

+48
-52
lines changed

4 files changed

+48
-52
lines changed

compiler/rustc_hir/src/hir.rs

+37-41
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_target::spec::abi::Abi;
2626
use smallvec::SmallVec;
2727
use std::fmt;
2828

29-
#[derive(Debug, Copy, Clone, Encodable, HashStable_Generic)]
29+
#[derive(Debug, Copy, Clone, HashStable_Generic)]
3030
pub struct Lifetime {
3131
pub hir_id: HirId,
3232

@@ -41,8 +41,7 @@ pub struct Lifetime {
4141
pub res: LifetimeName,
4242
}
4343

44-
#[derive(Debug, Clone, PartialEq, Eq, Encodable, Hash, Copy)]
45-
#[derive(HashStable_Generic)]
44+
#[derive(Debug, Copy, Clone, HashStable_Generic)]
4645
pub enum ParamName {
4746
/// Some user-given name like `T` or `'x`.
4847
Plain(Ident),
@@ -85,8 +84,7 @@ impl ParamName {
8584
}
8685
}
8786

88-
#[derive(Debug, Clone, PartialEq, Eq, Encodable, Hash, Copy)]
89-
#[derive(HashStable_Generic)]
87+
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
9088
pub enum LifetimeName {
9189
/// User-given names or fresh (synthetic) names.
9290
Param(LocalDefId),
@@ -243,13 +241,13 @@ impl<'hir> PathSegment<'hir> {
243241
}
244242
}
245243

246-
#[derive(Encodable, Clone, Copy, Debug, HashStable_Generic)]
244+
#[derive(Clone, Copy, Debug, HashStable_Generic)]
247245
pub struct ConstArg {
248246
pub value: AnonConst,
249247
pub span: Span,
250248
}
251249

252-
#[derive(Encodable, Clone, Copy, Debug, HashStable_Generic)]
250+
#[derive(Clone, Copy, Debug, HashStable_Generic)]
253251
pub struct InferArg {
254252
pub hir_id: HirId,
255253
pub span: Span,
@@ -422,8 +420,7 @@ impl<'hir> GenericArgs<'hir> {
422420
}
423421
}
424422

425-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)]
426-
#[derive(HashStable_Generic)]
423+
#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable_Generic)]
427424
pub enum GenericArgsParentheses {
428425
No,
429426
/// Bounds for `feature(return_type_notation)`, like `T: Trait<method(..): Send>`,
@@ -435,8 +432,7 @@ pub enum GenericArgsParentheses {
435432

436433
/// A modifier on a bound, currently this is only used for `?Sized`, where the
437434
/// modifier is `Maybe`. Negative bounds should also be handled here.
438-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)]
439-
#[derive(HashStable_Generic)]
435+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
440436
pub enum TraitBoundModifier {
441437
None,
442438
Maybe,
@@ -474,7 +470,7 @@ impl GenericBound<'_> {
474470

475471
pub type GenericBounds<'hir> = &'hir [GenericBound<'hir>];
476472

477-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
473+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
478474
pub enum LifetimeParamKind {
479475
// Indicates that the lifetime definition was explicitly declared (e.g., in
480476
// `fn foo<'a>(x: &'a u8) -> &'a u8 { x }`).
@@ -539,7 +535,7 @@ impl<'hir> GenericParam<'hir> {
539535
/// early-bound (but can be a late-bound lifetime in functions, for example),
540536
/// or from a `for<...>` binder, in which case it's late-bound (and notably,
541537
/// does not show up in the parent item's generics).
542-
#[derive(Debug, HashStable_Generic, PartialEq, Eq, Copy, Clone)]
538+
#[derive(Debug, Clone, Copy, HashStable_Generic)]
543539
pub enum GenericParamSource {
544540
// Early or late-bound parameters defined on an item
545541
Generics,
@@ -1097,7 +1093,7 @@ pub struct PatField<'hir> {
10971093
pub span: Span,
10981094
}
10991095

1100-
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
1096+
#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
11011097
pub enum RangeEnd {
11021098
Included,
11031099
Excluded,
@@ -1197,7 +1193,7 @@ pub enum PatKind<'hir> {
11971193
Slice(&'hir [Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [Pat<'hir>]),
11981194
}
11991195

1200-
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
1196+
#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
12011197
pub enum BinOpKind {
12021198
/// The `+` operator (addition).
12031199
Add,
@@ -1325,7 +1321,7 @@ impl Into<ast::BinOpKind> for BinOpKind {
13251321

13261322
pub type BinOp = Spanned<BinOpKind>;
13271323

1328-
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
1324+
#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
13291325
pub enum UnOp {
13301326
/// The `*` operator (dereferencing).
13311327
Deref,
@@ -1450,19 +1446,19 @@ pub struct ExprField<'hir> {
14501446
pub is_shorthand: bool,
14511447
}
14521448

1453-
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
1449+
#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
14541450
pub enum BlockCheckMode {
14551451
DefaultBlock,
14561452
UnsafeBlock(UnsafeSource),
14571453
}
14581454

1459-
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
1455+
#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
14601456
pub enum UnsafeSource {
14611457
CompilerGenerated,
14621458
UserProvided,
14631459
}
14641460

1465-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug)]
1461+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
14661462
pub struct BodyId {
14671463
pub hir_id: HirId,
14681464
}
@@ -1506,7 +1502,7 @@ impl<'hir> Body<'hir> {
15061502
}
15071503

15081504
/// The type of source expression that caused this generator to be created.
1509-
#[derive(Clone, PartialEq, PartialOrd, Eq, Hash, Debug, Copy)]
1505+
#[derive(Clone, PartialEq, Eq, Debug, Copy, Hash)]
15101506
#[derive(HashStable_Generic, Encodable, Decodable)]
15111507
pub enum GeneratorKind {
15121508
/// An explicit `async` block or the body of an async function.
@@ -1539,7 +1535,7 @@ impl GeneratorKind {
15391535
///
15401536
/// This helps error messages but is also used to drive coercions in
15411537
/// type-checking (see #60424).
1542-
#[derive(Clone, PartialEq, PartialOrd, Eq, Hash, Debug, Copy)]
1538+
#[derive(Clone, PartialEq, Eq, Hash, Debug, Copy)]
15431539
#[derive(HashStable_Generic, Encodable, Decodable)]
15441540
pub enum AsyncGeneratorKind {
15451541
/// An explicit `async` block written by the user.
@@ -1649,7 +1645,7 @@ impl fmt::Display for ConstContext {
16491645
/// A literal.
16501646
pub type Lit = Spanned<LitKind>;
16511647

1652-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
1648+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
16531649
pub enum ArrayLen {
16541650
Infer(HirId, Span),
16551651
Body(AnonConst),
@@ -1671,7 +1667,7 @@ impl ArrayLen {
16711667
///
16721668
/// You can check if this anon const is a default in a const param
16731669
/// `const N: usize = { ... }` with `tcx.hir().opt_const_param_default_param_def_id(..)`
1674-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
1670+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
16751671
pub struct AnonConst {
16761672
pub hir_id: HirId,
16771673
pub def_id: LocalDefId,
@@ -2105,7 +2101,7 @@ impl<'hir> QPath<'hir> {
21052101
}
21062102

21072103
/// Hints at the original code for a let statement.
2108-
#[derive(Copy, Clone, Encodable, Debug, HashStable_Generic)]
2104+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
21092105
pub enum LocalSource {
21102106
/// A `match _ { .. }`.
21112107
Normal,
@@ -2158,7 +2154,7 @@ impl MatchSource {
21582154
}
21592155

21602156
/// The loop type that yielded an `ExprKind::Loop`.
2161-
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
2157+
#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
21622158
pub enum LoopSource {
21632159
/// A `loop { .. }` loop.
21642160
Loop,
@@ -2178,7 +2174,7 @@ impl LoopSource {
21782174
}
21792175
}
21802176

2181-
#[derive(Copy, Clone, Encodable, Debug, HashStable_Generic)]
2177+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
21822178
pub enum LoopIdError {
21832179
OutsideLoopScope,
21842180
UnlabeledCfInWhileCondition,
@@ -2197,7 +2193,7 @@ impl fmt::Display for LoopIdError {
21972193
}
21982194
}
21992195

2200-
#[derive(Copy, Clone, Encodable, Debug, HashStable_Generic)]
2196+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
22012197
pub struct Destination {
22022198
/// This is `Some(_)` iff there is an explicit user-specified 'label
22032199
pub label: Option<Label>,
@@ -2208,7 +2204,7 @@ pub struct Destination {
22082204
}
22092205

22102206
/// The yield kind that caused an `ExprKind::Yield`.
2211-
#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable, Decodable, HashStable_Generic)]
2207+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
22122208
pub enum YieldSource {
22132209
/// An `<expr>.await`.
22142210
Await { expr: Option<HirId> },
@@ -2327,7 +2323,7 @@ impl<'hir> TraitItem<'hir> {
23272323
}
23282324

23292325
/// Represents a trait method's body (or just argument names).
2330-
#[derive(Encodable, Debug, Clone, Copy, HashStable_Generic)]
2326+
#[derive(Debug, Clone, Copy, HashStable_Generic)]
23312327
pub enum TraitFn<'hir> {
23322328
/// No default body in the trait, just a signature.
23332329
Required(&'hir [Ident]),
@@ -2658,7 +2654,7 @@ pub struct OpaqueTy<'hir> {
26582654
}
26592655

26602656
/// From whence the opaque type came.
2661-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
2657+
#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable_Generic)]
26622658
pub enum OpaqueTyOrigin {
26632659
/// `-> impl Trait`
26642660
FnReturn(LocalDefId),
@@ -2818,7 +2814,7 @@ impl ImplicitSelfKind {
28182814
}
28192815
}
28202816

2821-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable, Debug)]
2817+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)]
28222818
#[derive(HashStable_Generic)]
28232819
pub enum IsAsync {
28242820
Async,
@@ -2831,7 +2827,7 @@ impl IsAsync {
28312827
}
28322828
}
28332829

2834-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable, HashStable_Generic)]
2830+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable, Decodable, HashStable_Generic)]
28352831
pub enum Defaultness {
28362832
Default { has_value: bool },
28372833
Final,
@@ -2887,13 +2883,13 @@ pub enum ClosureBinder {
28872883
For { span: Span },
28882884
}
28892885

2890-
#[derive(Encodable, Debug, Clone, Copy, HashStable_Generic)]
2886+
#[derive(Debug, Clone, Copy, HashStable_Generic)]
28912887
pub struct Mod<'hir> {
28922888
pub spans: ModSpans,
28932889
pub item_ids: &'hir [ItemId],
28942890
}
28952891

2896-
#[derive(Copy, Clone, Debug, HashStable_Generic, Encodable)]
2892+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
28972893
pub struct ModSpans {
28982894
/// A span from the first token past `{` to the last token until `}`.
28992895
/// For `mod foo;`, the inner span ranges from the first token
@@ -2922,7 +2918,7 @@ pub struct Variant<'hir> {
29222918
pub span: Span,
29232919
}
29242920

2925-
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
2921+
#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
29262922
pub enum UseKind {
29272923
/// One import, e.g., `use foo::bar` or `use foo::bar as baz`.
29282924
/// Also produced for each element of a list `use`, e.g.
@@ -3233,7 +3229,7 @@ impl fmt::Display for Unsafety {
32333229
}
32343230
}
32353231

3236-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
3232+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
32373233
#[derive(Encodable, Decodable, HashStable_Generic)]
32383234
pub enum Constness {
32393235
Const,
@@ -3249,7 +3245,7 @@ impl fmt::Display for Constness {
32493245
}
32503246
}
32513247

3252-
#[derive(Copy, Clone, Encodable, Debug, HashStable_Generic)]
3248+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
32533249
pub struct FnHeader {
32543250
pub unsafety: Unsafety,
32553251
pub constness: Constness,
@@ -3381,7 +3377,7 @@ impl ItemKind<'_> {
33813377
/// type or method, and whether it is public). This allows other
33823378
/// passes to find the impl they want without loading the ID (which
33833379
/// means fewer edges in the incremental compilation graph).
3384-
#[derive(Encodable, Debug, Clone, Copy, HashStable_Generic)]
3380+
#[derive(Debug, Clone, Copy, HashStable_Generic)]
33853381
pub struct TraitItemRef {
33863382
pub id: TraitItemId,
33873383
pub ident: Ident,
@@ -3405,7 +3401,7 @@ pub struct ImplItemRef {
34053401
pub trait_item_def_id: Option<DefId>,
34063402
}
34073403

3408-
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]
3404+
#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)]
34093405
pub enum AssocItemKind {
34103406
Const,
34113407
Fn { has_self: bool },
@@ -3474,7 +3470,7 @@ pub enum ForeignItemKind<'hir> {
34743470
}
34753471

34763472
/// A variable captured by a closure.
3477-
#[derive(Debug, Copy, Clone, Encodable, HashStable_Generic)]
3473+
#[derive(Debug, Copy, Clone, HashStable_Generic)]
34783474
pub struct Upvar {
34793475
/// First span where it is accessed (there can be multiple).
34803476
pub span: Span,
@@ -3483,7 +3479,7 @@ pub struct Upvar {
34833479
// The TraitCandidate's import_ids is empty if the trait is defined in the same module, and
34843480
// has length > 0 if the trait is found through an chain of imports, starting with the
34853481
// import/use statement in the scope where the trait is used.
3486-
#[derive(Encodable, Decodable, Debug, Clone, HashStable_Generic)]
3482+
#[derive(Debug, Clone, HashStable_Generic)]
34873483
pub struct TraitCandidate {
34883484
pub def_id: DefId,
34893485
pub import_ids: SmallVec<[LocalDefId; 1]>,

compiler/rustc_middle/src/middle/region.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl Scope {
203203
pub type ScopeDepth = u32;
204204

205205
/// The region scope tree encodes information about region relationships.
206-
#[derive(TyEncodable, TyDecodable, Default, Debug)]
206+
#[derive(Default, Debug)]
207207
pub struct ScopeTree {
208208
/// If not empty, this body is the root of this region hierarchy.
209209
pub root_body: Option<hir::HirId>,
@@ -317,13 +317,13 @@ pub struct ScopeTree {
317317
/// candidates in general). In constants, the `lifetime` field is None
318318
/// to indicate that certain expressions escape into 'static and
319319
/// should have no local cleanup scope.
320-
#[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
320+
#[derive(Debug, Copy, Clone, HashStable)]
321321
pub enum RvalueCandidateType {
322322
Borrow { target: hir::ItemLocalId, lifetime: Option<Scope> },
323323
Pattern { target: hir::ItemLocalId, lifetime: Option<Scope> },
324324
}
325325

326-
#[derive(Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
326+
#[derive(Debug, Copy, Clone, HashStable)]
327327
pub struct YieldData {
328328
/// The `Span` of the yield.
329329
pub span: Span,

0 commit comments

Comments
 (0)