Skip to content

Commit f2c6d5c

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 290fc68 commit f2c6d5c

File tree

28 files changed

+27
-28
lines changed

28 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",
@@ -3986,7 +3984,6 @@ dependencies = [
39863984
"rustc_index",
39873985
"rustc_macros",
39883986
"rustc_middle",
3989-
"rustc_serialize",
39903987
"rustc_span",
39913988
"rustc_target",
39923989
"smallvec",
@@ -4204,7 +4201,6 @@ dependencies = [
42044201
"rustc_infer",
42054202
"rustc_macros",
42064203
"rustc_middle",
4207-
"rustc_serialize",
42084204
"rustc_session",
42094205
"rustc_span",
42104206
"rustc_target",
@@ -4228,7 +4224,6 @@ dependencies = [
42284224
"rustc_index",
42294225
"rustc_macros",
42304226
"rustc_middle",
4231-
"rustc_serialize",
42324227
"rustc_span",
42334228
"rustc_target",
42344229
"smallvec",
@@ -4255,7 +4250,6 @@ dependencies = [
42554250
"rustc_middle",
42564251
"rustc_mir_build",
42574252
"rustc_mir_dataflow",
4258-
"rustc_serialize",
42594253
"rustc_session",
42604254
"rustc_span",
42614255
"rustc_target",
@@ -4329,7 +4323,6 @@ dependencies = [
43294323
"rustc_lexer",
43304324
"rustc_macros",
43314325
"rustc_middle",
4332-
"rustc_serialize",
43334326
"rustc_session",
43344327
"rustc_span",
43354328
"rustc_target",
@@ -4553,7 +4546,6 @@ dependencies = [
45534546
"rustc_middle",
45544547
"rustc_parse_format",
45554548
"rustc_query_system",
4556-
"rustc_serialize",
45574549
"rustc_session",
45584550
"rustc_span",
45594551
"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_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"] }

compiler/rustc_lint/src/levels.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ struct LintLevelSets {
5656
}
5757

5858
rustc_index::newtype_index! {
59-
#[custom_encodable] // we don't need encoding
6059
struct LintStackIndex {
6160
const COMMAND_LINE = 0;
6261
}

0 commit comments

Comments
 (0)