about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2025-01-07 18:28:42 +0100
committerRalf Jung <post@ralfj.de>2025-01-14 16:16:38 +0100
commit9ac62f972fd47705f9d229e854772194565071eb (patch)
tree64fedcf02879ed35c722fcedc8c485bd72c25707
parent4df78a07e5c3ad032d59941b77ab394e4a75c7c1 (diff)
downloadrust-9ac62f972fd47705f9d229e854772194565071eb.tar.gz
rust-9ac62f972fd47705f9d229e854772194565071eb.zip
remove Rustc{En,De}codable from library and compiler
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/debug.rs2
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/decodable.rs215
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/default.rs2
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/encodable.rs284
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/generic/mod.rs26
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/generic/ty.rs2
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/mod.rs2
-rw-r--r--compiler/rustc_builtin_macros/src/lib.rs2
-rw-r--r--compiler/rustc_span/src/symbol.rs2
-rw-r--r--library/core/src/macros/mod.rs26
-rw-r--r--library/core/src/prelude/mod.rs9
-rw-r--r--library/std/src/prelude/mod.rs9
12 files changed, 10 insertions, 571 deletions
diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs
index eb01ca3941d..8ab21986e68 100644
--- a/compiler/rustc_builtin_macros/src/deriving/debug.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/debug.rs
@@ -56,7 +56,7 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) ->
 
     let (ident, vdata, fields) = match substr.fields {
         Struct(vdata, fields) => (substr.type_ident, *vdata, fields),
-        EnumMatching(_, v, fields) => (v.ident, &v.data, fields),
+        EnumMatching(v, fields) => (v.ident, &v.data, fields),
         AllFieldlessEnum(enum_def) => return show_fieldless_enum(cx, span, enum_def, substr),
         EnumDiscr(..) | StaticStruct(..) | StaticEnum(..) => {
             cx.dcx().span_bug(span, "nonsensical .fields in `#[derive(Debug)]`")
diff --git a/compiler/rustc_builtin_macros/src/deriving/decodable.rs b/compiler/rustc_builtin_macros/src/deriving/decodable.rs
deleted file mode 100644
index 6348560496e..00000000000
--- a/compiler/rustc_builtin_macros/src/deriving/decodable.rs
+++ /dev/null
@@ -1,215 +0,0 @@
-//! The compiler code necessary for `#[derive(RustcDecodable)]`. See encodable.rs for more.
-
-use rustc_ast::ptr::P;
-use rustc_ast::{self as ast, Expr, MetaItem, Mutability};
-use rustc_expand::base::{Annotatable, ExtCtxt};
-use rustc_span::{Ident, Span, Symbol, sym};
-use thin_vec::{ThinVec, thin_vec};
-
-use crate::deriving::generic::ty::*;
-use crate::deriving::generic::*;
-use crate::deriving::pathvec_std;
-
-pub(crate) fn expand_deriving_rustc_decodable(
-    cx: &ExtCtxt<'_>,
-    span: Span,
-    mitem: &MetaItem,
-    item: &Annotatable,
-    push: &mut dyn FnMut(Annotatable),
-    is_const: bool,
-) {
-    let krate = sym::rustc_serialize;
-    let typaram = sym::__D;
-
-    let trait_def = TraitDef {
-        span,
-        path: Path::new_(vec![krate, sym::Decodable], vec![], PathKind::Global),
-        skip_path_as_bound: false,
-        needs_copy_as_bound_if_packed: true,
-        additional_bounds: Vec::new(),
-        supports_unions: false,
-        methods: vec![MethodDef {
-            name: sym::decode,
-            generics: Bounds {
-                bounds: vec![(typaram, vec![Path::new_(
-                    vec![krate, sym::Decoder],
-                    vec![],
-                    PathKind::Global,
-                )])],
-            },
-            explicit_self: false,
-            nonself_args: vec![(
-                Ref(Box::new(Path(Path::new_local(typaram))), Mutability::Mut),
-                sym::d,
-            )],
-            ret_ty: Path(Path::new_(
-                pathvec_std!(result::Result),
-                vec![
-                    Box::new(Self_),
-                    Box::new(Path(Path::new_(vec![typaram, sym::Error], vec![], PathKind::Local))),
-                ],
-                PathKind::Std,
-            )),
-            attributes: ast::AttrVec::new(),
-            fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
-            combine_substructure: combine_substructure(Box::new(|a, b, c| {
-                decodable_substructure(a, b, c, krate)
-            })),
-        }],
-        associated_types: Vec::new(),
-        is_const,
-    };
-
-    trait_def.expand(cx, mitem, item, push)
-}
-
-fn decodable_substructure(
-    cx: &ExtCtxt<'_>,
-    trait_span: Span,
-    substr: &Substructure<'_>,
-    krate: Symbol,
-) -> BlockOrExpr {
-    let decoder = substr.nonselflike_args[0].clone();
-    let recurse = vec![
-        Ident::new(krate, trait_span),
-        Ident::new(sym::Decodable, trait_span),
-        Ident::new(sym::decode, trait_span),
-    ];
-    let exprdecode = cx.expr_path(cx.path_global(trait_span, recurse));
-    // throw an underscore in front to suppress unused variable warnings
-    let blkarg = Ident::new(sym::_d, trait_span);
-    let blkdecoder = cx.expr_ident(trait_span, blkarg);
-
-    let expr = match substr.fields {
-        StaticStruct(_, summary) => {
-            let nfields = match summary {
-                Unnamed(fields, _) => fields.len(),
-                Named(fields) => fields.len(),
-            };
-            let fn_read_struct_field_path: Vec<_> =
-                cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_struct_field]);
-
-            let path = cx.path_ident(trait_span, substr.type_ident);
-            let result =
-                decode_static_fields(cx, trait_span, path, summary, |cx, span, name, field| {
-                    cx.expr_try(
-                        span,
-                        cx.expr_call_global(span, fn_read_struct_field_path.clone(), thin_vec![
-                            blkdecoder.clone(),
-                            cx.expr_str(span, name),
-                            cx.expr_usize(span, field),
-                            exprdecode.clone(),
-                        ]),
-                    )
-                });
-            let result = cx.expr_ok(trait_span, result);
-            let fn_read_struct_path: Vec<_> =
-                cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_struct]);
-
-            cx.expr_call_global(trait_span, fn_read_struct_path, thin_vec![
-                decoder,
-                cx.expr_str(trait_span, substr.type_ident.name),
-                cx.expr_usize(trait_span, nfields),
-                cx.lambda1(trait_span, result, blkarg),
-            ])
-        }
-        StaticEnum(_, fields) => {
-            let variant = Ident::new(sym::i, trait_span);
-
-            let mut arms = ThinVec::with_capacity(fields.len() + 1);
-            let mut variants = ThinVec::with_capacity(fields.len());
-
-            let fn_read_enum_variant_arg_path: Vec<_> =
-                cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_enum_variant_arg]);
-
-            for (i, &(ident, v_span, ref parts)) in fields.iter().enumerate() {
-                variants.push(cx.expr_str(v_span, ident.name));
-
-                let path = cx.path(trait_span, vec![substr.type_ident, ident]);
-                let decoded =
-                    decode_static_fields(cx, v_span, path, parts, |cx, span, _, field| {
-                        let idx = cx.expr_usize(span, field);
-                        cx.expr_try(
-                            span,
-                            cx.expr_call_global(
-                                span,
-                                fn_read_enum_variant_arg_path.clone(),
-                                thin_vec![blkdecoder.clone(), idx, exprdecode.clone()],
-                            ),
-                        )
-                    });
-
-                arms.push(cx.arm(v_span, cx.pat_lit(v_span, cx.expr_usize(v_span, i)), decoded));
-            }
-
-            arms.push(cx.arm_unreachable(trait_span));
-
-            let result = cx.expr_ok(
-                trait_span,
-                cx.expr_match(trait_span, cx.expr_ident(trait_span, variant), arms),
-            );
-            let lambda = cx.lambda(trait_span, vec![blkarg, variant], result);
-            let variant_array_ref = cx.expr_array_ref(trait_span, variants);
-            let fn_read_enum_variant_path: Vec<_> =
-                cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_enum_variant]);
-            let result = cx.expr_call_global(trait_span, fn_read_enum_variant_path, thin_vec![
-                blkdecoder,
-                variant_array_ref,
-                lambda
-            ]);
-            let fn_read_enum_path: Vec<_> =
-                cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_enum]);
-
-            cx.expr_call_global(trait_span, fn_read_enum_path, thin_vec![
-                decoder,
-                cx.expr_str(trait_span, substr.type_ident.name),
-                cx.lambda1(trait_span, result, blkarg),
-            ])
-        }
-        _ => cx.dcx().bug("expected StaticEnum or StaticStruct in derive(Decodable)"),
-    };
-    BlockOrExpr::new_expr(expr)
-}
-
-/// Creates a decoder for a single enum variant/struct:
-/// - `outer_pat_path` is the path to this enum variant/struct
-/// - `getarg` should retrieve the `usize`-th field with name `@str`.
-fn decode_static_fields<F>(
-    cx: &ExtCtxt<'_>,
-    trait_span: Span,
-    outer_pat_path: ast::Path,
-    fields: &StaticFields,
-    mut getarg: F,
-) -> P<Expr>
-where
-    F: FnMut(&ExtCtxt<'_>, Span, Symbol, usize) -> P<Expr>,
-{
-    match fields {
-        Unnamed(fields, is_tuple) => {
-            let path_expr = cx.expr_path(outer_pat_path);
-            if matches!(is_tuple, IsTuple::No) {
-                path_expr
-            } else {
-                let fields = fields
-                    .iter()
-                    .enumerate()
-                    .map(|(i, &span)| getarg(cx, span, Symbol::intern(&format!("_field{i}")), i))
-                    .collect();
-
-                cx.expr_call(trait_span, path_expr, fields)
-            }
-        }
-        Named(fields) => {
-            // use the field's span to get nicer error messages.
-            let fields = fields
-                .iter()
-                .enumerate()
-                .map(|(i, &(ident, span, _))| {
-                    let arg = getarg(cx, span, ident.name, i);
-                    cx.field_imm(span, ident, arg)
-                })
-                .collect();
-            cx.expr_struct(trait_span, outer_pat_path, fields)
-        }
-    }
-}
diff --git a/compiler/rustc_builtin_macros/src/deriving/default.rs b/compiler/rustc_builtin_macros/src/deriving/default.rs
index 3c7bebd0f19..2388b7dd648 100644
--- a/compiler/rustc_builtin_macros/src/deriving/default.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/default.rs
@@ -42,7 +42,7 @@ pub(crate) fn expand_deriving_default(
                     StaticStruct(_, fields) => {
                         default_struct_substructure(cx, trait_span, substr, fields)
                     }
-                    StaticEnum(enum_def, _) => {
+                    StaticEnum(enum_def) => {
                         default_enum_substructure(cx, trait_span, enum_def, item.span())
                     }
                     _ => cx.dcx().span_bug(trait_span, "method in `derive(Default)`"),
diff --git a/compiler/rustc_builtin_macros/src/deriving/encodable.rs b/compiler/rustc_builtin_macros/src/deriving/encodable.rs
deleted file mode 100644
index 20aacb2caca..00000000000
--- a/compiler/rustc_builtin_macros/src/deriving/encodable.rs
+++ /dev/null
@@ -1,284 +0,0 @@
-//! The compiler code necessary to implement the `#[derive(RustcEncodable)]`
-//! (and `RustcDecodable`, in `decodable.rs`) extension. The idea here is that
-//! type-defining items may be tagged with
-//! `#[derive(RustcEncodable, RustcDecodable)]`.
-//!
-//! For example, a type like:
-//!
-//! ```ignore (old code)
-//! #[derive(RustcEncodable, RustcDecodable)]
-//! struct Node { id: usize }
-//! ```
-//!
-//! would generate two implementations like:
-//!
-//! ```ignore (old code)
-//! # struct Node { id: usize }
-//! impl<S: Encoder<E>, E> Encodable<S, E> for Node {
-//!     fn encode(&self, s: &mut S) -> Result<(), E> {
-//!         s.emit_struct("Node", 1, |this| {
-//!             this.emit_struct_field("id", 0, |this| {
-//!                 Encodable::encode(&self.id, this)
-//!                 /* this.emit_usize(self.id) can also be used */
-//!             })
-//!         })
-//!     }
-//! }
-//!
-//! impl<D: Decoder<E>, E> Decodable<D, E> for Node {
-//!     fn decode(d: &mut D) -> Result<Node, E> {
-//!         d.read_struct("Node", 1, |this| {
-//!             match this.read_struct_field("id", 0, |this| Decodable::decode(this)) {
-//!                 Ok(id) => Ok(Node { id: id }),
-//!                 Err(e) => Err(e),
-//!             }
-//!         })
-//!     }
-//! }
-//! ```
-//!
-//! Other interesting scenarios are when the item has type parameters or
-//! references other non-built-in types. A type definition like:
-//!
-//! ```ignore (old code)
-//! # #[derive(RustcEncodable, RustcDecodable)]
-//! # struct Span;
-//! #[derive(RustcEncodable, RustcDecodable)]
-//! struct Spanned<T> { node: T, span: Span }
-//! ```
-//!
-//! would yield functions like:
-//!
-//! ```ignore (old code)
-//! # #[derive(RustcEncodable, RustcDecodable)]
-//! # struct Span;
-//! # struct Spanned<T> { node: T, span: Span }
-//! impl<
-//!     S: Encoder<E>,
-//!     E,
-//!     T: Encodable<S, E>
-//! > Encodable<S, E> for Spanned<T> {
-//!     fn encode(&self, s: &mut S) -> Result<(), E> {
-//!         s.emit_struct("Spanned", 2, |this| {
-//!             this.emit_struct_field("node", 0, |this| self.node.encode(this))
-//!                 .unwrap();
-//!             this.emit_struct_field("span", 1, |this| self.span.encode(this))
-//!         })
-//!     }
-//! }
-//!
-//! impl<
-//!     D: Decoder<E>,
-//!     E,
-//!     T: Decodable<D, E>
-//! > Decodable<D, E> for Spanned<T> {
-//!     fn decode(d: &mut D) -> Result<Spanned<T>, E> {
-//!         d.read_struct("Spanned", 2, |this| {
-//!             Ok(Spanned {
-//!                 node: this.read_struct_field("node", 0, |this| Decodable::decode(this))
-//!                     .unwrap(),
-//!                 span: this.read_struct_field("span", 1, |this| Decodable::decode(this))
-//!                     .unwrap(),
-//!             })
-//!         })
-//!     }
-//! }
-//! ```
-
-use rustc_ast::{AttrVec, ExprKind, MetaItem, Mutability};
-use rustc_expand::base::{Annotatable, ExtCtxt};
-use rustc_span::{Ident, Span, Symbol, sym};
-use thin_vec::{ThinVec, thin_vec};
-
-use crate::deriving::generic::ty::*;
-use crate::deriving::generic::*;
-use crate::deriving::pathvec_std;
-
-pub(crate) fn expand_deriving_rustc_encodable(
-    cx: &ExtCtxt<'_>,
-    span: Span,
-    mitem: &MetaItem,
-    item: &Annotatable,
-    push: &mut dyn FnMut(Annotatable),
-    is_const: bool,
-) {
-    let krate = sym::rustc_serialize;
-    let typaram = sym::__S;
-
-    let trait_def = TraitDef {
-        span,
-        path: Path::new_(vec![krate, sym::Encodable], vec![], PathKind::Global),
-        skip_path_as_bound: false,
-        needs_copy_as_bound_if_packed: true,
-        additional_bounds: Vec::new(),
-        supports_unions: false,
-        methods: vec![MethodDef {
-            name: sym::encode,
-            generics: Bounds {
-                bounds: vec![(typaram, vec![Path::new_(
-                    vec![krate, sym::Encoder],
-                    vec![],
-                    PathKind::Global,
-                )])],
-            },
-            explicit_self: true,
-            nonself_args: vec![(
-                Ref(Box::new(Path(Path::new_local(typaram))), Mutability::Mut),
-                sym::s,
-            )],
-            ret_ty: Path(Path::new_(
-                pathvec_std!(result::Result),
-                vec![
-                    Box::new(Unit),
-                    Box::new(Path(Path::new_(vec![typaram, sym::Error], vec![], PathKind::Local))),
-                ],
-                PathKind::Std,
-            )),
-            attributes: AttrVec::new(),
-            fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
-            combine_substructure: combine_substructure(Box::new(|a, b, c| {
-                encodable_substructure(a, b, c, krate)
-            })),
-        }],
-        associated_types: Vec::new(),
-        is_const,
-    };
-
-    trait_def.expand(cx, mitem, item, push)
-}
-
-fn encodable_substructure(
-    cx: &ExtCtxt<'_>,
-    trait_span: Span,
-    substr: &Substructure<'_>,
-    krate: Symbol,
-) -> BlockOrExpr {
-    let encoder = substr.nonselflike_args[0].clone();
-    // throw an underscore in front to suppress unused variable warnings
-    let blkarg = Ident::new(sym::_e, trait_span);
-    let blkencoder = cx.expr_ident(trait_span, blkarg);
-    let fn_path = cx.expr_path(cx.path_global(trait_span, vec![
-        Ident::new(krate, trait_span),
-        Ident::new(sym::Encodable, trait_span),
-        Ident::new(sym::encode, trait_span),
-    ]));
-
-    match substr.fields {
-        Struct(_, fields) => {
-            let fn_emit_struct_field_path =
-                cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_struct_field]);
-            let mut stmts = ThinVec::new();
-            for (i, &FieldInfo { name, ref self_expr, span, .. }) in fields.iter().enumerate() {
-                let name = match name {
-                    Some(id) => id.name,
-                    None => Symbol::intern(&format!("_field{i}")),
-                };
-                let self_ref = cx.expr_addr_of(span, self_expr.clone());
-                let enc =
-                    cx.expr_call(span, fn_path.clone(), thin_vec![self_ref, blkencoder.clone()]);
-                let lambda = cx.lambda1(span, enc, blkarg);
-                let call = cx.expr_call_global(span, fn_emit_struct_field_path.clone(), thin_vec![
-                    blkencoder.clone(),
-                    cx.expr_str(span, name),
-                    cx.expr_usize(span, i),
-                    lambda,
-                ]);
-
-                // last call doesn't need a try!
-                let last = fields.len() - 1;
-                let call = if i != last {
-                    cx.expr_try(span, call)
-                } else {
-                    cx.expr(span, ExprKind::Ret(Some(call)))
-                };
-
-                let stmt = cx.stmt_expr(call);
-                stmts.push(stmt);
-            }
-
-            // unit structs have no fields and need to return Ok()
-            let blk = if stmts.is_empty() {
-                let ok = cx.expr_ok(trait_span, cx.expr_tuple(trait_span, ThinVec::new()));
-                cx.lambda1(trait_span, ok, blkarg)
-            } else {
-                cx.lambda_stmts_1(trait_span, stmts, blkarg)
-            };
-
-            let fn_emit_struct_path =
-                cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_struct]);
-
-            let expr = cx.expr_call_global(trait_span, fn_emit_struct_path, thin_vec![
-                encoder,
-                cx.expr_str(trait_span, substr.type_ident.name),
-                cx.expr_usize(trait_span, fields.len()),
-                blk,
-            ]);
-            BlockOrExpr::new_expr(expr)
-        }
-
-        EnumMatching(idx, variant, fields) => {
-            // We're not generating an AST that the borrow checker is expecting,
-            // so we need to generate a unique local variable to take the
-            // mutable loan out on, otherwise we get conflicts which don't
-            // actually exist.
-            let me = cx.stmt_let(trait_span, false, blkarg, encoder);
-            let encoder = cx.expr_ident(trait_span, blkarg);
-
-            let fn_emit_enum_variant_arg_path: Vec<_> =
-                cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_enum_variant_arg]);
-
-            let mut stmts = ThinVec::new();
-            if !fields.is_empty() {
-                let last = fields.len() - 1;
-                for (i, &FieldInfo { ref self_expr, span, .. }) in fields.iter().enumerate() {
-                    let self_ref = cx.expr_addr_of(span, self_expr.clone());
-                    let enc = cx
-                        .expr_call(span, fn_path.clone(), thin_vec![self_ref, blkencoder.clone()]);
-                    let lambda = cx.lambda1(span, enc, blkarg);
-
-                    let call = cx.expr_call_global(
-                        span,
-                        fn_emit_enum_variant_arg_path.clone(),
-                        thin_vec![blkencoder.clone(), cx.expr_usize(span, i), lambda],
-                    );
-                    let call = if i != last {
-                        cx.expr_try(span, call)
-                    } else {
-                        cx.expr(span, ExprKind::Ret(Some(call)))
-                    };
-                    stmts.push(cx.stmt_expr(call));
-                }
-            } else {
-                let ok = cx.expr_ok(trait_span, cx.expr_tuple(trait_span, ThinVec::new()));
-                let ret_ok = cx.expr(trait_span, ExprKind::Ret(Some(ok)));
-                stmts.push(cx.stmt_expr(ret_ok));
-            }
-
-            let blk = cx.lambda_stmts_1(trait_span, stmts, blkarg);
-            let name = cx.expr_str(trait_span, variant.ident.name);
-
-            let fn_emit_enum_variant_path: Vec<_> =
-                cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_enum_variant]);
-
-            let call = cx.expr_call_global(trait_span, fn_emit_enum_variant_path, thin_vec![
-                blkencoder,
-                name,
-                cx.expr_usize(trait_span, *idx),
-                cx.expr_usize(trait_span, fields.len()),
-                blk,
-            ]);
-
-            let blk = cx.lambda1(trait_span, call, blkarg);
-            let fn_emit_enum_path: Vec<_> =
-                cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_enum]);
-            let expr = cx.expr_call_global(trait_span, fn_emit_enum_path, thin_vec![
-                encoder,
-                cx.expr_str(trait_span, substr.type_ident.name),
-                blk
-            ]);
-            BlockOrExpr::new_mixed(thin_vec![me], Some(expr))
-        }
-
-        _ => cx.dcx().bug("expected Struct or EnumMatching in derive(Encodable)"),
-    }
-}
diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
index f0a5e44e066..755a733286c 100644
--- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
@@ -311,7 +311,7 @@ pub(crate) enum SubstructureFields<'a> {
     /// Matching variants of the enum: variant index, ast::Variant,
     /// fields: the field name is only non-`None` in the case of a struct
     /// variant.
