Skip to content

Commit 39b4adc

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 390e3c8 commit 39b4adc

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
@@ -3523,7 +3523,6 @@ dependencies = [
35233523
"rustc_macros",
35243524
"rustc_middle",
35253525
"rustc_mir_dataflow",
3526-
"rustc_serialize",
35273526
"rustc_session",
35283527
"rustc_span",
35293528
"rustc_target",
@@ -3934,7 +3933,6 @@ dependencies = [
39343933
"rustc_lint",
39353934
"rustc_macros",
39363935
"rustc_middle",
3937-
"rustc_serialize",
39383936
"rustc_session",
39393937
"rustc_span",
39403938
"rustc_target",
@@ -3997,7 +3995,6 @@ dependencies = [
39973995
"rustc_index",
39983996
"rustc_macros",
39993997
"rustc_middle",
4000-
"rustc_serialize",
40013998
"rustc_span",
40023999
"rustc_target",
40034000
"smallvec",
@@ -4215,7 +4212,6 @@ dependencies = [
42154212
"rustc_infer",
42164213
"rustc_macros",
42174214
"rustc_middle",
4218-
"rustc_serialize",
42194215
"rustc_session",
42204216
"rustc_span",
42214217
"rustc_target",
@@ -4239,7 +4235,6 @@ dependencies = [
42394235
"rustc_index",
42404236
"rustc_macros",
42414237
"rustc_middle",
4242-
"rustc_serialize",
42434238
"rustc_span",
42444239
"rustc_target",
42454240
"smallvec",
@@ -4266,7 +4261,6 @@ dependencies = [
42664261
"rustc_middle",
42674262
"rustc_mir_build",
42684263
"rustc_mir_dataflow",
4269-
"rustc_serialize",
42704264
"rustc_session",
42714265
"rustc_span",
42724266
"rustc_target",
@@ -4340,7 +4334,6 @@ dependencies = [
43404334
"rustc_lexer",
43414335
"rustc_macros",
43424336
"rustc_middle",
4343-
"rustc_serialize",
43444337
"rustc_session",
43454338
"rustc_span",
43464339
"rustc_target",
@@ -4564,7 +4557,6 @@ dependencies = [
45644557
"rustc_middle",
45654558
"rustc_parse_format",
45664559
"rustc_query_system",
4567-
"rustc_serialize",
45684560
"rustc_session",
45694561
"rustc_span",
45704562
"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
@@ -156,6 +156,7 @@ rustc_index::newtype_index! {
156156
/// an "item-like" to something else can be implemented by a `Vec` instead of a
157157
/// tree or hash map.
158158
#[derive(HashStable_Generic)]
159+
#[encodable]
159160
pub struct ItemLocalId {}
160161
}
161162

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)