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.
This commit is contained in:
Nicholas Nethercote
2023-11-21 16:35:26 +11:00
parent cc4bb0de20
commit 3ef9d4d0ed
29 changed files with 27 additions and 28 deletions

View File

@@ -148,6 +148,7 @@ rustc_index::newtype_index! {
/// * The subscope with `first_statement_index == 1` is scope of `c`,
/// and thus does not include EXPR_2, but covers the `...`.
#[derive(HashStable)]
#[encodable]
pub struct FirstStatementIndex {}
}

View File

@@ -17,6 +17,7 @@ rustc_index::newtype_index! {
/// Note that LLVM handles counter IDs as `uint32_t`, so there is no need
/// to use a larger representation on the Rust side.
#[derive(HashStable)]
#[encodable]
#[max = 0xFFFF_FFFF]
#[debug_format = "CounterId({})"]
pub struct CounterId {}
@@ -37,6 +38,7 @@ rustc_index::newtype_index! {
/// Note that LLVM handles expression IDs as `uint32_t`, so there is no need
/// to use a larger representation on the Rust side.
#[derive(HashStable)]
#[encodable]
#[max = 0xFFFF_FFFF]
#[debug_format = "ExpressionId({})"]
pub struct ExpressionId {}

View File

@@ -736,6 +736,7 @@ impl SourceInfo {
rustc_index::newtype_index! {
#[derive(HashStable)]
#[encodable]
#[debug_format = "_{}"]
pub struct Local {
const RETURN_PLACE = 0;
@@ -1171,6 +1172,7 @@ rustc_index::newtype_index! {
/// [`CriticalCallEdges`]: ../../rustc_const_eval/transform/add_call_guards/enum.AddCallGuards.html#variant.CriticalCallEdges
/// [guide-mir]: https://rustc-dev-guide.rust-lang.org/mir/
#[derive(HashStable)]
#[encodable]
#[debug_format = "bb{}"]
pub struct BasicBlock {
const START_BLOCK = 0;
@@ -1305,6 +1307,7 @@ impl<'tcx> BasicBlockData<'tcx> {
rustc_index::newtype_index! {
#[derive(HashStable)]
#[encodable]
#[debug_format = "scope[{}]"]
pub struct SourceScope {
const OUTERMOST_SOURCE_SCOPE = 0;
@@ -1533,6 +1536,7 @@ impl UserTypeProjection {
rustc_index::newtype_index! {
#[derive(HashStable)]
#[encodable]
#[debug_format = "promoted[{}]"]
pub struct Promoted {}
}

View File

@@ -132,6 +132,7 @@ pub struct UnsafetyCheckResult {
rustc_index::newtype_index! {
#[derive(HashStable)]
#[encodable]
#[debug_format = "_{}"]
pub struct CoroutineSavedLocal {}
}

View File

@@ -1612,6 +1612,7 @@ impl fmt::Debug for EarlyParamRegion {
rustc_index::newtype_index! {
/// A **region** (lifetime) **v**ariable **ID**.
#[derive(HashStable)]
#[encodable]
#[debug_format = "'?{}"]
pub struct RegionVid {}
}

View File

@@ -578,6 +578,7 @@ impl<'a, V> LocalTableInContextMut<'a, V> {
rustc_index::newtype_index! {
#[derive(HashStable)]
#[encodable]
#[debug_format = "UserType({})"]
pub struct UserTypeAnnotationIndex {
const START_INDEX = 0;