-    EnumMatching(usize, &'a ast::Variant, Vec<FieldInfo>),
+    EnumMatching(&'a ast::Variant, Vec<FieldInfo>),
 
     /// The discriminant of an enum. The first field is a `FieldInfo` for the discriminants, as
     /// if they were fields. The second field is the expression to combine the
@@ -322,7 +322,7 @@ pub(crate) enum SubstructureFields<'a> {
     StaticStruct(&'a ast::VariantData, StaticFields),
 
     /// A static method where `Self` is an enum.
-    StaticEnum(&'a ast::EnumDef, Vec<(Ident, Span, StaticFields)>),
+    StaticEnum(&'a ast::EnumDef),
 }
 
 /// Combine the values of all the fields together. The last argument is
@@ -1270,7 +1270,7 @@ impl<'a> MethodDef<'a> {
                     trait_,
                     type_ident,
                     nonselflike_args,
-                    &EnumMatching(0, variant, Vec::new()),
+                    &EnumMatching(variant, Vec::new()),
                 );
             }
         }
@@ -1282,9 +1282,8 @@ impl<'a> MethodDef<'a> {
         // where each tuple has length = selflike_args.len()
         let mut match_arms: ThinVec<ast::Arm> = variants
             .iter()
-            .enumerate()
-            .filter(|&(_, v)| !(unify_fieldless_variants && v.data.fields().is_empty()))
-            .map(|(index, variant)| {
+            .filter(|&v| !(unify_fieldless_variants && v.data.fields().is_empty()))
+            .map(|variant| {
                 // A single arm has form (&VariantK, &VariantK, ...) => BodyK
                 // (see "Final wrinkle" note below for why.)
 
@@ -1316,7 +1315,7 @@ impl<'a> MethodDef<'a> {
                 // expressions for referencing every field of every
                 // Self arg, assuming all are instances of VariantK.
                 // Build up code associated with such a case.
-                let substructure = EnumMatching(index, variant, fields);
+                let substructure = EnumMatching(variant, fields);
                 let arm_expr = self
                     .call_substructure_method(
                         cx,
@@ -1344,7 +1343,7 @@ impl<'a> MethodDef<'a> {
                         trait_,
                         type_ident,
                         nonselflike_args,
-                        &EnumMatching(0, v, Vec::new()),
+                        &EnumMatching(v, Vec::new()),
                     )
                     .into_expr(cx, span),
                 )
@@ -1407,21 +1406,12 @@ impl<'a> MethodDef<'a> {
         type_ident: Ident,
         nonselflike_args: &[P<Expr>],
     ) -> BlockOrExpr {
-        let summary = enum_def
-            .variants
-            .iter()
-            .map(|v| {
-                let sp = v.span.with_ctxt(trait_.span.ctxt());
-                let summary = trait_.summarise_struct(cx, &v.data);
-                (v.ident, sp, summary)
-            })
-            .collect();
         self.call_substructure_method(
             cx,
             trait_,
             type_ident,
             nonselflike_args,
-            &StaticEnum(enum_def, summary),
+            &StaticEnum(enum_def),
         )
     }
 }
diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs
index af6dc62db7a..f34a6ae1d98 100644
--- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs
@@ -21,7 +21,6 @@ pub(crate) struct Path {
 #[derive(Clone)]
 pub(crate) enum PathKind {
     Local,
-    Global,
     Std,
 }
 
@@ -57,7 +56,6 @@ impl Path {
         let params = tys.map(GenericArg::Type).collect();
 
         match self.kind {
-            PathKind::Global => cx.path_all(span, true, idents, params),
             PathKind::Local => cx.path_all(span, false, idents, params),
             PathKind::Std => {
                 let def_site = cx.with_def_site_ctxt(DUMMY_SP);
diff --git a/compiler/rustc_builtin_macros/src/deriving/mod.rs b/compiler/rustc_builtin_macros/src/deriving/mod.rs
index ec058b41313..c112589b131 100644
--- a/compiler/rustc_builtin_macros/src/deriving/mod.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/mod.rs
@@ -23,9 +23,7 @@ pub(crate) mod bounds;
 pub(crate) mod clone;
 pub(crate) mod coerce_pointee;
 pub(crate) mod debug;
-pub(crate) mod decodable;
 pub(crate) mod default;
-pub(crate) mod encodable;
 pub(crate) mod hash;
 
 #[path = "cmp/eq.rs"]
diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs
index 6071d36f8eb..dfc8fe2d7f0 100644
--- a/compiler/rustc_builtin_macros/src/lib.rs
+++ b/compiler/rustc_builtin_macros/src/lib.rs
@@ -131,8 +131,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
         Ord: ord::expand_deriving_ord,
         PartialEq: partial_eq::expand_deriving_partial_eq,
         PartialOrd: partial_ord::expand_deriving_partial_ord,
-        RustcDecodable: decodable::expand_deriving_rustc_decodable,
-        RustcEncodable: encodable::expand_deriving_rustc_encodable,
         CoercePointee: coerce_pointee::expand_deriving_coerce_pointee,
     }
 
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index a5bf5e06485..7e09adbea2b 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -314,8 +314,6 @@ symbols! {
         Right,
         Rust,
         RustaceansAreAwesome,
-        RustcDecodable,
-        RustcEncodable,
         RwLock,
         RwLockReadGuard,
         RwLockWriteGuard,
diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs
index ed79ceeb6db..205e9014c62 100644
--- a/library/core/src/macros/mod.rs
+++ b/library/core/src/macros/mod.rs
@@ -1768,30 +1768,4 @@ pub(crate) mod builtin {
     pub macro deref($pat:pat) {
         builtin # deref($pat)
     }
-
-    /// Derive macro for `rustc-serialize`. Should not be used in new code.
-    #[rustc_builtin_macro]
-    #[unstable(
-        feature = "rustc_encodable_decodable",
-        issue = "134301",
-        reason = "derive macro for `rustc-serialize`; should not be used in new code"
-    )]
-    #[deprecated(since = "1.52.0", note = "rustc-serialize is deprecated and no longer supported")]
-    #[doc(hidden)] // While technically stable, using it is unstable, and deprecated. Hide it.
-    pub macro RustcDecodable($item:item) {
-        /* compiler built-in */
-    }
-
-    /// Derive macro for `rustc-serialize`. Should not be used in new code.
-    #[rustc_builtin_macro]
-    #[unstable(
-        feature = "rustc_encodable_decodable",
-        issue = "134301",
-        reason = "derive macro for `rustc-serialize`; should not be used in new code"
-    )]
-    #[deprecated(since = "1.52.0", note = "rustc-serialize is deprecated and no longer supported")]
-    #[doc(hidden)] // While technically stable, using it is unstable, and deprecated. Hide it.
-    pub macro RustcEncodable($item:item) {
-        /* compiler built-in */
-    }
 }
diff --git a/library/core/src/prelude/mod.rs b/library/core/src/prelude/mod.rs
index 98f061d463a..0ab97f5bbd5 100644
--- a/library/core/src/prelude/mod.rs
+++ b/library/core/src/prelude/mod.rs
@@ -18,15 +18,6 @@ mod common;
 pub mod v1 {
     #[stable(feature = "rust1", since = "1.0.0")]
     pub use super::common::*;
-
-    // Do not `doc(inline)` these `doc(hidden)` items.
-    #[unstable(
-        feature = "rustc_encodable_decodable",
-        issue = "134301",
-        reason = "derive macro for `rustc-serialize`; should not be used in new code"
-    )]
-    #[allow(deprecated)]
-    pub use crate::macros::builtin::{RustcDecodable, RustcEncodable};
 }
 
 /// The 2015 version of the core prelude.
diff --git a/library/std/src/prelude/mod.rs b/library/std/src/prelude/mod.rs
index b7efffcc446..14e6c2715df 100644
--- a/library/std/src/prelude/mod.rs
+++ b/library/std/src/prelude/mod.rs
@@ -120,15 +120,6 @@ mod common;
 pub mod v1 {
     #[stable(feature = "rust1", since = "1.0.0")]
     pub use super::common::*;
-
-    // Do not `doc(inline)` these `doc(hidden)` items.
-    #[unstable(
-        feature = "rustc_encodable_decodable",
-        issue = "134301",
-        reason = "derive macro for `rustc-serialize`; should not be used in new code"
-    )]
-    #[allow(deprecated)]
-    pub use core::prelude::v1::{RustcDecodable, RustcEncodable};
 }
 
 /// The 2015 version of the prelude of The Rust Standard Library.