Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3ef9d4d

Browse files
committed
Replace custom_encodable with encodable.
By default, `newtype_index!` types get a default `Encodable`/`Decodable` impl. You can opt out of this with `custom_encodable`. Opting out is the opposite to how Rust normally works with autogenerated (derived) impls. This commit inverts the behaviour, replacing `custom_encodable` with `encodable` which opts into the default `Encodable`/`Decodable` impl. Only 23 of the 59 `newtype_index!` occurrences need `encodable`. Even better, there were eight crates with a dependency on `rustc_serialize` just from unused default `Encodable`/`Decodable` impls. This commit removes that dependency from those eight crates.
1 parent cc4bb0d commit 3ef9d4d

File tree

29 files changed

+27
-28
lines changed

29 files changed

+27
-28
lines changed

Cargo.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,7 +3524,6 @@ dependencies = [
35243524
"rustc_macros",
35253525
"rustc_middle",
35263526
"rustc_mir_dataflow",
3527-
"rustc_serialize",
35283527
"rustc_session",
35293528
"rustc_span",
35303529
"rustc_target",
@@ -3935,7 +3934,6 @@ dependencies = [
39353934
"rustc_lint",
39363935
"rustc_macros",
39373936
"rustc_middle",
3938-
"rustc_serialize",
39393937
"rustc_session",
39403938
"rustc_span",
39413939
"rustc_target",
@@ -3998,7 +3996,6 @@ dependencies = [
39983996
"rustc_index",
39993997
"rustc_macros",
40003998
"rustc_middle",
4001-
"rustc_serialize",
40023999
"rustc_span",
40034000
"rustc_target",
40044001
"smallvec",
@@ -4216,7 +4213,6 @@ dependencies = [
42164213
"rustc_infer",
42174214
"rustc_macros",
42184215
"rustc_middle",
4219-
"rustc_serialize",
42204216
"rustc_session",
42214217
"rustc_span",
42224218
"rustc_target",
@@ -4240,7 +4236,6 @@ dependencies = [
42404236
"rustc_index",
42414237
"rustc_macros",
42424238
"rustc_middle",
4243-
"rustc_serialize",
42444239
"rustc_span",
42454240
"rustc_target",
42464241
"smallvec",
@@ -4267,7 +4262,6 @@ dependencies = [
42674262
"rustc_middle",
42684263
"rustc_mir_build",
42694264
"rustc_mir_dataflow",
4270-
"rustc_serialize",
42714265
"rustc_session",
42724266
"rustc_span",
42734267
"rustc_target",
@@ -4341,7 +4335,6 @@ dependencies = [
43414335
"rustc_lexer",
43424336
"rustc_macros",
43434337
"rustc_middle",
4344-
"rustc_serialize",
43454338
"rustc_session",
43464339
"rustc_span",
43474340
"rustc_target",
@@ -4565,7 +4558,6 @@ dependencies = [
45654558
"rustc_middle",
45664559
"rustc_parse_format",
45674560
"rustc_query_system",
4568-
"rustc_serialize",
45694561
"rustc_session",
45704562
"rustc_span",
45714563
"rustc_target",

compiler/rustc_ast/src/ast.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2574,7 +2574,6 @@ pub enum AttrStyle {
25742574
}
25752575

25762576
rustc_index::newtype_index! {
2577-
#[custom_encodable]
25782577
#[debug_format = "AttrId({})"]
25792578
pub struct AttrId {}
25802579
}

compiler/rustc_ast/src/node_id.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ rustc_index::newtype_index! {
88
/// This is later turned into [`DefId`] and `HirId` for the HIR.
99
///
1010
/// [`DefId`]: rustc_span::def_id::DefId
11+
#[encodable]
1112
#[debug_format = "NodeId({})"]
1213
pub struct NodeId {
1314
/// The [`NodeId`] used to represent the root of the crate.

compiler/rustc_borrowck/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ rustc_lexer = { path = "../rustc_lexer" }
1919
rustc_macros = { path = "../rustc_macros" }
2020
rustc_middle = { path = "../rustc_middle" }
2121
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }
22-
rustc_serialize = { path = "../rustc_serialize" }
2322
rustc_session = { path = "../rustc_session" }
2423
rustc_span = { path = "../rustc_span" }
2524
rustc_target = { path = "../rustc_target" }

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ impl GlobalFileTable {
189189
}
190190

191191
rustc_index::newtype_index! {
192-
// Tell the newtype macro to not generate `Encode`/`Decode` impls.
193-
#[custom_encodable]
194192
struct LocalFileId {}
195193
}
196194

compiler/rustc_hir/src/hir_id.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ rustc_index::newtype_index! {
154154
/// an "item-like" to something else can be implemented by a `Vec` instead of a
155155
/// tree or hash map.
156156
#[derive(HashStable_Generic)]
157+
#[encodable]
157158
pub struct ItemLocalId {}
158159
}
159160

compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
198198
// entire graph when there are many connected regions.
199199

200200
rustc_index::newtype_index! {
201-
#[custom_encodable]
202201
pub struct RegionId {}
203202
}
204203

compiler/rustc_hir_typeck/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ rustc_infer = { path = "../rustc_infer" }
1919
rustc_lint = { path = "../rustc_lint" }
2020
rustc_macros = { path = "../rustc_macros" }
2121
rustc_middle = { path = "../rustc_middle" }
22-
rustc_serialize = { path = "../rustc_serialize" }
2322
rustc_session = { path = "../rustc_session" }
2423
rustc_span = { path = "../rustc_span" }
2524
rustc_target = { path = "../rustc_target" }

compiler/rustc_index_macros/src/newtype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Parse for Newtype {
2222
let mut debug_format: Option<Lit> = None;
2323
let mut max = None;
2424
let mut consts = Vec::new();
25-
let mut encodable = true;
25+
let mut encodable = false;
2626
let mut ord = true;
2727
let mut gate_rustc_only = quote! {};
2828
let mut gate_rustc_only_cfg = quote! { all() };
@@ -34,8 +34,8 @@ impl Parse for Newtype {
3434
gate_rustc_only_cfg = quote! { feature = "nightly" };
3535
false
3636
}
37-
"custom_encodable" => {
38-
encodable = false;
37+
"encodable" => {
38+
encodable = true;
3939
false
4040
}
4141
"no_ord_impl" => {

compiler/rustc_infer/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ rustc_hir = { path = "../rustc_hir" }
1515
rustc_index = { path = "../rustc_index" }
1616
rustc_macros = { path = "../rustc_macros" }
1717
rustc_middle = { path = "../rustc_middle" }
18-
rustc_serialize = { path = "../rustc_serialize" }
1918
rustc_span = { path = "../rustc_span" }
2019
rustc_target = { path = "../rustc_target" }
2120
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }

0 commit comments

Comments
 (0)