From cbcef3effcf64bd0d89ea2dc8973e18d7fcf94c3 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Thu, 11 Jun 2020 15:49:57 +0100 Subject: [PATCH] Rework `rustc_serialize` - Move the type parameter from `encode` and `decode` methods to the trait. - Remove `UseSpecialized(En|De)codable` traits. - Remove blanket impls for references. - Add `RefDecodable` trait to allow deserializing to arena-allocated references safely. - Remove ability to (de)serialize HIR. - Create proc-macros `(Ty)?(En|De)codable` to help implement these new traits. --- Cargo.lock | 9 + src/librustc_ast/ast.rs | 238 ++++---- src/librustc_ast/crate_disambiguator.rs | 2 +- src/librustc_ast/lib.rs | 3 +- src/librustc_ast/node_id.rs | 14 - src/librustc_ast/ptr.rs | 16 +- src/librustc_ast/token.rs | 18 +- src/librustc_ast/tokenstream.rs | 8 +- src/librustc_attr/builtin.rs | 17 +- src/librustc_attr/lib.rs | 3 +- src/librustc_codegen_ssa/Cargo.toml | 1 + src/librustc_codegen_ssa/back/linker.rs | 2 +- src/librustc_codegen_ssa/lib.rs | 10 +- src/librustc_data_structures/Cargo.toml | 1 + src/librustc_data_structures/fingerprint.rs | 48 +- src/librustc_data_structures/lib.rs | 2 + src/librustc_data_structures/sorted_map.rs | 13 +- src/librustc_data_structures/svh.rs | 8 +- src/librustc_data_structures/thin_vec.rs | 2 +- .../transitive_relation.rs | 69 +-- src/librustc_errors/Cargo.toml | 1 + src/librustc_errors/diagnostic.rs | 6 +- src/librustc_errors/json.rs | 12 +- src/librustc_errors/json/tests.rs | 4 +- src/librustc_errors/lib.rs | 17 +- src/librustc_errors/snippet.rs | 2 +- src/librustc_expand/Cargo.toml | 1 + src/librustc_expand/lib.rs | 3 + src/librustc_expand/mbe.rs | 10 +- src/librustc_hir/def.rs | 10 +- src/librustc_hir/definitions.rs | 10 +- src/librustc_hir/hir.rs | 225 ++++---- src/librustc_hir/hir_id.rs | 3 +- src/librustc_hir/lang_items.rs | 2 +- src/librustc_hir/lib.rs | 4 +- src/librustc_incremental/Cargo.toml | 1 + src/librustc_incremental/persist/data.rs | 3 +- src/librustc_index/Cargo.toml | 3 +- src/librustc_index/bit_set.rs | 8 +- src/librustc_index/vec.rs | 33 +- src/librustc_infer/infer/free_regions.rs | 9 +- src/librustc_macros/src/lib.rs | 7 + src/librustc_macros/src/serialize.rs | 290 ++++++++++ src/librustc_macros/src/symbols.rs | 2 +- src/librustc_metadata/Cargo.toml | 1 + src/librustc_metadata/lib.rs | 2 + src/librustc_metadata/rmeta/decoder.rs | 260 +++++---- src/librustc_metadata/rmeta/encoder.rs | 224 ++++---- src/librustc_metadata/rmeta/mod.rs | 33 +- src/librustc_metadata/rmeta/table.rs | 6 +- src/librustc_middle/arena.rs | 2 +- src/librustc_middle/dep_graph/dep_node.rs | 3 +- src/librustc_middle/hir/exports.rs | 2 +- src/librustc_middle/hir/place.rs | 10 +- src/librustc_middle/infer/canonical.rs | 13 +- .../middle/codegen_fn_attrs.rs | 4 +- src/librustc_middle/middle/cstore.rs | 14 +- .../middle/dependency_format.rs | 2 +- .../middle/exported_symbols.rs | 4 +- src/librustc_middle/middle/region.rs | 6 +- .../middle/resolve_lifetime.rs | 6 +- .../mir/interpret/allocation.rs | 8 +- src/librustc_middle/mir/interpret/error.rs | 4 +- src/librustc_middle/mir/interpret/mod.rs | 19 +- src/librustc_middle/mir/interpret/pointer.rs | 2 +- src/librustc_middle/mir/interpret/value.rs | 6 +- src/librustc_middle/mir/mod.rs | 92 +-- src/librustc_middle/mir/mono.rs | 2 +- src/librustc_middle/mir/predecessors.rs | 8 +- src/librustc_middle/mir/query.rs | 26 +- src/librustc_middle/mir/terminator/mod.rs | 4 +- src/librustc_middle/traits/mod.rs | 20 +- .../traits/specialization_graph.rs | 4 +- src/librustc_middle/ty/adjustment.rs | 18 +- src/librustc_middle/ty/binding.rs | 2 +- src/librustc_middle/ty/cast.rs | 2 +- src/librustc_middle/ty/codec.rs | 526 +++++++----------- src/librustc_middle/ty/consts.rs | 2 +- src/librustc_middle/ty/consts/kind.rs | 4 +- src/librustc_middle/ty/context.rs | 12 +- src/librustc_middle/ty/fast_reject.rs | 2 +- src/librustc_middle/ty/instance.rs | 4 +- src/librustc_middle/ty/layout.rs | 2 +- src/librustc_middle/ty/list.rs | 11 +- src/librustc_middle/ty/mod.rs | 75 +-- src/librustc_middle/ty/query/on_disk_cache.rs | 375 ++++++------- src/librustc_middle/ty/sty.rs | 50 +- src/librustc_middle/ty/subst.rs | 19 +- src/librustc_middle/ty/trait_def.rs | 2 +- src/librustc_middle/ty/util.rs | 2 +- src/librustc_query_system/Cargo.toml | 1 + .../dep_graph/dep_node.rs | 5 +- src/librustc_query_system/dep_graph/graph.rs | 2 +- src/librustc_query_system/dep_graph/prev.rs | 2 +- .../dep_graph/serialized.rs | 2 +- src/librustc_query_system/lib.rs | 2 + src/librustc_serialize/collection_impls.rs | 134 ++--- src/librustc_serialize/json.rs | 14 +- src/librustc_serialize/lib.rs | 4 - src/librustc_serialize/serialize.rs | 386 +++++-------- src/librustc_session/Cargo.toml | 1 + src/librustc_session/config.rs | 10 +- src/librustc_session/lib.rs | 2 + src/librustc_session/search_paths.rs | 2 +- src/librustc_session/utils.rs | 2 +- src/librustc_span/def_id.rs | 73 ++- src/librustc_span/edition.rs | 2 +- src/librustc_span/hygiene.rs | 49 +- src/librustc_span/lib.rs | 56 +- src/librustc_span/source_map.rs | 4 +- src/librustc_span/symbol.rs | 35 +- src/librustc_target/abi/mod.rs | 6 +- src/librustc_target/asm/mod.rs | 42 +- src/librustc_target/lib.rs | 3 +- src/librustc_target/spec/abi.rs | 4 +- src/librustc_target/spec/mod.rs | 8 +- 116 files changed, 1933 insertions(+), 1963 deletions(-) create mode 100644 src/librustc_macros/src/serialize.rs diff --git a/Cargo.lock b/Cargo.lock index f6b5b317646..564c3da5223 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3334,6 +3334,7 @@ dependencies = [ "rustc_hir", "rustc_incremental", "rustc_index", + "rustc_macros", "rustc_middle", "rustc_serialize", "rustc_session", @@ -3364,6 +3365,7 @@ dependencies = [ "rustc-rayon-core", "rustc_graphviz", "rustc_index", + "rustc_macros", "rustc_serialize", "smallvec 1.4.0", "stable_deref_trait", @@ -3416,6 +3418,7 @@ dependencies = [ "annotate-snippets 0.8.0", "atty", "rustc_data_structures", + "rustc_macros", "rustc_serialize", "rustc_span", "termcolor", @@ -3437,6 +3440,7 @@ dependencies = [ "rustc_errors", "rustc_feature", "rustc_lexer", + "rustc_macros", "rustc_parse", "rustc_serialize", "rustc_session", @@ -3499,6 +3503,7 @@ dependencies = [ "rustc_fs_util", "rustc_graphviz", "rustc_hir", + "rustc_macros", "rustc_middle", "rustc_serialize", "rustc_session", @@ -3511,6 +3516,7 @@ name = "rustc_index" version = "0.0.0" dependencies = [ "arrayvec 0.5.1", + "rustc_macros", "rustc_serialize", ] @@ -3640,6 +3646,7 @@ dependencies = [ "rustc_hir", "rustc_hir_pretty", "rustc_index", + "rustc_macros", "rustc_middle", "rustc_serialize", "rustc_session", @@ -3815,6 +3822,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_index", + "rustc_macros", "rustc_serialize", "rustc_span", "smallvec 1.4.0", @@ -3884,6 +3892,7 @@ dependencies = [ "rustc_errors", "rustc_feature", "rustc_fs_util", + "rustc_macros", "rustc_serialize", "rustc_span", "rustc_target", diff --git a/src/librustc_ast/ast.rs b/src/librustc_ast/ast.rs index a0541158bc2..6dff02486ff 100644 --- a/src/librustc_ast/ast.rs +++ b/src/librustc_ast/ast.rs @@ -53,7 +53,7 @@ mod tests; /// ``` /// /// `'outer` is a label. -#[derive(Clone, RustcEncodable, RustcDecodable, Copy, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Copy, HashStable_Generic)] pub struct Label { pub ident: Ident, } @@ -66,7 +66,7 @@ impl fmt::Debug for Label { /// A "Lifetime" is an annotation of the scope in which variable /// can be used, e.g. `'a` in `&'a i32`. -#[derive(Clone, RustcEncodable, RustcDecodable, Copy)] +#[derive(Clone, Encodable, Decodable, Copy)] pub struct Lifetime { pub id: NodeId, pub ident: Ident, @@ -90,7 +90,7 @@ impl fmt::Display for Lifetime { /// along with a bunch of supporting information. /// /// E.g., `std::cmp::PartialEq`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Path { pub span: Span, /// The segments in the path: the things separated by `::`. @@ -128,7 +128,7 @@ impl Path { /// A segment of a path: an identifier, an optional lifetime, and a set of types. /// /// E.g., `std`, `String` or `Box`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct PathSegment { /// The identifier portion of this path segment. pub ident: Ident, @@ -156,7 +156,7 @@ impl PathSegment { /// The arguments of a path segment. /// /// E.g., `` as in `Foo` or `(A, B)` as in `Foo(A, B)`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum GenericArgs { /// The `<'a, A, B, C>` in `foo::bar::baz::<'a, A, B, C>`. AngleBracketed(AngleBracketedArgs), @@ -188,7 +188,7 @@ impl GenericArgs { } /// Concrete argument in the sequence of generic args. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum GenericArg { /// `'a` in `Foo<'a>` Lifetime(Lifetime), @@ -209,7 +209,7 @@ impl GenericArg { } /// A path like `Foo<'a, T>`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default)] +#[derive(Clone, Encodable, Decodable, Debug, Default)] pub struct AngleBracketedArgs { /// The overall span. pub span: Span, @@ -219,7 +219,7 @@ pub struct AngleBracketedArgs { /// Either an argument for a parameter e.g., `'a`, `Vec`, `0`, /// or a constraint on an associated item, e.g., `Item = String` or `Item: Bound`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum AngleBracketedArg { /// Argument for a generic parameter. Arg(GenericArg), @@ -240,7 +240,7 @@ impl Into>> for ParenthesizedArgs { } /// A path like `Foo(A, B) -> C`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct ParenthesizedArgs { /// Overall span pub span: Span, @@ -269,7 +269,7 @@ pub use crate::node_id::{NodeId, CRATE_NODE_ID, DUMMY_NODE_ID}; /// A modifier on a bound, e.g., `?Sized` or `?const Trait`. /// /// Negative bounds should also be handled here. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)] pub enum TraitBoundModifier { /// No modifiers None, @@ -290,7 +290,7 @@ pub enum TraitBoundModifier { /// `typeck::collect::compute_bounds` matches these against /// the "special" built-in traits (see `middle::lang_items`) and /// detects `Copy`, `Send` and `Sync`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum GenericBound { Trait(PolyTraitRef, TraitBoundModifier), Outlives(Lifetime), @@ -357,7 +357,7 @@ impl fmt::Display for ParamKindOrd { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum GenericParamKind { /// A lifetime definition (e.g., `'a: 'b + 'c + 'd`). Lifetime, @@ -371,7 +371,7 @@ pub enum GenericParamKind { }, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct GenericParam { pub id: NodeId, pub ident: Ident, @@ -383,7 +383,7 @@ pub struct GenericParam { /// Represents lifetime, type and const parameters attached to a declaration of /// a function, enum, trait, etc. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Generics { pub params: Vec, pub where_clause: WhereClause, @@ -406,7 +406,7 @@ impl Default for Generics { } /// A where-clause in a definition. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct WhereClause { /// `true` if we ate a `where` token: this can happen /// if we parsed no predicates (e.g. `struct Foo where {}`). @@ -418,7 +418,7 @@ pub struct WhereClause { } /// A single predicate in a where-clause. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum WherePredicate { /// A type binding (e.g., `for<'c> Foo: Send + Clone + 'c`). BoundPredicate(WhereBoundPredicate), @@ -441,7 +441,7 @@ impl WherePredicate { /// A type bound. /// /// E.g., `for<'c> Foo: Send + Clone + 'c`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct WhereBoundPredicate { pub span: Span, /// Any generics from a `for` binding. @@ -455,7 +455,7 @@ pub struct WhereBoundPredicate { /// A lifetime predicate. /// /// E.g., `'a: 'b + 'c`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct WhereRegionPredicate { pub span: Span, pub lifetime: Lifetime, @@ -465,7 +465,7 @@ pub struct WhereRegionPredicate { /// An equality predicate (unsupported). /// /// E.g., `T = int`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct WhereEqPredicate { pub id: NodeId, pub span: Span, @@ -473,7 +473,7 @@ pub struct WhereEqPredicate { pub rhs_ty: P, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Crate { pub module: Mod, pub attrs: Vec, @@ -490,7 +490,7 @@ pub struct Crate { /// Possible values inside of compile-time attribute lists. /// /// E.g., the '..' in `#[name(..)]`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub enum NestedMetaItem { /// A full MetaItem, for recursive meta items. MetaItem(MetaItem), @@ -503,7 +503,7 @@ pub enum NestedMetaItem { /// A spanned compile-time attribute item. /// /// E.g., `#[test]`, `#[derive(..)]`, `#[rustfmt::skip]` or `#[feature = "foo"]`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub struct MetaItem { pub path: Path, pub kind: MetaItemKind, @@ -513,7 +513,7 @@ pub struct MetaItem { /// A compile-time attribute item. /// /// E.g., `#[test]`, `#[derive(..)]` or `#[feature = "foo"]`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub enum MetaItemKind { /// Word meta item. /// @@ -532,7 +532,7 @@ pub enum MetaItemKind { /// A block (`{ .. }`). /// /// E.g., `{ .. }` as in `fn foo() { .. }`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Block { /// The statements in the block. pub stmts: Vec, @@ -545,7 +545,7 @@ pub struct Block { /// A match pattern. /// /// Patterns appear in match statements and some other contexts, such as `let` and `if let`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Pat { pub id: NodeId, pub kind: PatKind, @@ -636,7 +636,7 @@ impl Pat { /// Patterns like the fields of Foo `{ x, ref y, ref mut z }` /// are treated the same as` x: x, y: ref y, z: ref mut z`, /// except is_shorthand is true -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct FieldPat { /// The identifier for the field pub ident: Ident, @@ -649,19 +649,19 @@ pub struct FieldPat { pub is_placeholder: bool, } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy)] pub enum BindingMode { ByRef(Mutability), ByValue(Mutability), } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum RangeEnd { Included(RangeSyntax), Excluded, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum RangeSyntax { /// `...` DotDotDot, @@ -669,7 +669,7 @@ pub enum RangeSyntax { DotDotEq, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum PatKind { /// Represents a wildcard pattern (`_`). Wild, @@ -736,8 +736,8 @@ pub enum PatKind { MacCall(MacCall), } -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug, Copy)] -#[derive(HashStable_Generic)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] +#[derive(HashStable_Generic, Encodable, Decodable)] pub enum Mutability { Mut, Not, @@ -770,7 +770,7 @@ impl Mutability { /// The kind of borrow in an `AddrOf` expression, /// e.g., `&place` or `&raw const place`. #[derive(Clone, Copy, PartialEq, Eq, Debug)] -#[derive(RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Encodable, Decodable, HashStable_Generic)] pub enum BorrowKind { /// A normal borrow, `&$expr` or `&mut $expr`. /// The resulting type is either `&'a T` or `&'a mut T` @@ -782,7 +782,7 @@ pub enum BorrowKind { Raw, } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy)] pub enum BinOpKind { /// The `+` operator (addition) Add, @@ -881,7 +881,7 @@ pub type BinOp = Spanned; /// Unary operator. /// /// Note that `&data` is not an operator, it's an `AddrOf` expression. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, Encodable, Decodable, Debug, Copy)] pub enum UnOp { /// The `*` operator for dereferencing Deref, @@ -910,7 +910,7 @@ impl UnOp { } /// A statement -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Stmt { pub id: NodeId, pub kind: StmtKind, @@ -944,7 +944,7 @@ impl Stmt { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum StmtKind { /// A local (let) binding. Local(P), @@ -960,7 +960,7 @@ pub enum StmtKind { MacCall(P<(MacCall, MacStmtStyle, AttrVec)>), } -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)] pub enum MacStmtStyle { /// The macro statement had a trailing semicolon (e.g., `foo! { ... };` /// `foo!(...);`, `foo![...];`). @@ -974,7 +974,7 @@ pub enum MacStmtStyle { } /// Local represents a `let` statement, e.g., `let : = ;`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Local { pub id: NodeId, pub pat: P, @@ -995,7 +995,7 @@ pub struct Local { /// _ => { println!("no match!") }, /// } /// ``` -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Arm { pub attrs: Vec, /// Match arm pattern, e.g. `10` in `match foo { 10 => {}, _ => {} }` @@ -1010,7 +1010,7 @@ pub struct Arm { } /// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Field { pub attrs: AttrVec, pub id: NodeId, @@ -1021,13 +1021,13 @@ pub struct Field { pub is_placeholder: bool, } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy)] pub enum BlockCheckMode { Default, Unsafe(UnsafeSource), } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy)] pub enum UnsafeSource { CompilerGenerated, UserProvided, @@ -1038,14 +1038,14 @@ pub enum UnsafeSource { /// These are usually found nested inside types (e.g., array lengths) /// or expressions (e.g., repeat counts), and also used to define /// explicit discriminant values for enum variants. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct AnonConst { pub id: NodeId, pub value: P, } /// An expression. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Expr { pub id: NodeId, pub kind: ExprKind, @@ -1204,7 +1204,7 @@ impl Expr { } /// Limit types of a range (inclusive or exclusive) -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug)] pub enum RangeLimits { /// Inclusive at the beginning, exclusive at the end HalfOpen, @@ -1212,7 +1212,7 @@ pub enum RangeLimits { Closed, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum ExprKind { /// A `box x` expression. Box(P), @@ -1369,7 +1369,7 @@ pub enum ExprKind { /// ^~~~~ ^ /// ty position = 0 /// ``` -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct QSelf { pub ty: P, @@ -1381,7 +1381,7 @@ pub struct QSelf { } /// A capture clause used in closures and `async` blocks. -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub enum CaptureBy { /// `move |x| y + x`. Value, @@ -1391,7 +1391,7 @@ pub enum CaptureBy { /// The movability of a generator / closure literal: /// whether a generator contains self-references, causing it to be `!Unpin`. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable, Debug, Copy)] #[derive(HashStable_Generic)] pub enum Movability { /// May contain self-references, `!Unpin`. @@ -1402,7 +1402,7 @@ pub enum Movability { /// Represents a macro invocation. The `path` indicates which macro /// is being invoked, and the `args` are arguments passed to it. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct MacCall { pub path: Path, pub args: P, @@ -1416,7 +1416,7 @@ impl MacCall { } /// Arguments passed to an attribute or a function-like macro. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub enum MacArgs { /// No arguments - `#[attr]`. Empty, @@ -1477,7 +1477,7 @@ impl MacArgs { } } -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)] pub enum MacDelimiter { Parenthesis, Bracket, @@ -1504,14 +1504,14 @@ impl MacDelimiter { } /// Represents a macro definition. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub struct MacroDef { pub body: P, /// `true` if macro was defined with `macro_rules`. pub macro_rules: bool, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, Eq, PartialEq)] +#[derive(Clone, Encodable, Decodable, Debug, Copy, Hash, Eq, PartialEq)] #[derive(HashStable_Generic)] pub enum StrStyle { /// A regular string, like `"foo"`. @@ -1523,7 +1523,7 @@ pub enum StrStyle { } /// An AST literal. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub struct Lit { /// The original literal token as written in source code. pub token: token::Lit, @@ -1535,7 +1535,7 @@ pub struct Lit { } /// Same as `Lit`, but restricted to string literals. -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, Encodable, Decodable, Debug)] pub struct StrLit { /// The original literal token as written in source code. pub style: StrStyle, @@ -1562,7 +1562,7 @@ impl StrLit { } /// Type of the integer literal based on provided suffix. -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, Eq, PartialEq)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, Hash, Eq, PartialEq)] #[derive(HashStable_Generic)] pub enum LitIntType { /// e.g. `42_i32`. @@ -1574,7 +1574,7 @@ pub enum LitIntType { } /// Type of the float literal based on provided suffix. -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, Hash, Eq, PartialEq)] +#[derive(Clone, Copy, Encodable, Decodable, Debug, Hash, Eq, PartialEq)] #[derive(HashStable_Generic)] pub enum LitFloatType { /// A float literal with a suffix (`1f32` or `1E10f32`). @@ -1586,7 +1586,7 @@ pub enum LitFloatType { /// Literal kind. /// /// E.g., `"foo"`, `42`, `12.34`, or `bool`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Hash, Eq, PartialEq, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, Hash, Eq, PartialEq, HashStable_Generic)] pub enum LitKind { /// A string literal (`"foo"`). Str(Symbol, StrStyle), @@ -1658,7 +1658,7 @@ impl LitKind { // N.B., If you change this, you'll probably want to change the corresponding // type structure in `middle/ty.rs` as well. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct MutTy { pub ty: P, pub mutbl: Mutability, @@ -1666,14 +1666,14 @@ pub struct MutTy { /// Represents a function's signature in a trait declaration, /// trait implementation, or free function. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct FnSig { pub header: FnHeader, pub decl: P, } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] -#[derive(HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Encodable, Decodable, HashStable_Generic)] pub enum FloatTy { F32, F64, @@ -1702,8 +1702,8 @@ impl FloatTy { } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] -#[derive(HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Encodable, Decodable, HashStable_Generic)] pub enum IntTy { Isize, I8, @@ -1767,8 +1767,8 @@ impl IntTy { } } -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Copy, Debug)] -#[derive(HashStable_Generic)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Debug)] +#[derive(Encodable, Decodable, HashStable_Generic)] pub enum UintTy { Usize, U8, @@ -1831,7 +1831,7 @@ impl UintTy { /// A constraint on an associated type (e.g., `A = Bar` in `Foo` or /// `A: TraitA + TraitB` in `Foo`). -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct AssocTyConstraint { pub id: NodeId, pub ident: Ident, @@ -1840,7 +1840,7 @@ pub struct AssocTyConstraint { } /// The kinds of an `AssocTyConstraint`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum AssocTyConstraintKind { /// E.g., `A = Bar` in `Foo`. Equality { ty: P }, @@ -1848,14 +1848,14 @@ pub enum AssocTyConstraintKind { Bound { bounds: GenericBounds }, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Ty { pub id: NodeId, pub kind: TyKind, pub span: Span, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct BareFnTy { pub unsafety: Unsafe, pub ext: Extern, @@ -1864,7 +1864,7 @@ pub struct BareFnTy { } /// The various kinds of type recognized by the compiler. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum TyKind { /// A variable-length slice (`[T]`). Slice(P), @@ -1923,7 +1923,7 @@ impl TyKind { } /// Syntax used to declare a trait object. -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)] pub enum TraitObjectSyntax { Dyn, None, @@ -1932,14 +1932,14 @@ pub enum TraitObjectSyntax { /// Inline assembly operand explicit register or register class. /// /// E.g., `"eax"` as in `asm!("mov eax, 2", out("eax") result)`. -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, Encodable, Decodable, Debug)] pub enum InlineAsmRegOrRegClass { Reg(Symbol), RegClass(Symbol), } bitflags::bitflags! { - #[derive(RustcEncodable, RustcDecodable, HashStable_Generic)] + #[derive(Encodable, Decodable, HashStable_Generic)] pub struct InlineAsmOptions: u8 { const PURE = 1 << 0; const NOMEM = 1 << 1; @@ -1951,7 +1951,7 @@ bitflags::bitflags! { } } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub enum InlineAsmTemplatePiece { String(String), Placeholder { operand_idx: usize, modifier: Option, span: Span }, @@ -1995,7 +1995,7 @@ impl InlineAsmTemplatePiece { /// Inline assembly operand. /// /// E.g., `out("eax") result` as in `asm!("mov eax, 2", out("eax") result)`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum InlineAsmOperand { In { reg: InlineAsmRegOrRegClass, @@ -2028,7 +2028,7 @@ pub enum InlineAsmOperand { /// Inline assembly. /// /// E.g., `asm!("NOP");`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct InlineAsm { pub template: Vec, pub operands: Vec<(InlineAsmOperand, Span)>, @@ -2039,7 +2039,7 @@ pub struct InlineAsm { /// Inline assembly dialect. /// /// E.g., `"intel"` as in `llvm_asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, HashStable_Generic)] pub enum LlvmAsmDialect { Att, Intel, @@ -2048,7 +2048,7 @@ pub enum LlvmAsmDialect { /// LLVM-style inline assembly. /// /// E.g., `"={eax}"(result)` as in `llvm_asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct LlvmInlineAsmOutput { pub constraint: Symbol, pub expr: P, @@ -2059,7 +2059,7 @@ pub struct LlvmInlineAsmOutput { /// LLVM-style inline assembly. /// /// E.g., `llvm_asm!("NOP");`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct LlvmInlineAsm { pub asm: Symbol, pub asm_str_style: StrStyle, @@ -2074,7 +2074,7 @@ pub struct LlvmInlineAsm { /// A parameter in a function header. /// /// E.g., `bar: usize` as in `fn foo(bar: usize)`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Param { pub attrs: AttrVec, pub ty: P, @@ -2087,7 +2087,7 @@ pub struct Param { /// Alternative representation for `Arg`s describing `self` parameter of methods. /// /// E.g., `&mut self` as in `fn foo(&mut self)`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum SelfKind { /// `self`, `mut self` Value(Mutability), @@ -2165,7 +2165,7 @@ impl Param { /// /// Please note that it's different from `FnHeader` structure /// which contains metadata about function safety, asyncness, constness and ABI. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct FnDecl { pub inputs: Vec, pub output: FnRetTy, @@ -2187,20 +2187,20 @@ impl FnDecl { } /// Is the trait definition an auto trait? -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub enum IsAuto { Yes, No, } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable, Debug)] #[derive(HashStable_Generic)] pub enum Unsafe { Yes(Span), No, } -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, Encodable, Decodable, Debug)] pub enum Async { Yes { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId }, No, @@ -2220,7 +2220,7 @@ impl Async { } } -#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable, Debug)] #[derive(HashStable_Generic)] pub enum Const { Yes(Span), @@ -2229,13 +2229,13 @@ pub enum Const { /// Item defaultness. /// For details see the [RFC #2532](https://github.com/rust-lang/rfcs/pull/2532). -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub enum Defaultness { Default(Span), Final, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)] pub enum ImplPolarity { /// `impl Trait for Type` Positive, @@ -2252,7 +2252,7 @@ impl fmt::Debug for ImplPolarity { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum FnRetTy { /// Returns type is not specified. /// @@ -2275,7 +2275,7 @@ impl FnRetTy { /// Module declaration. /// /// E.g., `mod foo;` or `mod foo { .. }`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default)] +#[derive(Clone, Encodable, Decodable, Debug, Default)] pub struct Mod { /// A span from the first token past `{` to the last token until `}`. /// For `mod foo;`, the inner span ranges from the first token @@ -2289,7 +2289,7 @@ pub struct Mod { /// Foreign module declaration. /// /// E.g., `extern { .. }` or `extern C { .. }`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct ForeignMod { pub abi: Option, pub items: Vec>, @@ -2298,17 +2298,17 @@ pub struct ForeignMod { /// Global inline assembly. /// /// Also known as "module-level assembly" or "file-scoped assembly". -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, Encodable, Decodable, Debug, Copy)] pub struct GlobalAsm { pub asm: Symbol, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct EnumDef { pub variants: Vec, } /// Enum variant. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Variant { /// Attributes of the variant. pub attrs: Vec, @@ -2330,7 +2330,7 @@ pub struct Variant { } /// Part of `use` item to the right of its prefix. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum UseTreeKind { /// `use prefix` or `use prefix as rename` /// @@ -2345,7 +2345,7 @@ pub enum UseTreeKind { /// A tree of paths sharing common prefixes. /// Used in `use` items both at top-level and inside of braces in import groups. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct UseTree { pub prefix: Path, pub kind: UseTreeKind, @@ -2367,7 +2367,7 @@ impl UseTree { /// Distinguishes between `Attribute`s that decorate items and Attributes that /// are contained as statements within items. These two cases need to be /// distinguished for pretty-printing. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, HashStable_Generic)] pub enum AttrStyle { Outer, Inner, @@ -2380,19 +2380,19 @@ rustc_index::newtype_index! { } } -impl rustc_serialize::Encodable for AttrId { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl rustc_serialize::Encodable for AttrId { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_unit() } } -impl rustc_serialize::Decodable for AttrId { - fn decode(d: &mut D) -> Result { +impl rustc_serialize::Decodable for AttrId { + fn decode(d: &mut D) -> Result { d.read_nil().map(|_| crate::attr::mk_attr_id()) } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub struct AttrItem { pub path: Path, pub args: MacArgs, @@ -2402,7 +2402,7 @@ pub struct AttrItem { pub type AttrVec = ThinVec; /// Metadata associated with an item. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Attribute { pub kind: AttrKind, pub id: AttrId, @@ -2412,7 +2412,7 @@ pub struct Attribute { pub span: Span, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum AttrKind { /// A normal attribute. Normal(AttrItem), @@ -2429,13 +2429,13 @@ pub enum AttrKind { /// that the `ref_id` is for. The `impl_id` maps to the "self type" of this impl. /// If this impl is an `ItemKind::Impl`, the `impl_id` is redundant (it could be the /// same as the impl's `NodeId`). -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct TraitRef { pub path: Path, pub ref_id: NodeId, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct PolyTraitRef { /// The `'a` in `<'a> Foo<&'a T>`. pub bound_generic_params: Vec, @@ -2456,7 +2456,7 @@ impl PolyTraitRef { } } -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, Encodable, Decodable, Debug, HashStable_Generic)] pub enum CrateSugar { /// Source is `pub(crate)`. PubCrate, @@ -2467,7 +2467,7 @@ pub enum CrateSugar { pub type Visibility = Spanned; -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum VisibilityKind { Public, Crate(CrateSugar), @@ -2484,7 +2484,7 @@ impl VisibilityKind { /// Field of a struct. /// /// E.g., `bar: usize` as in `struct Foo { bar: usize }`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct StructField { pub attrs: Vec, pub id: NodeId, @@ -2497,7 +2497,7 @@ pub struct StructField { } /// Fields and constructor ids of enum variants and structs. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum VariantData { /// Struct variant. /// @@ -2532,7 +2532,7 @@ impl VariantData { } /// An item definition. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct Item { pub attrs: Vec, pub id: NodeId, @@ -2569,7 +2569,7 @@ impl> Item { } /// `extern` qualifier on a function item or function type. -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, Encodable, Decodable, Debug)] pub enum Extern { None, Implicit, @@ -2586,7 +2586,7 @@ impl Extern { /// /// All the information between the visibility and the name of the function is /// included in this struct (e.g., `async unsafe fn` or `const extern "C" fn`). -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, Encodable, Decodable, Debug)] pub struct FnHeader { pub unsafety: Unsafe, pub asyncness: Async, @@ -2616,7 +2616,7 @@ impl Default for FnHeader { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum ItemKind { /// An `extern crate` item, with the optional *original* crate name if the crate was renamed. /// @@ -2755,7 +2755,7 @@ pub type AssocItem = Item; /// In an implementation, all items must be provided. /// The `Option`s below denote the bodies, where `Some(_)` /// means "provided" and conversely `None` means "required". -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum AssocItemKind { /// An associated constant, `const $ident: $ty $def?;` where `def ::= "=" $expr? ;`. /// If `def` is parsed, then the constant is provided, and otherwise required. @@ -2803,7 +2803,7 @@ impl TryFrom for AssocItemKind { } /// An item in `extern` block. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub enum ForeignItemKind { /// A foreign static item (`static FOO: u8`). Static(P, Mutability, Option>), diff --git a/src/librustc_ast/crate_disambiguator.rs b/src/librustc_ast/crate_disambiguator.rs index 95d4c09dac3..bd7d8516714 100644 --- a/src/librustc_ast/crate_disambiguator.rs +++ b/src/librustc_ast/crate_disambiguator.rs @@ -9,7 +9,7 @@ use std::fmt; /// Hash value constructed out of all the `-C metadata` arguments passed to the /// compiler. Together with the crate-name forms a unique global identifier for /// the crate. -#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy, RustcEncodable, RustcDecodable)] +#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy, Encodable, Decodable)] pub struct CrateDisambiguator(Fingerprint); impl CrateDisambiguator { diff --git a/src/librustc_ast/lib.rs b/src/librustc_ast/lib.rs index 3f876169d22..fb5ce311826 100644 --- a/src/librustc_ast/lib.rs +++ b/src/librustc_ast/lib.rs @@ -18,8 +18,7 @@ #![feature(unicode_internals)] #![recursion_limit = "256"] -// FIXME(#56935): Work around ICEs during cross-compilation. -#[allow(unused)] +#[macro_use] extern crate rustc_macros; #[macro_export] diff --git a/src/librustc_ast/node_id.rs b/src/librustc_ast/node_id.rs index cd562c48e91..1035e945538 100644 --- a/src/librustc_ast/node_id.rs +++ b/src/librustc_ast/node_id.rs @@ -1,10 +1,8 @@ -use rustc_serialize::{Decoder, Encoder}; use rustc_span::ExpnId; use std::fmt; rustc_index::newtype_index! { pub struct NodeId { - ENCODABLE = custom DEBUG_FORMAT = "NodeId({})" } } @@ -34,15 +32,3 @@ impl fmt::Display for NodeId { fmt::Display::fmt(&self.as_u32(), f) } } - -impl rustc_serialize::UseSpecializedEncodable for NodeId { - fn default_encode(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_u32(self.as_u32()) - } -} - -impl rustc_serialize::UseSpecializedDecodable for NodeId { - fn default_decode(d: &mut D) -> Result { - d.read_u32().map(NodeId::from_u32) - } -} diff --git a/src/librustc_ast/ptr.rs b/src/librustc_ast/ptr.rs index 4597624ef88..e4a3cccb7ea 100644 --- a/src/librustc_ast/ptr.rs +++ b/src/librustc_ast/ptr.rs @@ -114,14 +114,14 @@ impl fmt::Pointer for P { } } -impl Decodable for P { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for P { + fn decode(d: &mut D) -> Result, D::Error> { Decodable::decode(d).map(P) } } -impl Encodable for P { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl> Encodable for P { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { (**self).encode(s) } } @@ -197,14 +197,14 @@ impl<'a, T> IntoIterator for &'a P<[T]> { } } -impl Encodable for P<[T]> { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl> Encodable for P<[T]> { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { Encodable::encode(&**self, s) } } -impl Decodable for P<[T]> { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for P<[T]> { + fn decode(d: &mut D) -> Result, D::Error> { Ok(P::from_vec(Decodable::decode(d)?)) } } diff --git a/src/librustc_ast/token.rs b/src/librustc_ast/token.rs index bcce881ed48..46c4be0a33b 100644 --- a/src/librustc_ast/token.rs +++ b/src/librustc_ast/token.rs @@ -17,13 +17,13 @@ use rustc_span::{self, Span, DUMMY_SP}; use std::borrow::Cow; use std::{fmt, mem}; -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub enum CommentKind { Line, Block, } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, Encodable, Decodable, Hash, Debug, Copy)] #[derive(HashStable_Generic)] pub enum BinOpToken { Plus, @@ -39,7 +39,7 @@ pub enum BinOpToken { } /// A delimiter token. -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug, Copy)] #[derive(HashStable_Generic)] pub enum DelimToken { /// A round parenthesis (i.e., `(` or `)`). @@ -62,7 +62,7 @@ impl DelimToken { } } -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub enum LitKind { Bool, // AST only, must never appear in a `Token` Byte, @@ -77,7 +77,7 @@ pub enum LitKind { } /// A literal token. -#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub struct Lit { pub kind: LitKind, pub symbol: Symbol, @@ -188,7 +188,7 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: bool) -> bool { .contains(&name) } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub enum TokenKind { /* Expression-operator symbols. */ Eq, @@ -267,7 +267,7 @@ pub enum TokenKind { #[cfg(target_arch = "x86_64")] rustc_data_structures::static_assert_size!(TokenKind, 16); -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub struct Token { pub kind: TokenKind, pub span: Span, @@ -688,7 +688,7 @@ impl PartialEq for Token { } } -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone, Encodable, Decodable)] /// For interpolation during macro expansion. pub enum Nonterminal { NtItem(P), @@ -711,7 +711,7 @@ pub enum Nonterminal { #[cfg(target_arch = "x86_64")] rustc_data_structures::static_assert_size!(Nonterminal, 40); -#[derive(Debug, Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable)] pub enum NonterminalKind { Item, Block, diff --git a/src/librustc_ast/tokenstream.rs b/src/librustc_ast/tokenstream.rs index 9d0199078fa..151acddae84 100644 --- a/src/librustc_ast/tokenstream.rs +++ b/src/librustc_ast/tokenstream.rs @@ -35,7 +35,7 @@ use std::{iter, mem}; /// /// The RHS of an MBE macro is the only place `SubstNt`s are substituted. /// Nothing special happens to misnamed or misplaced `SubstNt`s. -#[derive(Debug, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)] pub enum TokenTree { /// A single token Token(Token), @@ -124,7 +124,7 @@ where /// The goal is for procedural macros to work with `TokenStream`s and `TokenTree`s /// instead of a representation of the abstract syntax tree. /// Today's `TokenTree`s can still contain AST via `token::Interpolated` for back-compat. -#[derive(Clone, Debug, Default, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, Default, Encodable, Decodable)] pub struct TokenStream(pub Lrc>); pub type TreeAndJoint = (TokenTree, IsJoint); @@ -133,7 +133,7 @@ pub type TreeAndJoint = (TokenTree, IsJoint); #[cfg(target_arch = "x86_64")] rustc_data_structures::static_assert_size!(TokenStream, 8); -#[derive(Clone, Copy, Debug, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable)] pub enum IsJoint { Joint, NonJoint, @@ -408,7 +408,7 @@ impl Cursor { } } -#[derive(Debug, Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)] pub struct DelimSpan { pub open: Span, pub close: Span, diff --git a/src/librustc_attr/builtin.rs b/src/librustc_attr/builtin.rs index 5f131fae385..3ddabcc17f8 100644 --- a/src/librustc_attr/builtin.rs +++ b/src/librustc_attr/builtin.rs @@ -67,7 +67,7 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) { } } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, Encodable, Decodable)] pub enum InlineAttr { None, Hint, @@ -75,7 +75,7 @@ pub enum InlineAttr { Never, } -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone, Encodable, Decodable)] pub enum OptimizeAttr { None, Speed, @@ -130,7 +130,7 @@ pub fn find_unwind_attr(sess: &Session, attrs: &[Attribute]) -> Option, /// The note to issue a reason. @@ -797,7 +797,7 @@ where depr } -#[derive(PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone)] +#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone)] pub enum ReprAttr { ReprInt(IntType), ReprC, @@ -808,7 +808,8 @@ pub enum ReprAttr { ReprNoNiche, } -#[derive(Eq, PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone, HashStable_Generic)] +#[derive(Eq, PartialEq, Debug, Copy, Clone)] +#[derive(Encodable, Decodable, HashStable_Generic)] pub enum IntType { SignedInt(ast::IntTy), UnsignedInt(ast::UintTy), diff --git a/src/librustc_attr/lib.rs b/src/librustc_attr/lib.rs index 5754bb48d24..149a950f7d4 100644 --- a/src/librustc_attr/lib.rs +++ b/src/librustc_attr/lib.rs @@ -6,8 +6,7 @@ #![feature(or_patterns)] -// FIXME(#56935): Work around ICEs during cross-compilation. -#[allow(unused)] +#[macro_use] extern crate rustc_macros; mod builtin; diff --git a/src/librustc_codegen_ssa/Cargo.toml b/src/librustc_codegen_ssa/Cargo.toml index 8fa0de37648..ff9dac372ab 100644 --- a/src/librustc_codegen_ssa/Cargo.toml +++ b/src/librustc_codegen_ssa/Cargo.toml @@ -33,5 +33,6 @@ rustc_fs_util = { path = "../librustc_fs_util" } rustc_hir = { path = "../librustc_hir" } rustc_incremental = { path = "../librustc_incremental" } rustc_index = { path = "../librustc_index" } +rustc_macros = { path = "../librustc_macros" } rustc_target = { path = "../librustc_target" } rustc_session = { path = "../librustc_session" } diff --git a/src/librustc_codegen_ssa/back/linker.rs b/src/librustc_codegen_ssa/back/linker.rs index f9a782af24c..5100ef8ad4f 100644 --- a/src/librustc_codegen_ssa/back/linker.rs +++ b/src/librustc_codegen_ssa/back/linker.rs @@ -35,7 +35,7 @@ pub fn disable_localization(linker: &mut Command) { /// For all the linkers we support, and information they might /// need out of the shared crate context before we get rid of it. -#[derive(RustcEncodable, RustcDecodable)] +#[derive(Encodable, Decodable)] pub struct LinkerInfo { exports: FxHashMap>, } diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index 85260d30a3d..6bfbda0f1d7 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -16,6 +16,8 @@ //! The backend-agnostic functions of this crate use functions defined in various traits that //! have to be implemented by each backends. +#[macro_use] +extern crate rustc_macros; #[macro_use] extern crate log; #[macro_use] @@ -74,7 +76,7 @@ impl ModuleCodegen { } } -#[derive(Debug, RustcEncodable, RustcDecodable)] +#[derive(Debug, Encodable, Decodable)] pub struct CompiledModule { pub name: String, pub kind: ModuleKind, @@ -87,7 +89,7 @@ pub struct CachedModuleCodegen { pub source: WorkProduct, } -#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Encodable, Decodable)] pub enum ModuleKind { Regular, Metadata, @@ -110,7 +112,7 @@ bitflags::bitflags! { /// identifiers (`CrateNum`) to `CrateSource`. The other fields map `CrateNum` to the crate's own /// additional properties, so that effectively we can retrieve each dependent crate's `CrateSource` /// and the corresponding properties without referencing information outside of a `CrateInfo`. -#[derive(Debug, RustcEncodable, RustcDecodable)] +#[derive(Debug, Encodable, Decodable)] pub struct CrateInfo { pub panic_runtime: Option, pub compiler_builtins: Option, @@ -128,7 +130,7 @@ pub struct CrateInfo { pub dependency_formats: Lrc, } -#[derive(RustcEncodable, RustcDecodable)] +#[derive(Encodable, Decodable)] pub struct CodegenResults { pub crate_name: Symbol, pub modules: Vec, diff --git a/src/librustc_data_structures/Cargo.toml b/src/librustc_data_structures/Cargo.toml index 36c32e60031..1926dbf06e7 100644 --- a/src/librustc_data_structures/Cargo.toml +++ b/src/librustc_data_structures/Cargo.toml @@ -17,6 +17,7 @@ jobserver_crate = { version = "0.1.13", package = "jobserver" } lazy_static = "1" once_cell = { version = "1", features = ["parking_lot"] } rustc_serialize = { path = "../librustc_serialize" } +rustc_macros = { path = "../librustc_macros" } rustc_graphviz = { path = "../librustc_graphviz" } cfg-if = "0.1.2" crossbeam-utils = { version = "0.7", features = ["nightly"] } diff --git a/src/librustc_data_structures/fingerprint.rs b/src/librustc_data_structures/fingerprint.rs index 282626611d5..f8d631ce01e 100644 --- a/src/librustc_data_structures/fingerprint.rs +++ b/src/librustc_data_structures/fingerprint.rs @@ -1,5 +1,8 @@ use crate::stable_hasher; -use rustc_serialize::opaque::{Decoder, EncodeResult, Encoder}; +use rustc_serialize::{ + opaque::{self, EncodeResult}, + Decodable, Encodable, +}; use std::mem; #[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy)] @@ -49,14 +52,14 @@ impl Fingerprint { format!("{:x}{:x}", self.0, self.1) } - pub fn encode_opaque(&self, encoder: &mut Encoder) -> EncodeResult { + pub fn encode_opaque(&self, encoder: &mut opaque::Encoder) -> EncodeResult { let bytes: [u8; 16] = unsafe { mem::transmute([self.0.to_le(), self.1.to_le()]) }; encoder.emit_raw_bytes(&bytes); Ok(()) } - pub fn decode_opaque(decoder: &mut Decoder<'_>) -> Result { + pub fn decode_opaque(decoder: &mut opaque::Decoder<'_>) -> Result { let mut bytes = [0; 16]; decoder.read_raw_bytes(&mut bytes)?; @@ -83,18 +86,45 @@ impl stable_hasher::StableHasherResult for Fingerprint { impl_stable_hash_via_hash!(Fingerprint); -impl rustc_serialize::UseSpecializedEncodable for Fingerprint {} +impl Encodable for Fingerprint { + fn encode(&self, s: &mut E) -> Result<(), E::Error> { + s.encode_fingerprint(self) + } +} -impl rustc_serialize::UseSpecializedDecodable for Fingerprint {} +impl Decodable for Fingerprint { + fn decode(d: &mut D) -> Result { + d.decode_fingerprint() + } +} -impl rustc_serialize::SpecializedEncoder for Encoder { - fn specialized_encode(&mut self, f: &Fingerprint) -> Result<(), Self::Error> { +pub trait FingerprintEncoder: rustc_serialize::Encoder { + fn encode_fingerprint(&mut self, f: &Fingerprint) -> Result<(), Self::Error>; +} + +pub trait FingerprintDecoder: rustc_serialize::Decoder { + fn decode_fingerprint(&mut self) -> Result; +} + +impl FingerprintEncoder for E { + default fn encode_fingerprint(&mut self, _: &Fingerprint) -> Result<(), E::Error> { + panic!("Cannot encode `Fingerprint` with `{}`", std::any::type_name::()); + } +} + +impl FingerprintEncoder for opaque::Encoder { + fn encode_fingerprint(&mut self, f: &Fingerprint) -> EncodeResult { f.encode_opaque(self) } } -impl<'a> rustc_serialize::SpecializedDecoder for Decoder<'a> { - fn specialized_decode(&mut self) -> Result { +impl FingerprintDecoder for D { + default fn decode_fingerprint(&mut self) -> Result { + panic!("Cannot decode `Fingerprint` with `{}`", std::any::type_name::()); + } +} +impl FingerprintDecoder for opaque::Decoder<'_> { + fn decode_fingerprint(&mut self) -> Result { Fingerprint::decode_opaque(self) } } diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 3884fc05105..017511cc50d 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -29,6 +29,8 @@ extern crate log; #[macro_use] extern crate cfg_if; +#[macro_use] +extern crate rustc_macros; #[inline(never)] #[cold] diff --git a/src/librustc_data_structures/sorted_map.rs b/src/librustc_data_structures/sorted_map.rs index 652268dcee8..856eb73e629 100644 --- a/src/librustc_data_structures/sorted_map.rs +++ b/src/librustc_data_structures/sorted_map.rs @@ -16,18 +16,7 @@ pub use index_map::SortedIndexMultiMap; /// stores data in a more compact way. It also supports accessing contiguous /// ranges of elements as a slice, and slices of already sorted elements can be /// inserted efficiently. -#[derive( - Clone, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - Default, - Debug, - RustcEncodable, - RustcDecodable -)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug, Encodable, Decodable)] pub struct SortedMap { data: Vec<(K, V)>, } diff --git a/src/librustc_data_structures/svh.rs b/src/librustc_data_structures/svh.rs index 476eb9e14f9..02103de2e8d 100644 --- a/src/librustc_data_structures/svh.rs +++ b/src/librustc_data_structures/svh.rs @@ -48,14 +48,14 @@ impl fmt::Display for Svh { } } -impl Encodable for Svh { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for Svh { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u64(self.as_u64().to_le()) } } -impl Decodable for Svh { - fn decode(d: &mut D) -> Result { +impl Decodable for Svh { + fn decode(d: &mut D) -> Result { d.read_u64().map(u64::from_le).map(Svh::new) } } diff --git a/src/librustc_data_structures/thin_vec.rs b/src/librustc_data_structures/thin_vec.rs index 43002178eb9..4d673fd5cf9 100644 --- a/src/librustc_data_structures/thin_vec.rs +++ b/src/librustc_data_structures/thin_vec.rs @@ -3,7 +3,7 @@ use crate::stable_hasher::{HashStable, StableHasher}; /// A vector type optimized for cases where this size is usually 0 (cf. `SmallVector`). /// The `Option>` wrapping allows us to represent a zero sized vector with `None`, /// which uses only a single (null) pointer. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug)] pub struct ThinVec(Option>>); impl ThinVec { diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs index 7d137a55033..fe60a99dde0 100644 --- a/src/librustc_data_structures/transitive_relation.rs +++ b/src/librustc_data_structures/transitive_relation.rs @@ -1,8 +1,6 @@ use crate::fx::FxIndexSet; -use crate::stable_hasher::{HashStable, StableHasher}; use crate::sync::Lock; use rustc_index::bit_set::BitMatrix; -use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use std::fmt::Debug; use std::hash::Hash; use std::mem; @@ -42,10 +40,10 @@ impl Default for TransitiveRelation { } } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] struct Index(usize); -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, PartialEq, Eq, Debug)] struct Edge { source: Index, target: Index, @@ -402,66 +400,3 @@ fn pare_down(candidates: &mut Vec, closure: &BitMatrix) { candidates.truncate(j - dead); } } - -impl Encodable for TransitiveRelation -where - T: Clone + Encodable + Debug + Eq + Hash + Clone, -{ - fn encode(&self, s: &mut E) -> Result<(), E::Error> { - s.emit_struct("TransitiveRelation", 2, |s| { - s.emit_struct_field("elements", 0, |s| self.elements.encode(s))?; - s.emit_struct_field("edges", 1, |s| self.edges.encode(s))?; - Ok(()) - }) - } -} - -impl Decodable for TransitiveRelation -where - T: Clone + Decodable + Debug + Eq + Hash + Clone, -{ - fn decode(d: &mut D) -> Result { - d.read_struct("TransitiveRelation", 2, |d| { - Ok(TransitiveRelation { - elements: d.read_struct_field("elements", 0, |d| Decodable::decode(d))?, - edges: d.read_struct_field("edges", 1, |d| Decodable::decode(d))?, - closure: Lock::new(None), - }) - }) - } -} - -impl HashStable for TransitiveRelation -where - T: HashStable + Eq + Debug + Clone + Hash, -{ - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { - // We are assuming here that the relation graph has been built in a - // deterministic way and we can just hash it the way it is. - let TransitiveRelation { - ref elements, - ref edges, - // "closure" is just a copy of the data above - closure: _, - } = *self; - - elements.hash_stable(hcx, hasher); - edges.hash_stable(hcx, hasher); - } -} - -impl HashStable for Edge { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { - let Edge { ref source, ref target } = *self; - - source.hash_stable(hcx, hasher); - target.hash_stable(hcx, hasher); - } -} - -impl HashStable for Index { - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { - let Index(idx) = *self; - idx.hash_stable(hcx, hasher); - } -} diff --git a/src/librustc_errors/Cargo.toml b/src/librustc_errors/Cargo.toml index d0f04c3fe76..c17d61dae9f 100644 --- a/src/librustc_errors/Cargo.toml +++ b/src/librustc_errors/Cargo.toml @@ -13,6 +13,7 @@ doctest = false log = { package = "tracing", version = "0.1" } rustc_serialize = { path = "../librustc_serialize" } rustc_span = { path = "../librustc_span" } +rustc_macros = { path = "../librustc_macros" } rustc_data_structures = { path = "../librustc_data_structures" } unicode-width = "0.1.4" atty = "0.2" diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index acaa26c6ad2..cd4b5d56f36 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -9,7 +9,7 @@ use rustc_span::{MultiSpan, Span, DUMMY_SP}; use std::fmt; #[must_use] -#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct Diagnostic { pub level: Level, pub message: Vec<(String, Style)>, @@ -24,14 +24,14 @@ pub struct Diagnostic { pub sort_span: Span, } -#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)] pub enum DiagnosticId { Error(String), Lint(String), } /// For example a note attached to an error. -#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct SubDiagnostic { pub level: Level, pub message: Vec<(String, Style)>, diff --git a/src/librustc_errors/json.rs b/src/librustc_errors/json.rs index 24186198fd2..750d36d3d89 100644 --- a/src/librustc_errors/json.rs +++ b/src/librustc_errors/json.rs @@ -145,7 +145,7 @@ impl Emitter for JsonEmitter { // The following data types are provided just for serialisation. -#[derive(RustcEncodable)] +#[derive(Encodable)] struct Diagnostic { /// The primary error message. message: String, @@ -159,7 +159,7 @@ struct Diagnostic { rendered: Option, } -#[derive(RustcEncodable)] +#[derive(Encodable)] struct DiagnosticSpan { file_name: String, byte_start: u32, @@ -186,7 +186,7 @@ struct DiagnosticSpan { expansion: Option>, } -#[derive(RustcEncodable)] +#[derive(Encodable)] struct DiagnosticSpanLine { text: String, @@ -196,7 +196,7 @@ struct DiagnosticSpanLine { highlight_end: usize, } -#[derive(RustcEncodable)] +#[derive(Encodable)] struct DiagnosticSpanMacroExpansion { /// span where macro was applied to generate this code; note that /// this may itself derive from a macro (if @@ -210,7 +210,7 @@ struct DiagnosticSpanMacroExpansion { def_site_span: DiagnosticSpan, } -#[derive(RustcEncodable)] +#[derive(Encodable)] struct DiagnosticCode { /// The code itself. code: String, @@ -218,7 +218,7 @@ struct DiagnosticCode { explanation: Option<&'static str>, } -#[derive(RustcEncodable)] +#[derive(Encodable)] struct ArtifactNotification<'a> { /// The path of the artifact. artifact: &'a Path, diff --git a/src/librustc_errors/json/tests.rs b/src/librustc_errors/json/tests.rs index dcfcdbc63f2..e69e868c8ed 100644 --- a/src/librustc_errors/json/tests.rs +++ b/src/librustc_errors/json/tests.rs @@ -10,12 +10,12 @@ use rustc_span::{BytePos, Span}; use std::str; -#[derive(RustcDecodable, Debug, PartialEq, Eq)] +#[derive(Decodable, Debug, PartialEq, Eq)] struct TestData { spans: Vec, } -#[derive(RustcDecodable, Debug, PartialEq, Eq)] +#[derive(Decodable, Debug, PartialEq, Eq)] struct SpanTestData { pub byte_start: u32, pub byte_end: u32, diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 73d71063b23..98e9972530e 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -6,6 +6,9 @@ #![feature(crate_visibility_modifier)] #![feature(nll)] +#[macro_use] +extern crate rustc_macros; + pub use emitter::ColorConfig; use log::debug; @@ -50,7 +53,7 @@ rustc_data_structures::static_assert_size!(PResult<'_, bool>, 16); /// All suggestions are marked with an `Applicability`. Tools use the applicability of a suggestion /// to determine whether it should be automatically applied or if the user should be consulted /// before applying the suggestion. -#[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub enum Applicability { /// The suggestion is definitely what the user intended. This suggestion should be /// automatically applied. @@ -69,7 +72,7 @@ pub enum Applicability { Unspecified, } -#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, RustcEncodable, RustcDecodable)] +#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Encodable, Decodable)] pub enum SuggestionStyle { /// Hide the suggested code when displaying this suggestion inline. HideCodeInline, @@ -94,7 +97,7 @@ impl SuggestionStyle { } } -#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct CodeSuggestion { /// Each substitute can have multiple variants due to multiple /// applicable suggestions @@ -129,13 +132,13 @@ pub struct CodeSuggestion { pub applicability: Applicability, } -#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] /// See the docs on `CodeSuggestion::substitutions` pub struct Substitution { pub parts: Vec, } -#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct SubstitutionPart { pub span: Span, pub snippet: String, @@ -943,7 +946,7 @@ impl HandlerInner { } } -#[derive(Copy, PartialEq, Clone, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, PartialEq, Clone, Hash, Debug, Encodable, Decodable)] pub enum Level { Bug, Fatal, @@ -1012,7 +1015,7 @@ macro_rules! pluralize { // Useful type to use with `Result<>` indicate that an error has already // been reported to the user, so no need to continue checking. -#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable, Hash, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Encodable, Decodable, Hash, PartialEq, Eq)] pub struct ErrorReported; rustc_data_structures::impl_stable_hash_via_hash!(ErrorReported); diff --git a/src/librustc_errors/snippet.rs b/src/librustc_errors/snippet.rs index 0660590a725..160bf577799 100644 --- a/src/librustc_errors/snippet.rs +++ b/src/librustc_errors/snippet.rs @@ -173,7 +173,7 @@ pub struct StyledString { pub style: Style, } -#[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub enum Style { MainHeaderMsg, HeaderMsg, diff --git a/src/librustc_expand/Cargo.toml b/src/librustc_expand/Cargo.toml index bdf039c36ab..fbdb65b5587 100644 --- a/src/librustc_expand/Cargo.toml +++ b/src/librustc_expand/Cargo.toml @@ -20,6 +20,7 @@ rustc_attr = { path = "../librustc_attr" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_errors = { path = "../librustc_errors" } rustc_feature = { path = "../librustc_feature" } +rustc_macros = { path = "../librustc_macros" } rustc_lexer = { path = "../librustc_lexer" } rustc_parse = { path = "../librustc_parse" } rustc_session = { path = "../librustc_session" } diff --git a/src/librustc_expand/lib.rs b/src/librustc_expand/lib.rs index 1e3ab2c5ec2..7f631cb71af 100644 --- a/src/librustc_expand/lib.rs +++ b/src/librustc_expand/lib.rs @@ -8,6 +8,9 @@ #![feature(proc_macro_span)] #![feature(try_blocks)] +#[macro_use] +extern crate rustc_macros; + extern crate proc_macro as pm; mod placeholders; diff --git a/src/librustc_expand/mbe.rs b/src/librustc_expand/mbe.rs index 6f2daaa81c0..9920e0650a7 100644 --- a/src/librustc_expand/mbe.rs +++ b/src/librustc_expand/mbe.rs @@ -19,7 +19,7 @@ use rustc_data_structures::sync::Lrc; /// Contains the sub-token-trees of a "delimited" token tree, such as the contents of `(`. Note /// that the delimiter itself might be `NoDelim`. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug)] struct Delimited { delim: token::DelimToken, tts: Vec, @@ -37,7 +37,7 @@ impl Delimited { } } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug)] struct SequenceRepetition { /// The sequence of token trees tts: Vec, @@ -49,7 +49,7 @@ struct SequenceRepetition { num_captures: usize, } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy)] struct KleeneToken { span: Span, op: KleeneOp, @@ -63,7 +63,7 @@ impl KleeneToken { /// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star) /// for token sequences. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy)] enum KleeneOp { /// Kleene star (`*`) for zero or more repetitions ZeroOrMore, @@ -75,7 +75,7 @@ enum KleeneOp { /// Similar to `tokenstream::TokenTree`, except that `$i`, `$i:ident`, and `$(...)` /// are "first-class" token trees. Useful for parsing macros. -#[derive(Debug, Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Debug, Clone, PartialEq, Encodable, Decodable)] enum TokenTree { Token(Token), Delimited(DelimSpan, Lrc), diff --git a/src/librustc_hir/def.rs b/src/librustc_hir/def.rs index 618f3e99c3f..c4877be3f64 100644 --- a/src/librustc_hir/def.rs +++ b/src/librustc_hir/def.rs @@ -9,7 +9,7 @@ use rustc_span::hygiene::MacroKind; use std::fmt::Debug; /// Encodes if a `DefKind::Ctor` is the constructor of an enum variant or a struct. -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug)] #[derive(HashStable_Generic)] pub enum CtorOf { /// This `DefKind::Ctor` is a synthesized constructor of a tuple or unit struct. @@ -18,7 +18,7 @@ pub enum CtorOf { Variant, } -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug)] #[derive(HashStable_Generic)] pub enum CtorKind { /// Constructor function automatically created by a tuple struct/variant. @@ -29,7 +29,7 @@ pub enum CtorKind { Fictive, } -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug)] #[derive(HashStable_Generic)] pub enum NonMacroAttrKind { /// Single-segment attribute defined by the language (`#[inline]`) @@ -42,7 +42,7 @@ pub enum NonMacroAttrKind { Registered, } -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug)] #[derive(HashStable_Generic)] pub enum DefKind { // Type namespace @@ -191,7 +191,7 @@ impl DefKind { } /// The resolution of a path or export. -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug)] #[derive(HashStable_Generic)] pub enum Res { Def(DefKind, DefId), diff --git a/src/librustc_hir/definitions.rs b/src/librustc_hir/definitions.rs index 79b70682739..5604e3a8dca 100644 --- a/src/librustc_hir/definitions.rs +++ b/src/librustc_hir/definitions.rs @@ -23,7 +23,7 @@ use std::hash::Hash; /// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey` /// stores the `DefIndex` of its parent. /// There is one `DefPathTable` for each crate. -#[derive(Clone, Default, RustcDecodable, RustcEncodable)] +#[derive(Clone, Default, Decodable, Encodable)] pub struct DefPathTable { index_to_key: IndexVec, def_path_hashes: IndexVec, @@ -92,7 +92,7 @@ pub struct Definitions { /// A unique identifier that we can use to lookup a definition /// precisely. It combines the index of the definition's parent (if /// any) with a `DisambiguatedDefPathData`. -#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Debug, Encodable, Decodable)] pub struct DefKey { /// The parent path. pub parent: Option, @@ -143,13 +143,13 @@ impl DefKey { /// between them. This introduces some artificial ordering dependency /// but means that if you have, e.g., two impls for the same type in /// the same module, they do get distinct `DefId`s. -#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Debug, Encodable, Decodable)] pub struct DisambiguatedDefPathData { pub data: DefPathData, pub disambiguator: u32, } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, Encodable, Decodable)] pub struct DefPath { /// The path leading from the crate root to the item. pub data: Vec, @@ -244,7 +244,7 @@ impl DefPath { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)] pub enum DefPathData { // Root: these should only be used for the root nodes, because // they are treated specially by the `def_path` function. diff --git a/src/librustc_hir/hir.rs b/src/librustc_hir/hir.rs index 6474dc318d3..928235adac3 100644 --- a/src/librustc_hir/hir.rs +++ b/src/librustc_hir/hir.rs @@ -23,7 +23,7 @@ use smallvec::SmallVec; use std::collections::{BTreeMap, BTreeSet}; use std::fmt; -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Copy, Clone, Encodable, HashStable_Generic)] pub struct Lifetime { pub hir_id: HirId, pub span: Span, @@ -37,7 +37,7 @@ pub struct Lifetime { pub name: LifetimeName, } -#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(Debug, Clone, PartialEq, Eq, Encodable, Hash, Copy)] #[derive(HashStable_Generic)] pub enum ParamName { /// Some user-given name like `T` or `'x`. @@ -83,7 +83,7 @@ impl ParamName { } } -#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(Debug, Clone, PartialEq, Eq, Encodable, Hash, Copy)] #[derive(HashStable_Generic)] pub enum LifetimeName { /// User-given names or fresh (synthetic) names. @@ -182,7 +182,7 @@ impl Lifetime { /// A `Path` is essentially Rust's notion of a name; for instance, /// `std::cmp::PartialEq`. It's represented as a sequence of identifiers, /// along with a bunch of supporting information. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct Path<'hir> { pub span: Span, /// The resolution for the path. @@ -199,7 +199,7 @@ impl Path<'_> { /// A segment of a path: an identifier, an optional lifetime, and a set of /// types. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct PathSegment<'hir> { /// The identifier portion of this path segment. #[stable_hasher(project(name))] @@ -242,13 +242,13 @@ impl<'hir> PathSegment<'hir> { } } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Encodable, Debug, HashStable_Generic)] pub struct ConstArg { pub value: AnonConst, pub span: Span, } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub enum GenericArg<'hir> { Lifetime(Lifetime), Type(Ty<'hir>), @@ -288,7 +288,7 @@ impl GenericArg<'_> { } } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct GenericArgs<'hir> { /// The generic arguments for this path segment. pub args: &'hir [GenericArg<'hir>], @@ -348,7 +348,7 @@ impl GenericArgs<'_> { /// A modifier on a bound, currently this is only used for `?Sized`, where the /// modifier is `Maybe`. Negative bounds should also be handled here. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)] #[derive(HashStable_Generic)] pub enum TraitBoundModifier { None, @@ -360,7 +360,7 @@ pub enum TraitBoundModifier { /// `typeck::collect::compute_bounds` matches these against /// the "special" built-in traits (see `middle::lang_items`) and /// detects `Copy`, `Send` and `Sync`. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub enum GenericBound<'hir> { Trait(PolyTraitRef<'hir>, TraitBoundModifier), Outlives(Lifetime), @@ -384,7 +384,7 @@ impl GenericBound<'_> { pub type GenericBounds<'hir> = &'hir [GenericBound<'hir>]; -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)] pub enum LifetimeParamKind { // Indicates that the lifetime definition was explicitly declared (e.g., in // `fn foo<'a>(x: &'a u8) -> &'a u8 { x }`). @@ -403,7 +403,7 @@ pub enum LifetimeParamKind { Error, } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub enum GenericParamKind<'hir> { /// A lifetime definition (e.g., `'a: 'b + 'c + 'd`). Lifetime { @@ -418,7 +418,7 @@ pub enum GenericParamKind<'hir> { }, } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct GenericParam<'hir> { pub hir_id: HirId, pub name: ParamName, @@ -448,7 +448,7 @@ pub struct GenericParamCount { /// Represents lifetimes and type parameters attached to a declaration /// of a function, enum, trait, etc. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct Generics<'hir> { pub params: &'hir [GenericParam<'hir>], pub where_clause: WhereClause<'hir>, @@ -501,14 +501,14 @@ impl Generics<'hir> { /// Synthetic type parameters are converted to another form during lowering; this allows /// us to track the original form they had, and is useful for error messages. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug)] #[derive(HashStable_Generic)] pub enum SyntheticTyParamKind { ImplTrait, } /// A where-clause in a definition. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct WhereClause<'hir> { pub predicates: &'hir [WherePredicate<'hir>], // Only valid if predicates aren't empty. @@ -535,7 +535,7 @@ impl WhereClause<'_> { } /// A single predicate in a where-clause. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub enum WherePredicate<'hir> { /// A type binding (e.g., `for<'c> Foo: Send + Clone + 'c`). BoundPredicate(WhereBoundPredicate<'hir>), @@ -556,7 +556,7 @@ impl WherePredicate<'_> { } /// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`). -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct WhereBoundPredicate<'hir> { pub span: Span, /// Any generics from a `for` binding. @@ -568,7 +568,7 @@ pub struct WhereBoundPredicate<'hir> { } /// A lifetime predicate (e.g., `'a: 'b + 'c`). -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct WhereRegionPredicate<'hir> { pub span: Span, pub lifetime: Lifetime, @@ -576,7 +576,7 @@ pub struct WhereRegionPredicate<'hir> { } /// An equality predicate (e.g., `T = int`); currently unsupported. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct WhereEqPredicate<'hir> { pub hir_id: HirId, pub span: Span, @@ -584,7 +584,7 @@ pub struct WhereEqPredicate<'hir> { pub rhs_ty: &'hir Ty<'hir>, } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Encodable, Debug, HashStable_Generic)] pub struct ModuleItems { // Use BTreeSets here so items are in the same order as in the // list of all items in Crate @@ -594,7 +594,7 @@ pub struct ModuleItems { } /// A type representing only the top-level module. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Encodable, Debug, HashStable_Generic)] pub struct CrateItem<'hir> { pub module: Mod<'hir>, pub attrs: &'hir [Attribute], @@ -607,7 +607,7 @@ pub struct CrateItem<'hir> { /// For more details, see the [rustc dev guide]. /// /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html -#[derive(RustcEncodable, RustcDecodable, Debug)] +#[derive(Debug)] pub struct Crate<'hir> { pub item: CrateItem<'hir>, pub exported_macros: &'hir [MacroDef<'hir>], @@ -715,7 +715,7 @@ impl Crate<'_> { /// A macro definition, in this crate or imported from another. /// /// Not parsed directly, but created on macro import or `macro_rules!` expansion. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct MacroDef<'hir> { pub ident: Ident, pub vis: Visibility<'hir>, @@ -728,7 +728,7 @@ pub struct MacroDef<'hir> { /// A block of statements `{ .. }`, which may have a label (in this case the /// `targeted_by_break` field will be `true`) and may be `unsafe` by means of /// the `rules` being anything but `DefaultBlock`. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct Block<'hir> { /// Statements in a block. pub stmts: &'hir [Stmt<'hir>], @@ -746,7 +746,7 @@ pub struct Block<'hir> { pub targeted_by_break: bool, } -#[derive(Debug, RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct Pat<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -824,7 +824,7 @@ impl Pat<'_> { /// Patterns like the fields of Foo `{ x, ref y, ref mut z }` /// are treated the same as` x: x, y: ref y, z: ref mut z`, /// except `is_shorthand` is true. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct FieldPat<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -840,7 +840,7 @@ pub struct FieldPat<'hir> { /// Explicit binding annotations given in the HIR for a binding. Note /// that this is not the final binding *mode* that we infer after type /// inference. -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)] pub enum BindingAnnotation { /// No binding annotation given: this means that the final binding mode /// will depend on whether we have skipped through a `&` reference @@ -861,7 +861,7 @@ pub enum BindingAnnotation { RefMut, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)] pub enum RangeEnd { Included, Excluded, @@ -876,7 +876,7 @@ impl fmt::Display for RangeEnd { } } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub enum PatKind<'hir> { /// Represents a wildcard pattern (i.e., `_`). Wild, @@ -932,7 +932,7 @@ pub enum PatKind<'hir> { Slice(&'hir [&'hir Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [&'hir Pat<'hir>]), } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)] pub enum BinOpKind { /// The `+` operator (addition). Add, @@ -1066,7 +1066,7 @@ impl Into for BinOpKind { pub type BinOp = Spanned; -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)] pub enum UnOp { /// The `*` operator (deferencing). UnDeref, @@ -1095,7 +1095,7 @@ impl UnOp { } /// A statement. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct Stmt<'hir> { pub hir_id: HirId, pub kind: StmtKind<'hir>, @@ -1103,7 +1103,7 @@ pub struct Stmt<'hir> { } /// The contents of a statement. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub enum StmtKind<'hir> { /// A local (`let`) binding. Local(&'hir Local<'hir>), @@ -1129,7 +1129,7 @@ impl StmtKind<'hir> { } /// Represents a `let` statement (i.e., `let : = ;`). -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct Local<'hir> { pub pat: &'hir Pat<'hir>, /// Type annotation, if any (otherwise the type will be inferred). @@ -1146,7 +1146,7 @@ pub struct Local<'hir> { /// Represents a single arm of a `match` expression, e.g. /// ` (if ) => `. -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct Arm<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -1160,12 +1160,12 @@ pub struct Arm<'hir> { pub body: &'hir Expr<'hir>, } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub enum Guard<'hir> { If(&'hir Expr<'hir>), } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub struct Field<'hir> { #[stable_hasher(ignore)] pub hir_id: HirId, @@ -1175,7 +1175,7 @@ pub struct Field<'hir> { pub is_shorthand: bool, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)] pub enum BlockCheckMode { DefaultBlock, UnsafeBlock(UnsafeSource), @@ -1183,13 +1183,13 @@ pub enum BlockCheckMode { PopUnsafeBlock(UnsafeSource), } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)] pub enum UnsafeSource { CompilerGenerated, UserProvided, } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Hash, Debug)] pub struct BodyId { pub hir_id: HirId, } @@ -1215,7 +1215,7 @@ pub struct BodyId { /// /// All bodies have an **owner**, which can be accessed via the HIR /// map using `body_owner_def_id()`. -#[derive(RustcEncodable, RustcDecodable, Debug)] +#[derive(Debug)] pub struct Body<'hir> { pub params: &'hir [Param<'hir>], pub value: Expr<'hir>, @@ -1233,7 +1233,7 @@ impl Body<'hir> { } /// The type of source expression that caused this generator to be created. -#[derive(Clone, PartialEq, Eq, HashStable_Generic, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Eq, HashStable_Generic, Encodable, Decodable, Debug, Copy)] pub enum GeneratorKind { /// An explicit `async` block or the body of an async function. Async(AsyncGeneratorKind), @@ -1256,7 +1256,7 @@ impl fmt::Display for GeneratorKind { /// /// This helps error messages but is also used to drive coercions in /// type-checking (see #60424). -#[derive(Clone, PartialEq, Eq, HashStable_Generic, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Eq, HashStable_Generic, Encodable, Decodable, Debug, Copy)] pub enum AsyncGeneratorKind { /// An explicit `async` block written by the user. Block, @@ -1357,14 +1357,14 @@ pub type Lit = Spanned; /// These are usually found nested inside types (e.g., array lengths) /// or expressions (e.g., repeat counts), and also used to define /// explicit discriminant values for enum variants. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)] pub struct AnonConst { pub hir_id: HirId, pub body: BodyId, } /// An expression. -#[derive(Debug, RustcEncodable, RustcDecodable)] +#[derive(Debug)] pub struct Expr<'hir> { pub hir_id: HirId, pub kind: ExprKind<'hir>, @@ -1543,7 +1543,7 @@ pub fn is_range_literal(sm: &SourceMap, expr: &Expr<'_>) -> bool { false } -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub enum ExprKind<'hir> { /// A `box x` expression. Box(&'hir Expr<'hir>), @@ -1660,7 +1660,7 @@ pub enum ExprKind<'hir> { /// To resolve the path to a `DefId`, call [`qpath_res`]. /// /// [`qpath_res`]: ../rustc_middle/ty/struct.TypeckResults.html#method.qpath_res -#[derive(RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Debug, HashStable_Generic)] pub enum QPath<'hir> { /// Path to a definition, optionally "fully-qualified" with a `Self` /// type, if the path points to an associated item in a trait. @@ -1680,7 +1680,7 @@ pub enum QPath<'hir> { } /// Hints at the original code for a let statement. -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, Encodable, Debug, HashStable_Generic)] pub enum LocalSource { /// A `match _ { .. }`. Normal, @@ -1702,7 +1702,7 @@ pub enum LocalSource { } /// Hints at the original code for a `match _ { .. }`. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)] #[derive(HashStable_Generic)] pub enum MatchSource { /// A `match _ { .. }`. @@ -1739,7 +1739,7 @@ impl MatchSource { } /// The loop type that yielded an `ExprKind::Loop`. -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)] pub enum LoopSource { /// A `loop { .. }` loop. Loop, @@ -1761,7 +1761,7 @@ impl LoopSource { } } -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, Encodable, Debug, HashStable_Generic)] pub enum LoopIdError { OutsideLoopScope, UnlabeledCfInWhileCondition, @@ -1780,7 +1780,7 @@ impl fmt::Display for LoopIdError { } } -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)] +#[derive(Copy, Clone, Encodable, Debug, HashStable_Generic)] pub struct Destination { // This is `Some(_)` iff there is an explicit user-specified `label pub label: Option::new` and /// so forth. -#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, Lift)] pub enum UserType<'tcx> { Ty(Ty<'tcx>), @@ -1333,7 +1333,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn serialize_query_result_cache(self, encoder: &mut E) -> Result<(), E::Error> where - E: ty::codec::TyEncoder, + E: ty::codec::OpaqueEncoder, { self.queries.on_disk_cache.serialize(self, encoder) } diff --git a/src/librustc_middle/ty/fast_reject.rs b/src/librustc_middle/ty/fast_reject.rs index b0fb179b18b..7456020ee9b 100644 --- a/src/librustc_middle/ty/fast_reject.rs +++ b/src/librustc_middle/ty/fast_reject.rs @@ -17,7 +17,7 @@ pub type SimplifiedType = SimplifiedTypeGen; /// because we sometimes need to use SimplifiedTypeGen values as stable sorting /// keys (in which case we use a DefPathHash as id-type) but in the general case /// the non-stable but fast to construct DefId-version is the better choice. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, TyEncodable, TyDecodable)] pub enum SimplifiedTypeGen where D: Copy + Debug + Ord + Eq, diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index 2def000da64..e6dafd4965b 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -15,14 +15,14 @@ use std::fmt; /// Monomorphization happens on-the-fly and no monomorphized MIR is ever created. Instead, this type /// simply couples a potentially generic `InstanceDef` with some substs, and codegen and const eval /// will do all required substitution as they run. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, Lift)] pub struct Instance<'tcx> { pub def: InstanceDef<'tcx>, pub substs: SubstsRef<'tcx>, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable, HashStable)] pub enum InstanceDef<'tcx> { /// A user-defined callable item. /// diff --git a/src/librustc_middle/ty/layout.rs b/src/librustc_middle/ty/layout.rs index 5aa94ba3d09..16e65d2cca4 100644 --- a/src/librustc_middle/ty/layout.rs +++ b/src/librustc_middle/ty/layout.rs @@ -165,7 +165,7 @@ pub const FAT_PTR_ADDR: usize = 0; /// - For a slice, this is the length. pub const FAT_PTR_EXTRA: usize = 1; -#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable)] pub enum LayoutError<'tcx> { Unknown(Ty<'tcx>), SizeOverflow(Ty<'tcx>), diff --git a/src/librustc_middle/ty/list.rs b/src/librustc_middle/ty/list.rs index 92d6dbb5f90..fe390adf89f 100644 --- a/src/librustc_middle/ty/list.rs +++ b/src/librustc_middle/ty/list.rs @@ -76,9 +76,16 @@ impl fmt::Debug for List { } } -impl Encodable for List { +impl> Encodable for List { #[inline] - fn encode(&self, s: &mut S) -> Result<(), S::Error> { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { + (**self).encode(s) + } +} + +impl> Encodable for &List { + #[inline] + fn encode(&self, s: &mut S) -> Result<(), S::Error> { (**self).encode(s) } } diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 6798addb8aa..ff6f0d346f7 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -89,12 +89,11 @@ pub use self::query::queries; pub use self::consts::{Const, ConstInt, ConstKind, InferConst}; +pub mod _match; pub mod adjustment; pub mod binding; pub mod cast; -#[macro_use] pub mod codec; -pub mod _match; mod erase_regions; pub mod error; pub mod fast_reject; @@ -171,7 +170,7 @@ pub struct ImplHeader<'tcx> { pub predicates: Vec>, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Copy, Clone, PartialEq, TyEncodable, TyDecodable, HashStable)] pub enum ImplPolarity { /// `impl Trait for Type` Positive, @@ -316,7 +315,7 @@ impl<'tcx> AssociatedItems<'tcx> { } } -#[derive(Clone, Debug, PartialEq, Eq, Copy, RustcEncodable, RustcDecodable, HashStable, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Copy, Hash, TyEncodable, TyDecodable, HashStable)] pub enum Visibility { /// Visible everywhere (including in other crates). Public, @@ -403,7 +402,7 @@ impl Visibility { } } -#[derive(Copy, Clone, PartialEq, RustcDecodable, RustcEncodable, HashStable)] +#[derive(Copy, Clone, PartialEq, TyDecodable, TyEncodable, HashStable)] pub enum Variance { Covariant, // T <: T iff A <: B -- e.g., function return type Invariant, // T <: T iff B == A -- e.g., type of mutable cell @@ -652,13 +651,9 @@ impl<'a, 'tcx> HashStable> for TyS<'tcx> { #[rustc_diagnostic_item = "Ty"] pub type Ty<'tcx> = &'tcx TyS<'tcx>; -impl<'tcx> rustc_serialize::UseSpecializedEncodable for Ty<'tcx> {} -impl<'tcx> rustc_serialize::UseSpecializedDecodable for Ty<'tcx> {} -impl<'tcx> rustc_serialize::UseSpecializedDecodable for &'tcx List> {} - pub type CanonicalTy<'tcx> = Canonical<'tcx, Ty<'tcx>>; -#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)] pub struct UpvarPath { pub hir_id: hir::HirId, } @@ -666,13 +661,13 @@ pub struct UpvarPath { /// Upvars do not get their own `NodeId`. Instead, we use the pair of /// the original var ID (that is, the root variable that is referenced /// by the upvar) and the ID of the closure expression. -#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)] pub struct UpvarId { pub var_path: UpvarPath, pub closure_expr_id: LocalDefId, } -#[derive(Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, HashStable)] +#[derive(Clone, PartialEq, Debug, TyEncodable, TyDecodable, Copy, HashStable)] pub enum BorrowKind { /// Data must be immutable and is aliasable. ImmBorrow, @@ -720,7 +715,7 @@ pub enum BorrowKind { /// Information describing the capture of an upvar. This is computed /// during `typeck`, specifically by `regionck`. -#[derive(PartialEq, Clone, Debug, Copy, RustcEncodable, RustcDecodable, HashStable)] +#[derive(PartialEq, Clone, Debug, Copy, TyEncodable, TyDecodable, HashStable)] pub enum UpvarCapture<'tcx> { /// Upvar is captured by value. This is always true when the /// closure is labeled `move`, but can also be true in other cases @@ -731,7 +726,7 @@ pub enum UpvarCapture<'tcx> { ByRef(UpvarBorrow<'tcx>), } -#[derive(PartialEq, Clone, Copy, RustcEncodable, RustcDecodable, HashStable)] +#[derive(PartialEq, Clone, Copy, TyEncodable, TyDecodable, HashStable)] pub struct UpvarBorrow<'tcx> { /// The kind of borrow: by-ref upvars have access to shared /// immutable borrows, which are not part of the normal language @@ -766,7 +761,7 @@ impl ty::EarlyBoundRegion { } } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] pub enum GenericParamDefKind { Lifetime, Type { @@ -787,7 +782,7 @@ impl GenericParamDefKind { } } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] pub struct GenericParamDef { pub name: Symbol, pub def_id: DefId, @@ -831,7 +826,7 @@ pub struct GenericParamCount { /// /// The ordering of parameters is the same as in `Subst` (excluding child generics): /// `Self` (optionally), `Lifetime` params..., `Type` params... -#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] pub struct Generics { pub parent: Option, pub parent_count: usize, @@ -933,7 +928,7 @@ impl<'tcx> Generics { } /// Bounds on generics. -#[derive(Copy, Clone, Default, Debug, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Copy, Clone, Default, Debug, TyEncodable, TyDecodable, HashStable)] pub struct GenericPredicates<'tcx> { pub parent: Option, pub predicates: &'tcx [(Predicate<'tcx>, Span)], @@ -1025,9 +1020,6 @@ pub struct Predicate<'tcx> { inner: &'tcx PredicateInner<'tcx>, } -impl rustc_serialize::UseSpecializedEncodable for Predicate<'_> {} -impl rustc_serialize::UseSpecializedDecodable for Predicate<'_> {} - impl<'tcx> PartialEq for Predicate<'tcx> { fn eq(&self, other: &Self) -> bool { // `self.kind` is always interned. @@ -1103,7 +1095,7 @@ impl<'a, 'tcx> HashStable> for Predicate<'tcx> { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub enum PredicateKind<'tcx> { /// `for<'a>: ...` @@ -1111,7 +1103,7 @@ pub enum PredicateKind<'tcx> { Atom(PredicateAtom<'tcx>), } -#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub enum PredicateAtom<'tcx> { /// Corresponds to `where Foo: Bar`. `Foo` here would be @@ -1261,7 +1253,7 @@ impl<'tcx> Predicate<'tcx> { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct TraitPredicate<'tcx> { pub trait_ref: TraitRef<'tcx>, @@ -1286,7 +1278,7 @@ impl<'tcx> PolyTraitPredicate<'tcx> { } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct OutlivesPredicate(pub A, pub B); // `A: B` pub type PolyOutlivesPredicate = ty::Binder>; @@ -1295,7 +1287,7 @@ pub type TypeOutlivesPredicate<'tcx> = OutlivesPredicate, ty::Region<'t pub type PolyRegionOutlivesPredicate<'tcx> = ty::Binder>; pub type PolyTypeOutlivesPredicate<'tcx> = ty::Binder>; -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct SubtypePredicate<'tcx> { pub a_is_expected: bool, @@ -1316,7 +1308,7 @@ pub type PolySubtypePredicate<'tcx> = ty::Binder>; /// equality between arbitrary types. Processing an instance of /// Form #2 eventually yields one of these `ProjectionPredicate` /// instances to normalize the LHS. -#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct ProjectionPredicate<'tcx> { pub projection_ty: ProjectionTy<'tcx>, @@ -1585,7 +1577,7 @@ impl UniverseIndex { /// basically a name -- distinct bound regions within the same /// universe are just two regions with an unknown relationship to one /// another. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, PartialOrd, Ord)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)] pub struct Placeholder { pub universe: UniverseIndex, pub name: T, @@ -1635,7 +1627,7 @@ pub type PlaceholderConst = Placeholder; /// a.foo::<7>(); /// } /// ``` -#[derive(Copy, Clone, Debug, TypeFoldable, Lift, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, TypeFoldable, Lift, TyEncodable, TyDecodable)] #[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(Hash, HashStable)] pub struct WithOptConstParam { @@ -2106,7 +2098,7 @@ impl<'tcx> VariantDef { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Encodable, Decodable, HashStable)] pub enum VariantDiscr { /// Explicit value for this variant, i.e., `X = 123`. /// The `DefId` corresponds to the embedded constant. @@ -2178,14 +2170,12 @@ impl Hash for AdtDef { } } -impl<'tcx> rustc_serialize::UseSpecializedEncodable for &'tcx AdtDef { - fn default_encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for AdtDef { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { self.did.encode(s) } } -impl<'tcx> rustc_serialize::UseSpecializedDecodable for &'tcx AdtDef {} - impl<'a> HashStable> for AdtDef { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { thread_local! { @@ -2229,7 +2219,7 @@ impl Into for AdtKind { } bitflags! { - #[derive(RustcEncodable, RustcDecodable, Default, HashStable)] + #[derive(TyEncodable, TyDecodable, Default, HashStable)] pub struct ReprFlags: u8 { const IS_C = 1 << 0; const IS_SIMD = 1 << 1; @@ -2246,7 +2236,7 @@ bitflags! { } /// Represents the repr options provided by the user, -#[derive(Copy, Clone, Debug, Eq, PartialEq, RustcEncodable, RustcDecodable, Default, HashStable)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable, Default, HashStable)] pub struct ReprOptions { pub int: Option, pub align: Option, @@ -2690,7 +2680,7 @@ impl<'tcx> FieldDef { /// /// You can get the environment type of a closure using /// `tcx.closure_env_ty()`. -#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable)] pub enum ClosureKind { // Warning: Ordering is significant here! The ordering is chosen @@ -3141,7 +3131,7 @@ pub struct CrateInherentImpls { pub inherent_impls: DefIdMap>, } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, HashStable)] pub struct SymbolName<'tcx> { /// `&str` gives a consistent ordering, which ensures reproducible builds. pub name: &'tcx str, @@ -3166,12 +3156,3 @@ impl<'tcx> fmt::Debug for SymbolName<'tcx> { fmt::Display::fmt(&self.name, fmt) } } - -impl<'tcx> rustc_serialize::UseSpecializedEncodable for SymbolName<'tcx> { - fn default_encode(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_str(self.name) - } -} - -// The decoding takes place in `decode_symbol_name()`. -impl<'tcx> rustc_serialize::UseSpecializedDecodable for SymbolName<'tcx> {} diff --git a/src/librustc_middle/ty/query/on_disk_cache.rs b/src/librustc_middle/ty/query/on_disk_cache.rs index 08b0bfecf49..007b46b1176 100644 --- a/src/librustc_middle/ty/query/on_disk_cache.rs +++ b/src/librustc_middle/ty/query/on_disk_cache.rs @@ -1,28 +1,24 @@ use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex}; -use crate::mir::interpret; use crate::mir::interpret::{AllocDecodingSession, AllocDecodingState}; -use crate::ty::codec::{self as ty_codec, TyDecoder, TyEncoder}; +use crate::mir::{self, interpret}; +use crate::ty::codec::{OpaqueEncoder, RefDecodable, TyDecoder, TyEncoder}; use crate::ty::context::TyCtxt; use crate::ty::{self, Ty}; -use rustc_data_structures::fingerprint::Fingerprint; -use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; +use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder, FingerprintEncoder}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_data_structures::sync::{HashMapExt, Lock, Lrc, OnceCell}; use rustc_data_structures::thin_vec::ThinVec; use rustc_errors::Diagnostic; use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, LOCAL_CRATE}; use rustc_hir::definitions::DefPathHash; use rustc_index::vec::{Idx, IndexVec}; -use rustc_serialize::{ - opaque, Decodable, Decoder, Encodable, Encoder, SpecializedDecoder, SpecializedEncoder, - UseSpecializedDecodable, UseSpecializedEncodable, -}; +use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder}; use rustc_session::{CrateDisambiguator, Session}; use rustc_span::hygiene::{ ExpnDataDecodeMode, ExpnDataEncodeMode, ExpnId, HygieneDecodeContext, HygieneEncodeContext, SyntaxContext, SyntaxContextData, }; use rustc_span::source_map::{SourceMap, StableSourceFileId}; -use rustc_span::symbol::Ident; use rustc_span::CachingSourceMapView; use rustc_span::{BytePos, ExpnData, SourceFile, Span, DUMMY_SP}; use std::mem; @@ -87,7 +83,7 @@ pub struct OnDiskCache<'sess> { } // This type is used only for serialization and deserialization. -#[derive(RustcEncodable, RustcDecodable)] +#[derive(Encodable, Decodable)] struct Footer { file_index_to_stable_id: FxHashMap, prev_cnums: Vec<(u32, String, CrateDisambiguator)>, @@ -105,10 +101,10 @@ type EncodedQueryResultIndex = Vec<(SerializedDepNodeIndex, AbsoluteBytePos)>; type EncodedDiagnosticsIndex = Vec<(SerializedDepNodeIndex, AbsoluteBytePos)>; type EncodedDiagnostics = Vec; -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable)] struct SourceFileIndex(u32); -#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Encodable, Decodable)] struct AbsoluteBytePos(u32); impl AbsoluteBytePos { @@ -182,7 +178,7 @@ impl<'sess> OnDiskCache<'sess> { pub fn serialize<'tcx, E>(&self, tcx: TyCtxt<'tcx>, encoder: &mut E) -> Result<(), E::Error> where - E: TyEncoder, + E: OpaqueEncoder, { // Serializing the `DepGraph` should not modify it. tcx.dep_graph.with_ignore(|| { @@ -333,7 +329,7 @@ impl<'sess> OnDiskCache<'sess> { // Encode the position of the footer as the last 8 bytes of the // file so we know where to look for it. - IntEncodedWithFixedSize(footer_pos).encode(encoder.encoder)?; + IntEncodedWithFixedSize(footer_pos).encode(encoder.encoder.opaque())?; // DO NOT WRITE ANYTHING TO THE ENCODER AFTER THIS POINT! The address // of the footer must be the last thing in the data stream. @@ -380,13 +376,13 @@ impl<'sess> OnDiskCache<'sess> { /// Returns the cached query result if there is something in the cache for /// the given `SerializedDepNodeIndex`; otherwise returns `None`. - pub fn try_load_query_result( + crate fn try_load_query_result<'tcx, T>( &self, - tcx: TyCtxt<'_>, + tcx: TyCtxt<'tcx>, dep_node_index: SerializedDepNodeIndex, ) -> Option where - T: Decodable, + T: for<'a> Decodable>, { self.load_indexed(tcx, dep_node_index, &self.query_result_index, "query result") } @@ -417,7 +413,7 @@ impl<'sess> OnDiskCache<'sess> { debug_tag: &'static str, ) -> Option where - T: Decodable, + T: for<'a> Decodable>, { let pos = index.get(&dep_node_index).cloned()?; @@ -427,14 +423,14 @@ impl<'sess> OnDiskCache<'sess> { }) } - fn with_decoder<'tcx, T, F: FnOnce(&mut CacheDecoder<'sess, 'tcx>) -> T>( + fn with_decoder<'a, 'tcx, T, F: FnOnce(&mut CacheDecoder<'sess, 'tcx>) -> T>( &'sess self, tcx: TyCtxt<'tcx>, pos: AbsoluteBytePos, f: F, ) -> T where - T: Decodable, + T: Decodable>, { let cnum_map = self.cnum_map.get_or_init(|| Self::compute_cnum_map(tcx, &self.prev_cnums[..])); @@ -492,7 +488,7 @@ impl<'sess> OnDiskCache<'sess> { /// A decoder that can read from the incr. comp. cache. It is similar to the one /// we use for crate metadata decoding in that it can rebase spans and eventually /// will also handle things that contain `Ty` instances. -struct CacheDecoder<'a, 'tcx> { +crate struct CacheDecoder<'a, 'tcx> { tcx: TyCtxt<'tcx>, opaque: opaque::Decoder<'a>, source_map: &'a SourceMap, @@ -547,8 +543,8 @@ impl<'a, 'tcx> DecoderWithPosition for CacheDecoder<'a, 'tcx> { // tag matches and the correct amount of bytes was read. fn decode_tagged(decoder: &mut D, expected_tag: T) -> Result where - T: Decodable + Eq + ::std::fmt::Debug, - V: Decodable, + T: Decodable + Eq + ::std::fmt::Debug, + V: Decodable, D: DecoderWithPosition, { let start_pos = decoder.position(); @@ -565,6 +561,8 @@ where } impl<'a, 'tcx> TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> { + const CLEAR_CROSS_CRATE: bool = false; + #[inline] fn tcx(&self) -> TyCtxt<'tcx> { self.tcx @@ -642,14 +640,19 @@ impl<'a, 'tcx> TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> { fn map_encoded_cnum_to_current(&self, cnum: CrateNum) -> CrateNum { self.cnum_map[cnum].unwrap_or_else(|| bug!("could not find new `CrateNum` for {:?}", cnum)) } + + fn decode_alloc_id(&mut self) -> Result { + let alloc_decoding_session = self.alloc_decoding_session; + alloc_decoding_session.decode_alloc_id(self) + } } -implement_ty_decoder!(CacheDecoder<'a, 'tcx>); +crate::implement_ty_decoder!(CacheDecoder<'a, 'tcx>); -impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { - fn specialized_decode(&mut self) -> Result { - let syntax_contexts = self.syntax_contexts; - rustc_span::hygiene::decode_syntax_context(self, self.hygiene_context, |this, id| { +impl<'a, 'tcx> Decodable> for SyntaxContext { + fn decode(decoder: &mut CacheDecoder<'a, 'tcx>) -> Result { + let syntax_contexts = decoder.syntax_contexts; + rustc_span::hygiene::decode_syntax_context(decoder, decoder.hygiene_context, |this, id| { // This closure is invoked if we haven't already decoded the data for the `SyntaxContext` we are deserializing. // We look up the position of the associated `SyntaxData` and decode it. let pos = syntax_contexts.get(&id).unwrap(); @@ -661,12 +664,12 @@ impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { } } -impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { - fn specialized_decode(&mut self) -> Result { - let expn_data = self.expn_data; +impl<'a, 'tcx> Decodable> for ExpnId { + fn decode(decoder: &mut CacheDecoder<'a, 'tcx>) -> Result { + let expn_data = decoder.expn_data; rustc_span::hygiene::decode_expn_id( - self, - ExpnDataDecodeMode::incr_comp(self.hygiene_context), + decoder, + ExpnDataDecodeMode::incr_comp(decoder.hygiene_context), |this, index| { // This closure is invoked if we haven't already decoded the data for the `ExpnId` we are deserializing. // We look up the position of the associated `ExpnData` and decode it. @@ -683,16 +686,9 @@ impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { } } -impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { - fn specialized_decode(&mut self) -> Result { - let alloc_decoding_session = self.alloc_decoding_session; - alloc_decoding_session.decode_alloc_id(self) - } -} - -impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { - fn specialized_decode(&mut self) -> Result { - let tag: u8 = Decodable::decode(self)?; +impl<'a, 'tcx> Decodable> for Span { + fn decode(decoder: &mut CacheDecoder<'a, 'tcx>) -> Result { + let tag: u8 = Decodable::decode(decoder)?; if tag == TAG_INVALID_SPAN { return Ok(DUMMY_SP); @@ -700,13 +696,13 @@ impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { debug_assert_eq!(tag, TAG_VALID_SPAN); } - let file_lo_index = SourceFileIndex::decode(self)?; - let line_lo = usize::decode(self)?; - let col_lo = BytePos::decode(self)?; - let len = BytePos::decode(self)?; - let ctxt = SyntaxContext::decode(self)?; + let file_lo_index = SourceFileIndex::decode(decoder)?; + let line_lo = usize::decode(decoder)?; + let col_lo = BytePos::decode(decoder)?; + let len = BytePos::decode(decoder)?; + let ctxt = SyntaxContext::decode(decoder)?; - let file_lo = self.file_index_to_file(file_lo_index); + let file_lo = decoder.file_index_to_file(file_lo_index); let lo = file_lo.lines[line_lo - 1] + col_lo; let hi = lo + len; @@ -714,10 +710,10 @@ impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { } } -impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { - fn specialized_decode(&mut self) -> Result { - // FIXME: Handle hygiene in incremental - bug!("Trying to decode Ident for incremental"); +impl<'a, 'tcx> Decodable> for CrateNum { + fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result { + let cnum = CrateNum::from_u32(u32::decode(d)?); + Ok(d.map_encoded_cnum_to_current(cnum)) } } @@ -725,43 +721,69 @@ impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { // `DefIndex` that is not contained in a `DefId`. Such a case would be problematic // because we would not know how to transform the `DefIndex` to the current // context. -impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { - fn specialized_decode(&mut self) -> Result { - bug!("trying to decode `DefIndex` outside the context of a `DefId`") +impl<'a, 'tcx> Decodable> for DefIndex { + fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result { + Err(d.error("trying to decode `DefIndex` outside the context of a `DefId`")) } } // Both the `CrateNum` and the `DefIndex` of a `DefId` can change in between two // compilation sessions. We use the `DefPathHash`, which is stable across // sessions, to map the old `DefId` to the new one. -impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { - #[inline] - fn specialized_decode(&mut self) -> Result { +impl<'a, 'tcx> Decodable> for DefId { + fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result { // Load the `DefPathHash` which is was we encoded the `DefId` as. - let def_path_hash = DefPathHash::decode(self)?; + let def_path_hash = DefPathHash::decode(d)?; // Using the `DefPathHash`, we can lookup the new `DefId`. - Ok(self.tcx().def_path_hash_to_def_id.as_ref().unwrap()[&def_path_hash]) + Ok(d.tcx().def_path_hash_to_def_id.as_ref().unwrap()[&def_path_hash]) } } -impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { - #[inline] - fn specialized_decode(&mut self) -> Result { - Ok(DefId::decode(self)?.expect_local()) - } -} - -impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { - fn specialized_decode(&mut self) -> Result { +impl<'a, 'tcx> FingerprintDecoder for CacheDecoder<'a, 'tcx> { + fn decode_fingerprint(&mut self) -> Result { Fingerprint::decode_opaque(&mut self.opaque) } } +impl<'a, 'tcx> Decodable> for &'tcx FxHashSet { + fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result { + RefDecodable::decode(d) + } +} + +impl<'a, 'tcx> Decodable> + for &'tcx IndexVec> +{ + fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result { + RefDecodable::decode(d) + } +} + +impl<'a, 'tcx> Decodable> for &'tcx [(ty::Predicate<'tcx>, Span)] { + fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result { + RefDecodable::decode(d) + } +} + +impl<'a, 'tcx> Decodable> + for &'tcx [rustc_ast::ast::InlineAsmTemplatePiece] +{ + fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result { + RefDecodable::decode(d) + } +} + +impl<'a, 'tcx> Decodable> for &'tcx [Span] { + fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result { + RefDecodable::decode(d) + } +} + //- ENCODING ------------------------------------------------------------------- /// An encoder that can write the incr. comp. cache. -struct CacheEncoder<'a, 'tcx, E: ty_codec::TyEncoder> { +struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> { tcx: TyCtxt<'tcx>, encoder: &'a mut E, type_shorthands: FxHashMap, usize>, @@ -774,7 +796,7 @@ struct CacheEncoder<'a, 'tcx, E: ty_codec::TyEncoder> { impl<'a, 'tcx, E> CacheEncoder<'a, 'tcx, E> where - E: 'a + TyEncoder, + E: 'a + OpaqueEncoder, { fn source_file_index(&mut self, source_file: Lrc) -> SourceFileIndex { self.file_to_file_index[&(&*source_file as *const SourceFile)] @@ -785,7 +807,7 @@ where /// encode the specified tag, then the given value, then the number of /// bytes taken up by tag and value. On decoding, we can then verify that /// we get the expected tag and read the expected number of bytes. - fn encode_tagged( + fn encode_tagged, V: Encodable>( &mut self, tag: T, value: &V, @@ -800,170 +822,111 @@ where } } -impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> -where - E: 'a + TyEncoder, -{ - fn specialized_encode(&mut self, alloc_id: &interpret::AllocId) -> Result<(), Self::Error> { - let (index, _) = self.interpret_allocs.insert_full(*alloc_id); - index.encode(self) +impl<'a, 'tcx> FingerprintEncoder for CacheEncoder<'a, 'tcx, rustc_serialize::opaque::Encoder> { + fn encode_fingerprint(&mut self, f: &Fingerprint) -> opaque::EncodeResult { + f.encode_opaque(self.encoder) } } -impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> +impl<'a, 'tcx, E> Encodable> for SyntaxContext where - E: 'a + TyEncoder, + E: 'a + OpaqueEncoder, { - fn specialized_encode(&mut self, ctxt: &SyntaxContext) -> Result<(), Self::Error> { - rustc_span::hygiene::raw_encode_syntax_context(*ctxt, self.hygiene_context, self) + fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> { + rustc_span::hygiene::raw_encode_syntax_context(*self, s.hygiene_context, s) } } -impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> +impl<'a, 'tcx, E> Encodable> for ExpnId where - E: 'a + TyEncoder, + E: 'a + OpaqueEncoder, { - fn specialized_encode(&mut self, expn: &ExpnId) -> Result<(), Self::Error> { + fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> { rustc_span::hygiene::raw_encode_expn_id( - *expn, - self.hygiene_context, + *self, + s.hygiene_context, ExpnDataEncodeMode::IncrComp, - self, + s, ) } } -impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> +impl<'a, 'tcx, E> Encodable> for Span where - E: 'a + TyEncoder, + E: 'a + OpaqueEncoder, { - fn specialized_encode(&mut self, span: &Span) -> Result<(), Self::Error> { - if *span == DUMMY_SP { - return TAG_INVALID_SPAN.encode(self); + fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> { + if *self == DUMMY_SP { + return TAG_INVALID_SPAN.encode(s); } - let span_data = span.data(); - let (file_lo, line_lo, col_lo) = - match self.source_map.byte_pos_to_line_and_col(span_data.lo) { - Some(pos) => pos, - None => return TAG_INVALID_SPAN.encode(self), - }; + let span_data = self.data(); + let (file_lo, line_lo, col_lo) = match s.source_map.byte_pos_to_line_and_col(span_data.lo) { + Some(pos) => pos, + None => return TAG_INVALID_SPAN.encode(s), + }; if !file_lo.contains(span_data.hi) { - return TAG_INVALID_SPAN.encode(self); + return TAG_INVALID_SPAN.encode(s); } let len = span_data.hi - span_data.lo; - let source_file_index = self.source_file_index(file_lo); + let source_file_index = s.source_file_index(file_lo); - TAG_VALID_SPAN.encode(self)?; - source_file_index.encode(self)?; - line_lo.encode(self)?; - col_lo.encode(self)?; - len.encode(self)?; - span_data.ctxt.encode(self)?; - Ok(()) + TAG_VALID_SPAN.encode(s)?; + source_file_index.encode(s)?; + line_lo.encode(s)?; + col_lo.encode(s)?; + len.encode(s)?; + span_data.ctxt.encode(s) } } -impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> +impl<'a, 'tcx, E> TyEncoder<'tcx> for CacheEncoder<'a, 'tcx, E> where - E: 'a + ty_codec::TyEncoder, + E: 'a + OpaqueEncoder, { - fn specialized_encode(&mut self, _: &Ident) -> Result<(), Self::Error> { - // We don't currently encode enough information to ensure hygiene works - // with incremental, so panic rather than risk incremental bugs. + const CLEAR_CROSS_CRATE: bool = false; - // FIXME: handle hygiene in incremental. - bug!("trying to encode `Ident` for incremental"); + fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx } -} - -impl<'a, 'tcx, E> ty_codec::TyEncoder for CacheEncoder<'a, 'tcx, E> -where - E: 'a + TyEncoder, -{ - #[inline] fn position(&self) -> usize { - self.encoder.position() + self.encoder.encoder_position() + } + fn type_shorthands(&mut self) -> &mut FxHashMap, usize> { + &mut self.type_shorthands + } + fn predicate_shorthands(&mut self) -> &mut FxHashMap, usize> { + &mut self.predicate_shorthands + } + fn encode_alloc_id(&mut self, alloc_id: &interpret::AllocId) -> Result<(), Self::Error> { + let (index, _) = self.interpret_allocs.insert_full(*alloc_id); + + index.encode(self) } } -impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> +impl<'a, 'tcx, E> Encodable> for DefId where - E: 'a + TyEncoder, + E: 'a + OpaqueEncoder, { - #[inline] - fn specialized_encode(&mut self, cnum: &CrateNum) -> Result<(), Self::Error> { - self.emit_u32(cnum.as_u32()) + fn encode(&self, s: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> { + let def_path_hash = s.tcx.def_path_hash(*self); + def_path_hash.encode(s) } } -impl<'a, 'b, 'c, 'tcx, E> SpecializedEncoder<&'b ty::TyS<'c>> for CacheEncoder<'a, 'tcx, E> +impl<'a, 'tcx, E> Encodable> for DefIndex where - E: 'a + TyEncoder, - &'b ty::TyS<'c>: UseSpecializedEncodable, + E: 'a + OpaqueEncoder, { - #[inline] - fn specialized_encode(&mut self, ty: &&'b ty::TyS<'c>) -> Result<(), Self::Error> { - debug_assert!(self.tcx.lift(ty).is_some()); - let ty = unsafe { std::mem::transmute::<&&'b ty::TyS<'c>, &&'tcx ty::TyS<'tcx>>(ty) }; - ty_codec::encode_with_shorthand(self, ty, |encoder| &mut encoder.type_shorthands) - } -} - -impl<'a, 'b, 'tcx, E> SpecializedEncoder> for CacheEncoder<'a, 'tcx, E> -where - E: 'a + TyEncoder, -{ - #[inline] - fn specialized_encode(&mut self, predicate: &ty::Predicate<'b>) -> Result<(), Self::Error> { - debug_assert!(self.tcx.lift(predicate).is_some()); - let predicate = - unsafe { std::mem::transmute::<&ty::Predicate<'b>, &ty::Predicate<'tcx>>(predicate) }; - ty_codec::encode_with_shorthand(self, predicate, |encoder| { - &mut encoder.predicate_shorthands - }) - } -} - -impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> -where - E: 'a + TyEncoder, -{ - #[inline] - fn specialized_encode(&mut self, id: &DefId) -> Result<(), Self::Error> { - let def_path_hash = self.tcx.def_path_hash(*id); - def_path_hash.encode(self) - } -} - -impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> -where - E: 'a + TyEncoder, -{ - #[inline] - fn specialized_encode(&mut self, id: &LocalDefId) -> Result<(), Self::Error> { - id.to_def_id().encode(self) - } -} - -impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> -where - E: 'a + TyEncoder, -{ - fn specialized_encode(&mut self, _: &DefIndex) -> Result<(), Self::Error> { + fn encode(&self, _: &mut CacheEncoder<'a, 'tcx, E>) -> Result<(), E::Error> { bug!("encoding `DefIndex` without context"); } } -impl<'a, 'tcx> SpecializedEncoder for CacheEncoder<'a, 'tcx, opaque::Encoder> { - fn specialized_encode(&mut self, f: &Fingerprint) -> Result<(), Self::Error> { - f.encode_opaque(&mut self.encoder) - } -} - macro_rules! encoder_methods { ($($name:ident($ty:ty);)*) => { #[inline] @@ -975,7 +938,7 @@ macro_rules! encoder_methods { impl<'a, 'tcx, E> Encoder for CacheEncoder<'a, 'tcx, E> where - E: 'a + TyEncoder, + E: 'a + OpaqueEncoder, { type Error = E::Error; @@ -1014,32 +977,29 @@ impl IntEncodedWithFixedSize { pub const ENCODED_SIZE: usize = 8; } -impl UseSpecializedEncodable for IntEncodedWithFixedSize {} -impl UseSpecializedDecodable for IntEncodedWithFixedSize {} - -impl SpecializedEncoder for opaque::Encoder { - fn specialized_encode(&mut self, x: &IntEncodedWithFixedSize) -> Result<(), Self::Error> { - let start_pos = self.position(); +impl Encodable for IntEncodedWithFixedSize { + fn encode(&self, e: &mut opaque::Encoder) -> Result<(), !> { + let start_pos = e.position(); for i in 0..IntEncodedWithFixedSize::ENCODED_SIZE { - ((x.0 >> (i * 8)) as u8).encode(self)?; + ((self.0 >> (i * 8)) as u8).encode(e)?; } - let end_pos = self.position(); + let end_pos = e.position(); assert_eq!((end_pos - start_pos), IntEncodedWithFixedSize::ENCODED_SIZE); Ok(()) } } -impl<'a> SpecializedDecoder for opaque::Decoder<'a> { - fn specialized_decode(&mut self) -> Result { +impl<'a> Decodable> for IntEncodedWithFixedSize { + fn decode(decoder: &mut opaque::Decoder<'a>) -> Result { let mut value: u64 = 0; - let start_pos = self.position(); + let start_pos = decoder.position(); for i in 0..IntEncodedWithFixedSize::ENCODED_SIZE { - let byte: u8 = Decodable::decode(self)?; + let byte: u8 = Decodable::decode(decoder)?; value |= (byte as u64) << (i * 8); } - let end_pos = self.position(); + let end_pos = decoder.position(); assert_eq!((end_pos - start_pos), IntEncodedWithFixedSize::ENCODED_SIZE); Ok(IntEncodedWithFixedSize(value)) @@ -1053,8 +1013,8 @@ fn encode_query_results<'a, 'tcx, Q, E>( ) -> Result<(), E::Error> where Q: super::QueryDescription> + super::QueryAccessors>, - Q::Value: Encodable, - E: 'a + TyEncoder, + Q::Value: Encodable>, + E: 'a + OpaqueEncoder, { let _timer = tcx .sess @@ -1066,15 +1026,16 @@ where state.iter_results(|results| { for (key, value, dep_node) in results { - if Q::cache_on_disk(tcx, &key, Some(&value)) { + if Q::cache_on_disk(tcx, &key, Some(value)) { let dep_node = SerializedDepNodeIndex::new(dep_node.index()); // Record position of the cache entry. - query_result_index.push((dep_node, AbsoluteBytePos::new(encoder.position()))); + query_result_index + .push((dep_node, AbsoluteBytePos::new(encoder.encoder.opaque().position()))); // Encode the type check tables with the `SerializedDepNodeIndex` // as tag. - encoder.encode_tagged(dep_node, &value)?; + encoder.encode_tagged(dep_node, value)?; } } Ok(()) diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 310ab4f7235..dc979e52c57 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -27,14 +27,14 @@ use std::marker::PhantomData; use std::ops::Range; use ty::util::IntTypeExt; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, Lift)] pub struct TypeAndMut<'tcx> { pub ty: Ty<'tcx>, pub mutbl: hir::Mutability, } -#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable, RustcDecodable, Copy)] +#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, TyEncodable, TyDecodable, Copy)] #[derive(HashStable)] /// A "free" region `fr` can be interpreted as "some region /// at least as big as the scope `fr.scope`". @@ -43,7 +43,7 @@ pub struct FreeRegion { pub bound_region: BoundRegion, } -#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable, RustcDecodable, Copy)] +#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, TyEncodable, TyDecodable, Copy)] #[derive(HashStable)] pub enum BoundRegion { /// An anonymous region parameter for a given fn (&T) @@ -82,7 +82,7 @@ impl BoundRegion { /// N.B., if you change this, you'll probably want to change the corresponding /// AST structure in `librustc_ast/ast.rs` as well. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable, Debug)] #[derive(HashStable)] #[rustc_diagnostic_item = "TyKind"] pub enum TyKind<'tcx> { @@ -215,7 +215,7 @@ impl TyKind<'tcx> { /// A type that is not publicly constructable. This prevents people from making `TyKind::Error` /// except through `tcx.err*()`. #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)] -#[derive(RustcEncodable, RustcDecodable, HashStable)] +#[derive(Encodable, Decodable, HashStable)] pub struct DelaySpanBugEmitted(pub(super) ()); // `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger. @@ -622,7 +622,7 @@ impl<'tcx> UpvarSubsts<'tcx> { } } -#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub enum ExistentialPredicate<'tcx> { /// E.g., `Iterator`. @@ -673,8 +673,6 @@ impl<'tcx> Binder> { } } -impl<'tcx> rustc_serialize::UseSpecializedDecodable for &'tcx List> {} - impl<'tcx> List> { /// Returns the "principal `DefId`" of this set of existential predicates. /// @@ -770,7 +768,7 @@ impl<'tcx> Binder<&'tcx List>> { /// /// Trait references also appear in object types like `Foo`, but in /// that case the `Self` parameter is absent from the substitutions. -#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct TraitRef<'tcx> { pub def_id: DefId, @@ -828,7 +826,7 @@ impl<'tcx> PolyTraitRef<'tcx> { /// /// The substitutions don't include the erased `Self`, only trait /// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct ExistentialTraitRef<'tcx> { pub def_id: DefId, @@ -884,7 +882,7 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> { /// erase, or otherwise "discharge" these bound vars, we change the /// type from `Binder` to just `T` (see /// e.g., `liberate_late_bound_regions`). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] pub struct Binder(T); impl Binder { @@ -1016,7 +1014,7 @@ impl Binder> { /// Represents the projection of an associated type. In explicit UFCS /// form this would be written `>::N`. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct ProjectionTy<'tcx> { /// The parameters of the associated item. @@ -1086,7 +1084,7 @@ impl<'tcx> PolyGenSig<'tcx> { /// - `inputs`: is the list of arguments and their modes. /// - `output`: is the return type. /// - `c_variadic`: indicates whether this is a C-variadic function. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct FnSig<'tcx> { pub inputs_and_output: &'tcx List>, @@ -1147,7 +1145,7 @@ impl<'tcx> PolyFnSig<'tcx> { pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder>>; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] #[derive(HashStable)] pub struct ParamTy { pub index: u32, @@ -1172,7 +1170,7 @@ impl<'tcx> ParamTy { } } -#[derive(Copy, Clone, Hash, RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)] +#[derive(Copy, Clone, Hash, TyEncodable, TyDecodable, Eq, PartialEq, Ord, PartialOrd)] #[derive(HashStable)] pub struct ParamConst { pub index: u32, @@ -1345,7 +1343,7 @@ pub type Region<'tcx> = &'tcx RegionKind; /// [1]: http://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/ /// [2]: http://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/ /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html -#[derive(Clone, PartialEq, Eq, Hash, Copy, RustcEncodable, RustcDecodable, PartialOrd, Ord)] +#[derive(Clone, PartialEq, Eq, Hash, Copy, TyEncodable, TyDecodable, PartialOrd, Ord)] pub enum RegionKind { /// Region bound in a type or fn declaration which will be /// substituted 'early' -- that is, at the same time when type @@ -1383,32 +1381,30 @@ pub enum RegionKind { ReErased, } -impl<'tcx> rustc_serialize::UseSpecializedDecodable for Region<'tcx> {} - -#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, PartialOrd, Ord)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, PartialOrd, Ord)] pub struct EarlyBoundRegion { pub def_id: DefId, pub index: u32, pub name: Symbol, } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] pub struct TyVid { pub index: u32, } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] pub struct ConstVid<'tcx> { pub index: u32, pub phantom: PhantomData<&'tcx ()>, } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] pub struct IntVid { pub index: u32, } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] pub struct FloatVid { pub index: u32, } @@ -1425,7 +1421,7 @@ impl Atom for RegionVid { } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] #[derive(HashStable)] pub enum InferTy { TyVar(TyVid), @@ -1444,14 +1440,14 @@ rustc_index::newtype_index! { pub struct BoundVar { .. } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable)] pub struct BoundTy { pub var: BoundVar, pub kind: BoundTyKind, } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable)] pub enum BoundTyKind { Anon, @@ -1465,7 +1461,7 @@ impl From for BoundTy { } /// A `ProjectionPredicate` for an `ExistentialTraitRef`. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable)] pub struct ExistentialProjection<'tcx> { pub item_def_id: DefId, diff --git a/src/librustc_middle/ty/subst.rs b/src/librustc_middle/ty/subst.rs index 866b529f35e..acd58ab7f96 100644 --- a/src/librustc_middle/ty/subst.rs +++ b/src/librustc_middle/ty/subst.rs @@ -1,13 +1,14 @@ // Type substitutions. use crate::infer::canonical::Canonical; +use crate::ty::codec::{TyDecoder, TyEncoder}; use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use crate::ty::sty::{ClosureSubsts, GeneratorSubsts}; use crate::ty::{self, Lift, List, ParamConst, Ty, TyCtxt}; use rustc_hir::def_id::DefId; use rustc_macros::HashStable; -use rustc_serialize::{self, Decodable, Decoder, Encodable, Encoder}; +use rustc_serialize::{self, Decodable, Encodable}; use rustc_span::{Span, DUMMY_SP}; use smallvec::SmallVec; @@ -34,7 +35,7 @@ const TYPE_TAG: usize = 0b00; const REGION_TAG: usize = 0b01; const CONST_TAG: usize = 0b10; -#[derive(Debug, RustcEncodable, RustcDecodable, PartialEq, Eq, PartialOrd, Ord, HashStable)] +#[derive(Debug, TyEncodable, TyDecodable, PartialEq, Eq, PartialOrd, Ord, HashStable)] pub enum GenericArgKind<'tcx> { Lifetime(ty::Region<'tcx>), Type(Ty<'tcx>), @@ -168,14 +169,14 @@ impl<'tcx> TypeFoldable<'tcx> for GenericArg<'tcx> { } } -impl<'tcx> Encodable for GenericArg<'tcx> { - fn encode(&self, e: &mut E) -> Result<(), E::Error> { +impl<'tcx, E: TyEncoder<'tcx>> Encodable for GenericArg<'tcx> { + fn encode(&self, e: &mut E) -> Result<(), E::Error> { self.unpack().encode(e) } } -impl<'tcx> Decodable for GenericArg<'tcx> { - fn decode(d: &mut D) -> Result, D::Error> { +impl<'tcx, D: TyDecoder<'tcx>> Decodable for GenericArg<'tcx> { + fn decode(d: &mut D) -> Result, D::Error> { Ok(GenericArgKind::decode(d)?.pack()) } } @@ -396,8 +397,6 @@ impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> { } } -impl<'tcx> rustc_serialize::UseSpecializedDecodable for SubstsRef<'tcx> {} - /////////////////////////////////////////////////////////////////////////// // Public trait `Subst` // @@ -653,7 +652,7 @@ pub type CanonicalUserSubsts<'tcx> = Canonical<'tcx, UserSubsts<'tcx>>; /// Stores the user-given substs to reach some fully qualified path /// (e.g., `::Item` or `::Item`). -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, Lift)] pub struct UserSubsts<'tcx> { /// The substitutions for the item as given by the user. @@ -680,7 +679,7 @@ pub struct UserSubsts<'tcx> { /// the impl (with the substs from `UserSubsts`) and apply those to /// the self type, giving `Foo`. Finally, we unify that with /// the self type here, which contains `?A` to be `&'static u32` -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, Lift)] pub struct UserSelfTy<'tcx> { pub impl_def_id: DefId, diff --git a/src/librustc_middle/ty/trait_def.rs b/src/librustc_middle/ty/trait_def.rs index f93cce3f4da..86fe3ac3751 100644 --- a/src/librustc_middle/ty/trait_def.rs +++ b/src/librustc_middle/ty/trait_def.rs @@ -47,7 +47,7 @@ pub struct TraitDef { /// Whether this trait is treated specially by the standard library /// specialization lint. -#[derive(HashStable, PartialEq, Clone, Copy, RustcEncodable, RustcDecodable)] +#[derive(HashStable, PartialEq, Clone, Copy, TyEncodable, TyDecodable)] pub enum TraitSpecializationKind { /// The default. Specializing on this trait is not allowed. None, diff --git a/src/librustc_middle/ty/util.rs b/src/librustc_middle/ty/util.rs index 07221082048..23507ac830d 100644 --- a/src/librustc_middle/ty/util.rs +++ b/src/librustc_middle/ty/util.rs @@ -1143,7 +1143,7 @@ pub fn needs_drop_components( } } -#[derive(Copy, Clone, Debug, HashStable, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, HashStable, TyEncodable, TyDecodable)] pub struct AlwaysRequiresDrop; /// Normalizes all opaque types in the given value, replacing them diff --git a/src/librustc_query_system/Cargo.toml b/src/librustc_query_system/Cargo.toml index 64af9c5f1a1..c1ec452e001 100644 --- a/src/librustc_query_system/Cargo.toml +++ b/src/librustc_query_system/Cargo.toml @@ -15,6 +15,7 @@ log = { package = "tracing", version = "0.1" } rustc-rayon-core = "0.3.0" rustc_data_structures = { path = "../librustc_data_structures" } rustc_errors = { path = "../librustc_errors" } +rustc_macros = { path = "../librustc_macros" } rustc_index = { path = "../librustc_index" } rustc_serialize = { path = "../librustc_serialize" } rustc_span = { path = "../librustc_span" } diff --git a/src/librustc_query_system/dep_graph/dep_node.rs b/src/librustc_query_system/dep_graph/dep_node.rs index 002b0f9c165..e302784cc3e 100644 --- a/src/librustc_query_system/dep_graph/dep_node.rs +++ b/src/librustc_query_system/dep_graph/dep_node.rs @@ -50,7 +50,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use std::fmt; use std::hash::Hash; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)] pub struct DepNode { pub kind: K, pub hash: Fingerprint, @@ -152,7 +152,8 @@ impl DepNodeParams for () { /// some independent path or string that persists between runs without /// the need to be mapped or unmapped. (This ensures we can serialize /// them even in the absence of a tcx.) -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Encodable, Decodable)] pub struct WorkProductId { hash: Fingerprint, } diff --git a/src/librustc_query_system/dep_graph/graph.rs b/src/librustc_query_system/dep_graph/graph.rs index 04a45090b72..d70306b4869 100644 --- a/src/librustc_query_system/dep_graph/graph.rs +++ b/src/librustc_query_system/dep_graph/graph.rs @@ -857,7 +857,7 @@ impl DepGraph { /// may be added -- for example, new monomorphizations -- even if /// nothing in P changed!). We will compare that hash against the /// previous hash. If it matches up, we can reuse the object file. -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, Encodable, Decodable)] pub struct WorkProduct { pub cgu_name: String, /// Saved file associated with this CGU. diff --git a/src/librustc_query_system/dep_graph/prev.rs b/src/librustc_query_system/dep_graph/prev.rs index 5cba64cac4b..29357ce9449 100644 --- a/src/librustc_query_system/dep_graph/prev.rs +++ b/src/librustc_query_system/dep_graph/prev.rs @@ -3,7 +3,7 @@ use super::{DepKind, DepNode}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; -#[derive(Debug, RustcEncodable, RustcDecodable)] +#[derive(Debug, Encodable, Decodable)] pub struct PreviousDepGraph { data: SerializedDepGraph, index: FxHashMap, SerializedDepNodeIndex>, diff --git a/src/librustc_query_system/dep_graph/serialized.rs b/src/librustc_query_system/dep_graph/serialized.rs index 4a89da23ea6..932c6d2a2f1 100644 --- a/src/librustc_query_system/dep_graph/serialized.rs +++ b/src/librustc_query_system/dep_graph/serialized.rs @@ -9,7 +9,7 @@ rustc_index::newtype_index! { } /// Data for use when recompiling the **current crate**. -#[derive(Debug, RustcEncodable, RustcDecodable)] +#[derive(Debug, Encodable, Decodable)] pub struct SerializedDepGraph { /// The set of all DepNodes in the graph pub nodes: IndexVec>, diff --git a/src/librustc_query_system/lib.rs b/src/librustc_query_system/lib.rs index 4bbba7befe9..db104398f16 100644 --- a/src/librustc_query_system/lib.rs +++ b/src/librustc_query_system/lib.rs @@ -10,6 +10,8 @@ extern crate log; #[macro_use] extern crate rustc_data_structures; +#[macro_use] +extern crate rustc_macros; pub mod cache; pub mod dep_graph; diff --git a/src/librustc_serialize/collection_impls.rs b/src/librustc_serialize/collection_impls.rs index 49b8094abd0..3d274cb0150 100644 --- a/src/librustc_serialize/collection_impls.rs +++ b/src/librustc_serialize/collection_impls.rs @@ -9,8 +9,8 @@ use std::sync::Arc; use smallvec::{Array, SmallVec}; -impl> Encodable for SmallVec { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl>> Encodable for SmallVec { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s))?; @@ -20,8 +20,8 @@ impl> Encodable for SmallVec { } } -impl> Decodable for SmallVec { - fn decode(d: &mut D) -> Result, D::Error> { +impl>> Decodable for SmallVec { + fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut vec = SmallVec::with_capacity(len); // FIXME(#48994) - could just be collected into a Result @@ -33,8 +33,8 @@ impl> Decodable for SmallVec { } } -impl Encodable for LinkedList { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl> Encodable for LinkedList { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s))?; @@ -44,8 +44,8 @@ impl Encodable for LinkedList { } } -impl Decodable for LinkedList { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for LinkedList { + fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut list = LinkedList::new(); for i in 0..len { @@ -56,8 +56,8 @@ impl Decodable for LinkedList { } } -impl Encodable for VecDeque { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl> Encodable for VecDeque { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s))?; @@ -67,8 +67,8 @@ impl Encodable for VecDeque { } } -impl Decodable for VecDeque { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for VecDeque { + fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut deque: VecDeque = VecDeque::with_capacity(len); for i in 0..len { @@ -79,12 +79,12 @@ impl Decodable for VecDeque { } } -impl Encodable for BTreeMap +impl Encodable for BTreeMap where - K: Encodable + PartialEq + Ord, - V: Encodable, + K: Encodable + PartialEq + Ord, + V: Encodable, { - fn encode(&self, e: &mut S) -> Result<(), S::Error> { + fn encode(&self, e: &mut S) -> Result<(), S::Error> { e.emit_map(self.len(), |e| { for (i, (key, val)) in self.iter().enumerate() { e.emit_map_elt_key(i, |e| key.encode(e))?; @@ -95,12 +95,12 @@ where } } -impl Decodable for BTreeMap +impl Decodable for BTreeMap where - K: Decodable + PartialEq + Ord, - V: Decodable, + K: Decodable + PartialEq + Ord, + V: Decodable, { - fn decode(d: &mut D) -> Result, D::Error> { + fn decode(d: &mut D) -> Result, D::Error> { d.read_map(|d, len| { let mut map = BTreeMap::new(); for i in 0..len { @@ -113,11 +113,11 @@ where } } -impl Encodable for BTreeSet +impl Encodable for BTreeSet where - T: Encodable + PartialEq + Ord, + T: Encodable + PartialEq + Ord, { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s))?; @@ -127,11 +127,11 @@ where } } -impl Decodable for BTreeSet +impl Decodable for BTreeSet where - T: Decodable + PartialEq + Ord, + T: Decodable + PartialEq + Ord, { - fn decode(d: &mut D) -> Result, D::Error> { + fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut set = BTreeSet::new(); for i in 0..len { @@ -142,13 +142,13 @@ where } } -impl Encodable for HashMap +impl Encodable for HashMap where - K: Encodable + Eq, - V: Encodable, + K: Encodable + Eq, + V: Encodable, S: BuildHasher, { - fn encode(&self, e: &mut E) -> Result<(), E::Error> { + fn encode(&self, e: &mut E) -> Result<(), E::Error> { e.emit_map(self.len(), |e| { for (i, (key, val)) in self.iter().enumerate() { e.emit_map_elt_key(i, |e| key.encode(e))?; @@ -159,13 +159,13 @@ where } } -impl Decodable for HashMap +impl Decodable for HashMap where - K: Decodable + Hash + Eq, - V: Decodable, + K: Decodable + Hash + Eq, + V: Decodable, S: BuildHasher + Default, { - fn decode(d: &mut D) -> Result, D::Error> { + fn decode(d: &mut D) -> Result, D::Error> { d.read_map(|d, len| { let state = Default::default(); let mut map = HashMap::with_capacity_and_hasher(len, state); @@ -179,12 +179,12 @@ where } } -impl Encodable for HashSet +impl Encodable for HashSet where - T: Encodable + Eq, + T: Encodable + Eq, S: BuildHasher, { - fn encode(&self, s: &mut E) -> Result<(), E::Error> { + fn encode(&self, s: &mut E) -> Result<(), E::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s))?; @@ -194,12 +194,22 @@ where } } -impl Decodable for HashSet +impl Encodable for &HashSet where - T: Decodable + Hash + Eq, + T: Encodable + Eq, + S: BuildHasher, +{ + fn encode(&self, s: &mut E) -> Result<(), E::Error> { + (**self).encode(s) + } +} + +impl Decodable for HashSet +where + T: Decodable + Hash + Eq, S: BuildHasher + Default, { - fn decode(d: &mut D) -> Result, D::Error> { + fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let state = Default::default(); let mut set = HashSet::with_capacity_and_hasher(len, state); @@ -211,13 +221,13 @@ where } } -impl Encodable for indexmap::IndexMap +impl Encodable for indexmap::IndexMap where - K: Encodable + Hash + Eq, - V: Encodable, + K: Encodable + Hash + Eq, + V: Encodable, S: BuildHasher, { - fn encode(&self, e: &mut E) -> Result<(), E::Error> { + fn encode(&self, e: &mut E) -> Result<(), E::Error> { e.emit_map(self.len(), |e| { for (i, (key, val)) in self.iter().enumerate() { e.emit_map_elt_key(i, |e| key.encode(e))?; @@ -228,13 +238,13 @@ where } } -impl Decodable for indexmap::IndexMap +impl Decodable for indexmap::IndexMap where - K: Decodable + Hash + Eq, - V: Decodable, + K: Decodable + Hash + Eq, + V: Decodable, S: BuildHasher + Default, { - fn decode(d: &mut D) -> Result, D::Error> { + fn decode(d: &mut D) -> Result, D::Error> { d.read_map(|d, len| { let state = Default::default(); let mut map = indexmap::IndexMap::with_capacity_and_hasher(len, state); @@ -248,12 +258,12 @@ where } } -impl Encodable for indexmap::IndexSet +impl Encodable for indexmap::IndexSet where - T: Encodable + Hash + Eq, + T: Encodable + Hash + Eq, S: BuildHasher, { - fn encode(&self, s: &mut E) -> Result<(), E::Error> { + fn encode(&self, s: &mut E) -> Result<(), E::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s))?; @@ -263,12 +273,12 @@ where } } -impl Decodable for indexmap::IndexSet +impl Decodable for indexmap::IndexSet where - T: Decodable + Hash + Eq, + T: Decodable + Hash + Eq, S: BuildHasher + Default, { - fn decode(d: &mut D) -> Result, D::Error> { + fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let state = Default::default(); let mut set = indexmap::IndexSet::with_capacity_and_hasher(len, state); @@ -280,8 +290,8 @@ where } } -impl Encodable for Rc<[T]> { - fn encode(&self, s: &mut E) -> Result<(), E::Error> { +impl> Encodable for Rc<[T]> { + fn encode(&self, s: &mut E) -> Result<(), E::Error> { s.emit_seq(self.len(), |s| { for (index, e) in self.iter().enumerate() { s.emit_seq_elt(index, |s| e.encode(s))?; @@ -291,8 +301,8 @@ impl Encodable for Rc<[T]> { } } -impl Decodable for Rc<[T]> { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for Rc<[T]> { + fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut vec = Vec::with_capacity(len); for index in 0..len { @@ -303,8 +313,8 @@ impl Decodable for Rc<[T]> { } } -impl Encodable for Arc<[T]> { - fn encode(&self, s: &mut E) -> Result<(), E::Error> { +impl> Encodable for Arc<[T]> { + fn encode(&self, s: &mut E) -> Result<(), E::Error> { s.emit_seq(self.len(), |s| { for (index, e) in self.iter().enumerate() { s.emit_seq_elt(index, |s| e.encode(s))?; @@ -314,8 +324,8 @@ impl Encodable for Arc<[T]> { } } -impl Decodable for Arc<[T]> { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for Arc<[T]> { + fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut vec = Vec::with_capacity(len); for index in 0..len { diff --git a/src/librustc_serialize/json.rs b/src/librustc_serialize/json.rs index ab7f6975325..dafeb053d83 100644 --- a/src/librustc_serialize/json.rs +++ b/src/librustc_serialize/json.rs @@ -292,7 +292,7 @@ pub fn error_str(error: ErrorCode) -> &'static str { } /// Shortcut function to decode a JSON `&str` into an object -pub fn decode(s: &str) -> DecodeResult { +pub fn decode>(s: &str) -> DecodeResult { let json = match from_str(s) { Ok(x) => x, Err(e) => return Err(ParseError(e)), @@ -303,7 +303,9 @@ pub fn decode(s: &str) -> DecodeResult { } /// Shortcut function to encode a `T` into a JSON `String` -pub fn encode(object: &T) -> Result { +pub fn encode crate::Encodable>>( + object: &T, +) -> Result { let mut s = String::new(); { let mut encoder = Encoder::new(&mut s); @@ -1144,8 +1146,8 @@ impl<'a> crate::Encoder for PrettyEncoder<'a> { } } -impl Encodable for Json { - fn encode(&self, e: &mut E) -> Result<(), E::Error> { +impl Encodable for Json { + fn encode(&self, e: &mut E) -> Result<(), E::Error> { match *self { Json::I64(v) => v.encode(e), Json::U64(v) => v.encode(e), @@ -2727,7 +2729,7 @@ impl<'a> fmt::Display for PrettyJson<'a> { } } -impl<'a, T: Encodable> fmt::Display for AsJson<'a, T> { +impl<'a, T: for<'r> Encodable>> fmt::Display for AsJson<'a, T> { /// Encodes a json value into a string fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut shim = FormatShim { inner: f }; @@ -2747,7 +2749,7 @@ impl<'a, T> AsPrettyJson<'a, T> { } } -impl<'a, T: Encodable> fmt::Display for AsPrettyJson<'a, T> { +impl<'a, T: for<'x> Encodable>> fmt::Display for AsPrettyJson<'a, T> { /// Encodes a json value into a string fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut shim = FormatShim { inner: f }; diff --git a/src/librustc_serialize/lib.rs b/src/librustc_serialize/lib.rs index 3dc3e783820..265b3b95e95 100644 --- a/src/librustc_serialize/lib.rs +++ b/src/librustc_serialize/lib.rs @@ -10,7 +10,6 @@ Core encoding and decoding interfaces. test(attr(allow(unused_variables), deny(warnings))) )] #![feature(box_syntax)] -#![feature(min_specialization)] #![feature(never_type)] #![feature(nll)] #![feature(associated_type_bounds)] @@ -19,9 +18,6 @@ Core encoding and decoding interfaces. pub use self::serialize::{Decodable, Decoder, Encodable, Encoder}; -pub use self::serialize::{SpecializationError, SpecializedDecoder, SpecializedEncoder}; -pub use self::serialize::{UseSpecializedDecodable, UseSpecializedEncodable}; - mod collection_impls; mod serialize; diff --git a/src/librustc_serialize/serialize.rs b/src/librustc_serialize/serialize.rs index 29c5737ad89..d279954bf91 100644 --- a/src/librustc_serialize/serialize.rs +++ b/src/librustc_serialize/serialize.rs @@ -4,7 +4,6 @@ Core encoding and decoding interfaces. */ -use std::any; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::marker::PhantomData; @@ -380,282 +379,288 @@ pub trait Decoder { fn error(&mut self, err: &str) -> Self::Error; } -pub trait Encodable { - fn encode(&self, s: &mut S) -> Result<(), S::Error>; +pub trait Encodable { + fn encode(&self, s: &mut S) -> Result<(), S::Error>; } -pub trait Decodable: Sized { - fn decode(d: &mut D) -> Result; +pub trait Decodable: Sized { + fn decode(d: &mut D) -> Result; } -impl Encodable for usize { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for usize { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_usize(*self) } } -impl Decodable for usize { - fn decode(d: &mut D) -> Result { +impl Decodable for usize { + fn decode(d: &mut D) -> Result { d.read_usize() } } -impl Encodable for u8 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for u8 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u8(*self) } } -impl Decodable for u8 { - fn decode(d: &mut D) -> Result { +impl Decodable for u8 { + fn decode(d: &mut D) -> Result { d.read_u8() } } -impl Encodable for u16 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for u16 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u16(*self) } } -impl Decodable for u16 { - fn decode(d: &mut D) -> Result { +impl Decodable for u16 { + fn decode(d: &mut D) -> Result { d.read_u16() } } -impl Encodable for u32 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for u32 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u32(*self) } } -impl Decodable for u32 { - fn decode(d: &mut D) -> Result { +impl Decodable for u32 { + fn decode(d: &mut D) -> Result { d.read_u32() } } -impl Encodable for ::std::num::NonZeroU32 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for ::std::num::NonZeroU32 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u32(self.get()) } } -impl Decodable for ::std::num::NonZeroU32 { - fn decode(d: &mut D) -> Result { +impl Decodable for ::std::num::NonZeroU32 { + fn decode(d: &mut D) -> Result { d.read_u32().map(|d| ::std::num::NonZeroU32::new(d).unwrap()) } } -impl Encodable for u64 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for u64 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u64(*self) } } -impl Decodable for u64 { - fn decode(d: &mut D) -> Result { +impl Decodable for u64 { + fn decode(d: &mut D) -> Result { d.read_u64() } } -impl Encodable for u128 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for u128 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u128(*self) } } -impl Decodable for u128 { - fn decode(d: &mut D) -> Result { +impl Decodable for u128 { + fn decode(d: &mut D) -> Result { d.read_u128() } } -impl Encodable for isize { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for isize { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_isize(*self) } } -impl Decodable for isize { - fn decode(d: &mut D) -> Result { +impl Decodable for isize { + fn decode(d: &mut D) -> Result { d.read_isize() } } -impl Encodable for i8 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for i8 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_i8(*self) } } -impl Decodable for i8 { - fn decode(d: &mut D) -> Result { +impl Decodable for i8 { + fn decode(d: &mut D) -> Result { d.read_i8() } } -impl Encodable for i16 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for i16 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_i16(*self) } } -impl Decodable for i16 { - fn decode(d: &mut D) -> Result { +impl Decodable for i16 { + fn decode(d: &mut D) -> Result { d.read_i16() } } -impl Encodable for i32 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for i32 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_i32(*self) } } -impl Decodable for i32 { - fn decode(d: &mut D) -> Result { +impl Decodable for i32 { + fn decode(d: &mut D) -> Result { d.read_i32() } } -impl Encodable for i64 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for i64 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_i64(*self) } } -impl Decodable for i64 { - fn decode(d: &mut D) -> Result { +impl Decodable for i64 { + fn decode(d: &mut D) -> Result { d.read_i64() } } -impl Encodable for i128 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for i128 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_i128(*self) } } -impl Decodable for i128 { - fn decode(d: &mut D) -> Result { +impl Decodable for i128 { + fn decode(d: &mut D) -> Result { d.read_i128() } } -impl Encodable for str { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for str { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_str(self) } } -impl Encodable for String { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for &str { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { + s.emit_str(self) + } +} + +impl Encodable for String { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_str(&self[..]) } } -impl Decodable for String { - fn decode(d: &mut D) -> Result { +impl Decodable for String { + fn decode(d: &mut D) -> Result { Ok(d.read_str()?.into_owned()) } } -impl Encodable for f32 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for f32 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_f32(*self) } } -impl Decodable for f32 { - fn decode(d: &mut D) -> Result { +impl Decodable for f32 { + fn decode(d: &mut D) -> Result { d.read_f32() } } -impl Encodable for f64 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for f64 { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_f64(*self) } } -impl Decodable for f64 { - fn decode(d: &mut D) -> Result { +impl Decodable for f64 { + fn decode(d: &mut D) -> Result { d.read_f64() } } -impl Encodable for bool { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for bool { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_bool(*self) } } -impl Decodable for bool { - fn decode(d: &mut D) -> Result { +impl Decodable for bool { + fn decode(d: &mut D) -> Result { d.read_bool() } } -impl Encodable for char { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for char { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_char(*self) } } -impl Decodable for char { - fn decode(d: &mut D) -> Result { +impl Decodable for char { + fn decode(d: &mut D) -> Result { d.read_char() } } -impl Encodable for () { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for () { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_unit() } } -impl Decodable for () { - fn decode(d: &mut D) -> Result<(), D::Error> { +impl Decodable for () { + fn decode(d: &mut D) -> Result<(), D::Error> { d.read_nil() } } -impl Encodable for PhantomData { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for PhantomData { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_unit() } } -impl Decodable for PhantomData { - fn decode(d: &mut D) -> Result, D::Error> { +impl Decodable for PhantomData { + fn decode(d: &mut D) -> Result, D::Error> { d.read_nil()?; Ok(PhantomData) } } -impl Decodable for Box<[T]> { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for Box<[T]> { + fn decode(d: &mut D) -> Result, D::Error> { let v: Vec = Decodable::decode(d)?; Ok(v.into_boxed_slice()) } } -impl Encodable for Rc { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl> Encodable for Rc { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { (**self).encode(s) } } -impl Decodable for Rc { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for Rc { + fn decode(d: &mut D) -> Result, D::Error> { Ok(Rc::new(Decodable::decode(d)?)) } } -impl Encodable for [T] { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl> Encodable for [T] { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s))? @@ -665,8 +670,8 @@ impl Encodable for [T] { } } -impl Encodable for Vec { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl> Encodable for Vec { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s))? @@ -676,8 +681,8 @@ impl Encodable for Vec { } } -impl Decodable for Vec { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for Vec { + fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut v = Vec::with_capacity(len); for i in 0..len { @@ -688,8 +693,8 @@ impl Decodable for Vec { } } -impl Encodable for [u8; 20] { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for [u8; 20] { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s))? @@ -699,8 +704,8 @@ impl Encodable for [u8; 20] { } } -impl Decodable for [u8; 20] { - fn decode(d: &mut D) -> Result<[u8; 20], D::Error> { +impl Decodable for [u8; 20] { + fn decode(d: &mut D) -> Result<[u8; 20], D::Error> { d.read_seq(|d, len| { assert!(len == 20); let mut v = [0u8; 20]; @@ -712,11 +717,11 @@ impl Decodable for [u8; 20] { } } -impl<'a, T: Encodable> Encodable for Cow<'a, [T]> +impl<'a, S: Encoder, T: Encodable> Encodable for Cow<'a, [T]> where [T]: ToOwned>, { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_seq(self.len(), |s| { for (i, e) in self.iter().enumerate() { s.emit_seq_elt(i, |s| e.encode(s))? @@ -726,11 +731,11 @@ where } } -impl Decodable for Cow<'static, [T]> +impl + ToOwned> Decodable for Cow<'static, [T]> where [T]: ToOwned>, { - fn decode(d: &mut D) -> Result, D::Error> { + fn decode(d: &mut D) -> Result, D::Error> { d.read_seq(|d, len| { let mut v = Vec::with_capacity(len); for i in 0..len { @@ -741,8 +746,8 @@ where } } -impl Encodable for Option { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl> Encodable for Option { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_option(|s| match *self { None => s.emit_option_none(), Some(ref v) => s.emit_option_some(|s| v.encode(s)), @@ -750,14 +755,14 @@ impl Encodable for Option { } } -impl Decodable for Option { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for Option { + fn decode(d: &mut D) -> Result, D::Error> { d.read_option(|d, b| if b { Ok(Some(Decodable::decode(d)?)) } else { Ok(None) }) } } -impl Encodable for Result { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl, T2: Encodable> Encodable for Result { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_enum("Result", |s| match *self { Ok(ref v) => { s.emit_enum_variant("Ok", 0, 1, |s| s.emit_enum_variant_arg(0, |s| v.encode(s))) @@ -769,8 +774,8 @@ impl Encodable for Result { } } -impl Decodable for Result { - fn decode(d: &mut D) -> Result, D::Error> { +impl, T2: Decodable> Decodable for Result { + fn decode(d: &mut D) -> Result, D::Error> { d.read_enum("Result", |d| { d.read_enum_variant(&["Ok", "Err"], |d, disr| match disr { 0 => Ok(Ok(d.read_enum_variant_arg(0, |d| T1::decode(d))?)), @@ -806,9 +811,9 @@ macro_rules! count { macro_rules! tuple { () => (); ( $($name:ident,)+ ) => ( - impl<$($name:Decodable),+> Decodable for ($($name,)+) { + impl),+> Decodable for ($($name,)+) { #[allow(non_snake_case)] - fn decode(d: &mut D) -> Result<($($name,)+), D::Error> { + fn decode(d: &mut D) -> Result<($($name,)+), D::Error> { let len: usize = count!($($name)+); d.read_tuple(len, |d| { let mut i = 0; @@ -819,9 +824,9 @@ macro_rules! tuple { }) } } - impl<$($name:Encodable),+> Encodable for ($($name,)+) { + impl),+> Encodable for ($($name,)+) { #[allow(non_snake_case)] - fn encode(&self, s: &mut S) -> Result<(), S::Error> { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { let ($(ref $name,)+) = *self; let mut n = 0; $(let $name = $name; n += 1;)+ @@ -838,33 +843,33 @@ macro_rules! tuple { tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, } -impl Encodable for path::Path { - fn encode(&self, e: &mut S) -> Result<(), S::Error> { +impl Encodable for path::Path { + fn encode(&self, e: &mut S) -> Result<(), S::Error> { self.to_str().unwrap().encode(e) } } -impl Encodable for path::PathBuf { - fn encode(&self, e: &mut S) -> Result<(), S::Error> { +impl Encodable for path::PathBuf { + fn encode(&self, e: &mut S) -> Result<(), S::Error> { path::Path::encode(self, e) } } -impl Decodable for path::PathBuf { - fn decode(d: &mut D) -> Result { +impl Decodable for path::PathBuf { + fn decode(d: &mut D) -> Result { let bytes: String = Decodable::decode(d)?; Ok(path::PathBuf::from(bytes)) } } -impl Encodable for Cell { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl + Copy> Encodable for Cell { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { self.get().encode(s) } } -impl Decodable for Cell { - fn decode(d: &mut D) -> Result, D::Error> { +impl + Copy> Decodable for Cell { + fn decode(d: &mut D) -> Result, D::Error> { Ok(Cell::new(Decodable::decode(d)?)) } } @@ -874,136 +879,37 @@ impl Decodable for Cell { // `encoder.error("attempting to Encode borrowed RefCell")` // from `encode` when `try_borrow` returns `None`. -impl Encodable for RefCell { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl> Encodable for RefCell { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { self.borrow().encode(s) } } -impl Decodable for RefCell { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for RefCell { + fn decode(d: &mut D) -> Result, D::Error> { Ok(RefCell::new(Decodable::decode(d)?)) } } -impl Encodable for Arc { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl> Encodable for Arc { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { (**self).encode(s) } } -impl Decodable for Arc { - fn decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for Arc { + fn decode(d: &mut D) -> Result, D::Error> { Ok(Arc::new(Decodable::decode(d)?)) } } -// ___________________________________________________________________________ -// Specialization-based interface for multi-dispatch Encodable/Decodable. - -/// Implement this trait on your `{Encodable,Decodable}::Error` types -/// to override the default panic behavior for missing specializations. -pub trait SpecializationError { - /// Creates an error for a missing method specialization. - /// Defaults to panicking with type, trait & method names. - /// `S` is the encoder/decoder state type, - /// `T` is the type being encoded/decoded, and - /// the arguments are the names of the trait - /// and method that should've been overridden. - fn not_found(trait_name: &'static str, method_name: &'static str) -> Self; -} - -impl SpecializationError for E { - default fn not_found(trait_name: &'static str, method_name: &'static str) -> E { - panic!( - "missing specialization: `<{} as {}<{}>>::{}` not overridden", - any::type_name::(), - trait_name, - any::type_name::(), - method_name - ); - } -} - -/// Implement this trait on encoders, with `T` being the type -/// you want to encode (employing `UseSpecializedEncodable`), -/// using a strategy specific to the encoder. -pub trait SpecializedEncoder: Encoder { - /// Encode the value in a manner specific to this encoder state. - fn specialized_encode(&mut self, value: &T) -> Result<(), Self::Error>; -} - -impl SpecializedEncoder for E { - default fn specialized_encode(&mut self, value: &T) -> Result<(), E::Error> { - value.default_encode(self) - } -} - -/// Implement this trait on decoders, with `T` being the type -/// you want to decode (employing `UseSpecializedDecodable`), -/// using a strategy specific to the decoder. -pub trait SpecializedDecoder: Decoder { - /// Decode a value in a manner specific to this decoder state. - fn specialized_decode(&mut self) -> Result; -} - -impl SpecializedDecoder for D { - default fn specialized_decode(&mut self) -> Result { - T::default_decode(self) - } -} - -/// Implement this trait on your type to get an `Encodable` -/// implementation which goes through `SpecializedEncoder`. -pub trait UseSpecializedEncodable { - /// Defaults to returning an error (see `SpecializationError`). - fn default_encode(&self, _: &mut E) -> Result<(), E::Error> { - Err(E::Error::not_found::("SpecializedEncoder", "specialized_encode")) - } -} - -impl Encodable for T { - default fn encode(&self, e: &mut E) -> Result<(), E::Error> { - E::specialized_encode(e, self) - } -} - -/// Implement this trait on your type to get an `Decodable` -/// implementation which goes through `SpecializedDecoder`. -pub trait UseSpecializedDecodable: Sized { - /// Defaults to returning an error (see `SpecializationError`). - fn default_decode(_: &mut D) -> Result { - Err(D::Error::not_found::("SpecializedDecoder", "specialized_decode")) - } -} - -impl Decodable for T { - default fn decode(d: &mut D) -> Result { - D::specialized_decode(d) - } -} - -// Can't avoid specialization for &T and Box impls, -// as proxy impls on them are blankets that conflict -// with the Encodable and Decodable impls above, -// which only have `default` on their methods -// for this exact reason. -// May be fixable in a simpler fashion via the -// more complex lattice model for specialization. -impl<'a, T: ?Sized + Encodable> UseSpecializedEncodable for &'a T { - fn default_encode(&self, s: &mut S) -> Result<(), S::Error> { +impl> Encodable for Box { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { (**self).encode(s) } } -impl UseSpecializedEncodable for Box { - fn default_encode(&self, s: &mut S) -> Result<(), S::Error> { - (**self).encode(s) - } -} -impl UseSpecializedDecodable for Box { - fn default_decode(d: &mut D) -> Result, D::Error> { +impl> Decodable for Box { + fn decode(d: &mut D) -> Result, D::Error> { Ok(box Decodable::decode(d)?) } } -impl<'a, T: Decodable> UseSpecializedDecodable for &'a T {} -impl<'a, T: Decodable> UseSpecializedDecodable for &'a [T] {} diff --git a/src/librustc_session/Cargo.toml b/src/librustc_session/Cargo.toml index 35c227df850..cb6626d0f4b 100644 --- a/src/librustc_session/Cargo.toml +++ b/src/librustc_session/Cargo.toml @@ -12,6 +12,7 @@ path = "lib.rs" bitflags = "1.2.1" getopts = "0.2" log = { package = "tracing", version = "0.1" } +rustc_macros = { path = "../librustc_macros" } rustc_errors = { path = "../librustc_errors" } rustc_feature = { path = "../librustc_feature" } rustc_target = { path = "../librustc_target" } diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index 9fcdd46539c..c26c9bde3ee 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -39,7 +39,7 @@ pub struct Config { } bitflags! { - #[derive(Default, RustcEncodable, RustcDecodable)] + #[derive(Default, Encodable, Decodable)] pub struct SanitizerSet: u8 { const ADDRESS = 1 << 0; const LEAK = 1 << 1; @@ -194,7 +194,8 @@ impl SwitchWithOptPath { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Encodable, Decodable)] pub enum SymbolManglingVersion { Legacy, V0, @@ -209,7 +210,8 @@ pub enum DebugInfo { Full, } -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)] +#[derive(Encodable, Decodable)] pub enum OutputType { Bitcode, Assembly, @@ -672,7 +674,7 @@ pub enum EntryFnType { impl_stable_hash_via_hash!(EntryFnType); -#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, Encodable, Decodable)] pub enum CrateType { Executable, Dylib, diff --git a/src/librustc_session/lib.rs b/src/librustc_session/lib.rs index be9d2e7be27..c2ea141a06f 100644 --- a/src/librustc_session/lib.rs +++ b/src/librustc_session/lib.rs @@ -3,6 +3,8 @@ #[macro_use] extern crate bitflags; +#[macro_use] +extern crate rustc_macros; pub mod cgu_reuse_tracker; pub mod utils; diff --git a/src/librustc_session/search_paths.rs b/src/librustc_session/search_paths.rs index 4ff06acaa1f..e12364b7dac 100644 --- a/src/librustc_session/search_paths.rs +++ b/src/librustc_session/search_paths.rs @@ -33,7 +33,7 @@ impl SearchPathFile { } } -#[derive(PartialEq, Clone, Copy, Debug, Hash, Eq, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Clone, Copy, Debug, Hash, Eq, Encodable, Decodable)] pub enum PathKind { Native, Crate, diff --git a/src/librustc_session/utils.rs b/src/librustc_session/utils.rs index b97308c22cb..15447c01d1e 100644 --- a/src/librustc_session/utils.rs +++ b/src/librustc_session/utils.rs @@ -10,7 +10,7 @@ impl Session { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)] pub enum NativeLibKind { /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC) included /// when linking a final binary, but not when archiving an rlib. diff --git a/src/librustc_span/def_id.rs b/src/librustc_span/def_id.rs index a874f81868f..aae778217d3 100644 --- a/src/librustc_span/def_id.rs +++ b/src/librustc_span/def_id.rs @@ -4,7 +4,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::AtomicRef; use rustc_index::vec::Idx; use rustc_macros::HashStable_Generic; -use rustc_serialize::{Decoder, Encoder}; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use std::borrow::Borrow; use std::fmt; @@ -84,13 +84,14 @@ impl fmt::Display for CrateNum { /// As a local identifier, a `CrateNum` is only meaningful within its context, e.g. within a tcx. /// Therefore, make sure to include the context when encode a `CrateNum`. -impl rustc_serialize::UseSpecializedEncodable for CrateNum { - fn default_encode(&self, e: &mut E) -> Result<(), E::Error> { - e.emit_u32(self.as_u32()) +impl Encodable for CrateNum { + default fn encode(&self, s: &mut E) -> Result<(), E::Error> { + s.emit_u32(self.as_u32()) } } -impl rustc_serialize::UseSpecializedDecodable for CrateNum { - fn default_decode(d: &mut D) -> Result { + +impl Decodable for CrateNum { + default fn decode(d: &mut D) -> Result { Ok(CrateNum::from_u32(d.read_u32()?)) } } @@ -104,8 +105,8 @@ impl ::std::fmt::Debug for CrateNum { } } -#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, RustcEncodable, RustcDecodable)] -#[derive(HashStable_Generic)] +#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)] +#[derive(HashStable_Generic, Encodable, Decodable)] pub struct DefPathHash(pub Fingerprint); impl Borrow for DefPathHash { @@ -120,16 +121,26 @@ rustc_index::newtype_index! { /// particular definition. It should really be considered an interned /// shorthand for a particular DefPath. pub struct DefIndex { - DEBUG_FORMAT = "DefIndex({})", + ENCODABLE = custom // (only encodable in metadata) + DEBUG_FORMAT = "DefIndex({})", /// The crate root is always assigned index 0 by the AST Map code, /// thanks to `NodeCollector::new`. const CRATE_DEF_INDEX = 0, } } -impl rustc_serialize::UseSpecializedEncodable for DefIndex {} -impl rustc_serialize::UseSpecializedDecodable for DefIndex {} +impl Encodable for DefIndex { + default fn encode(&self, _: &mut E) -> Result<(), E::Error> { + panic!("cannot encode `DefIndex` with `{}`", std::any::type_name::()); + } +} + +impl Decodable for DefIndex { + default fn decode(_: &mut D) -> Result { + panic!("cannot decode `DefIndex` with `{}`", std::any::type_name::()); + } +} /// A `DefId` identifies a particular *definition*, by combining a crate /// index and a def index. @@ -168,19 +179,24 @@ impl DefId { } } -impl rustc_serialize::UseSpecializedEncodable for DefId { - fn default_encode(&self, s: &mut S) -> Result<(), S::Error> { - let krate = u64::from(self.krate.as_u32()); - let index = u64::from(self.index.as_u32()); - s.emit_u64((krate << 32) | index) +impl Encodable for DefId { + default fn encode(&self, s: &mut E) -> Result<(), E::Error> { + s.emit_struct("DefId", 2, |s| { + s.emit_struct_field("krate", 0, |s| self.krate.encode(s))?; + + s.emit_struct_field("index", 1, |s| self.index.encode(s)) + }) } } -impl rustc_serialize::UseSpecializedDecodable for DefId { - fn default_decode(d: &mut D) -> Result { - let def_id = d.read_u64()?; - let krate = CrateNum::from_u32((def_id >> 32) as u32); - let index = DefIndex::from_u32((def_id & 0xffffffff) as u32); - Ok(DefId { krate, index }) + +impl Decodable for DefId { + default fn decode(d: &mut D) -> Result { + d.read_struct("DefId", 2, |d| { + Ok(DefId { + krate: d.read_struct_field("krate", 0, Decodable::decode)?, + index: d.read_struct_field("index", 1, Decodable::decode)?, + }) + }) } } @@ -239,8 +255,17 @@ impl fmt::Debug for LocalDefId { } } -impl rustc_serialize::UseSpecializedEncodable for LocalDefId {} -impl rustc_serialize::UseSpecializedDecodable for LocalDefId {} +impl Encodable for LocalDefId { + fn encode(&self, s: &mut E) -> Result<(), E::Error> { + self.to_def_id().encode(s) + } +} + +impl Decodable for LocalDefId { + fn decode(d: &mut D) -> Result { + DefId::decode(d).map(|d| d.expect_local()) + } +} impl HashStable for DefId { fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { diff --git a/src/librustc_span/edition.rs b/src/librustc_span/edition.rs index b1ac7f04321..4d0c92f51d7 100644 --- a/src/librustc_span/edition.rs +++ b/src/librustc_span/edition.rs @@ -5,7 +5,7 @@ use std::str::FromStr; use rustc_macros::HashStable_Generic; /// The edition of the compiler (RFC 2052) -#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, RustcEncodable, RustcDecodable, Eq)] +#[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Debug, Encodable, Decodable, Eq)] #[derive(HashStable_Generic)] pub enum Edition { // editions must be kept in order, oldest to newest diff --git a/src/librustc_span/hygiene.rs b/src/librustc_span/hygiene.rs index f52b2195c2f..e8f4606b518 100644 --- a/src/librustc_span/hygiene.rs +++ b/src/librustc_span/hygiene.rs @@ -34,16 +34,14 @@ use log::*; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{Lock, Lrc}; use rustc_macros::HashStable_Generic; -use rustc_serialize::{ - Decodable, Decoder, Encodable, Encoder, UseSpecializedDecodable, UseSpecializedEncodable, -}; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use std::fmt; /// A `SyntaxContext` represents a chain of pairs `(ExpnId, Transparency)` named "marks". #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SyntaxContext(u32); -#[derive(Debug, RustcEncodable, RustcDecodable, Clone)] +#[derive(Debug, Encodable, Decodable, Clone)] pub struct SyntaxContextData { outer_expn: ExpnId, outer_transparency: Transparency, @@ -62,7 +60,7 @@ pub struct ExpnId(u32); /// A property of a macro expansion that determines how identifiers /// produced by that expansion are resolved. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Hash, Debug, Encodable, Decodable)] #[derive(HashStable_Generic)] pub enum Transparency { /// Identifier produced by a transparent expansion is always resolved at call-site. @@ -664,7 +662,7 @@ impl Span { /// A subset of properties from both macro definition and macro call available through global data. /// Avoid using this if you have access to the original definition or call structures. -#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic)] pub struct ExpnData { // --- The part unique to each expansion. /// The kind of this expansion - macro or compiler desugaring. @@ -766,7 +764,7 @@ impl ExpnData { } /// Expansion kind. -#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Clone, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)] pub enum ExpnKind { /// No expansion, aka root expansion. Only `ExpnId::root()` has this kind. Root, @@ -794,7 +792,7 @@ impl ExpnKind { } /// The kind of macro invocation or definition. -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug)] #[derive(HashStable_Generic)] pub enum MacroKind { /// A bang macro `foo!()`. @@ -830,7 +828,7 @@ impl MacroKind { } /// The kind of AST transform. -#[derive(Clone, Copy, Debug, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)] pub enum AstPass { StdImports, TestHarness, @@ -848,7 +846,7 @@ impl AstPass { } /// The kind of compiler desugaring. -#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Debug, Encodable, Decodable, HashStable_Generic)] pub enum DesugaringKind { /// We desugar `if c { i } else { e }` to `match $ExprKind::Use(c) { true => i, _ => e }`. /// However, we do not want to blame `c` for unreachability but rather say that `i` @@ -867,7 +865,7 @@ pub enum DesugaringKind { } /// A location in the desugaring of a `for` loop -#[derive(Clone, Copy, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Debug, Encodable, Decodable, HashStable_Generic)] pub enum ForLoopLoc { Head, IntoIter, @@ -888,9 +886,6 @@ impl DesugaringKind { } } -impl UseSpecializedEncodable for ExpnId {} -impl UseSpecializedDecodable for ExpnId {} - #[derive(Default)] pub struct HygieneEncodeContext { /// All `SyntaxContexts` for which we have written `SyntaxContextData` into crate metadata. @@ -1137,6 +1132,7 @@ pub fn for_all_expns_in Result<(), E>>( } Ok(()) } + pub fn for_all_data Result<(), E>>( mut f: F, ) -> Result<(), E> { @@ -1147,6 +1143,18 @@ pub fn for_all_data Res Ok(()) } +impl Encodable for ExpnId { + default fn encode(&self, _: &mut E) -> Result<(), E::Error> { + panic!("cannot encode `ExpnId` with `{}`", std::any::type_name::()); + } +} + +impl Decodable for ExpnId { + default fn decode(_: &mut D) -> Result { + panic!("cannot decode `ExpnId` with `{}`", std::any::type_name::()); + } +} + pub fn for_all_expn_data Result<(), E>>(mut f: F) -> Result<(), E> { let all_data = HygieneData::with(|data| data.expn_data.clone()); for (i, data) in all_data.into_iter().enumerate() { @@ -1218,5 +1226,14 @@ impl<'a> ExpnDataDecodeMode<'a, Box &'a HygieneDecodeCon } } -impl UseSpecializedEncodable for SyntaxContext {} -impl UseSpecializedDecodable for SyntaxContext {} +impl Encodable for SyntaxContext { + default fn encode(&self, _: &mut E) -> Result<(), E::Error> { + panic!("cannot encode `SyntaxContext` with `{}`", std::any::type_name::()); + } +} + +impl Decodable for SyntaxContext { + default fn decode(_: &mut D) -> Result { + panic!("cannot decode `SyntaxContext` with `{}`", std::any::type_name::()); + } +} diff --git a/src/librustc_span/lib.rs b/src/librustc_span/lib.rs index 697d88ad063..c654dade2ab 100644 --- a/src/librustc_span/lib.rs +++ b/src/librustc_span/lib.rs @@ -15,8 +15,7 @@ #![feature(option_expect_none)] #![feature(refcell_take)] -// FIXME(#56935): Work around ICEs during cross-compilation. -#[allow(unused)] +#[macro_use] extern crate rustc_macros; use rustc_data_structures::AtomicRef; @@ -105,8 +104,8 @@ scoped_tls::scoped_thread_local!(pub static SESSION_GLOBALS: SessionGlobals); // // FIXME: We should use this enum or something like it to get rid of the // use of magic `/rust/1.x/...` paths across the board. -#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)] -#[derive(HashStable_Generic)] +#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)] +#[derive(HashStable_Generic, Decodable, Encodable)] pub enum RealFileName { Named(PathBuf), /// For de-virtualized paths (namely paths into libstd that have been mapped @@ -152,8 +151,8 @@ impl RealFileName { } /// Differentiates between real files and common virtual files. -#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)] -#[derive(HashStable_Generic)] +#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)] +#[derive(HashStable_Generic, Decodable, Encodable)] pub enum FileName { Real(RealFileName), /// Call to `quote!`. @@ -333,7 +332,7 @@ impl Ord for Span { /// the error, and would be rendered with `^^^`. /// - They can have a *label*. In this case, the label is written next /// to the mark in the snippet when we render. -#[derive(Clone, Debug, Hash, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, Encodable, Decodable)] pub struct MultiSpan { primary_spans: Vec, span_labels: Vec<(Span, String)>, @@ -698,23 +697,22 @@ impl Default for Span { } } -impl rustc_serialize::UseSpecializedEncodable for Span { - fn default_encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for Span { + default fn encode(&self, s: &mut E) -> Result<(), E::Error> { let span = self.data(); s.emit_struct("Span", 2, |s| { s.emit_struct_field("lo", 0, |s| span.lo.encode(s))?; - s.emit_struct_field("hi", 1, |s| span.hi.encode(s)) }) } } - -impl rustc_serialize::UseSpecializedDecodable for Span { - fn default_decode(d: &mut D) -> Result { - d.read_struct("Span", 2, |d| { +impl Decodable for Span { + default fn decode(s: &mut D) -> Result { + s.read_struct("Span", 2, |d| { let lo = d.read_struct_field("lo", 0, Decodable::decode)?; let hi = d.read_struct_field("hi", 1, Decodable::decode)?; - Ok(Span::with_root_ctxt(lo, hi)) + + Ok(Span::new(lo, hi, SyntaxContext::root())) }) } } @@ -889,7 +887,7 @@ impl From> for MultiSpan { } /// Identifies an offset of a multi-byte character in a `SourceFile`. -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Eq, PartialEq, Debug)] +#[derive(Copy, Clone, Encodable, Decodable, Eq, PartialEq, Debug)] pub struct MultiByteChar { /// The absolute offset of the character in the `SourceMap`. pub pos: BytePos, @@ -898,7 +896,7 @@ pub struct MultiByteChar { } /// Identifies an offset of a non-narrow character in a `SourceFile`. -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Eq, PartialEq, Debug)] +#[derive(Copy, Clone, Encodable, Decodable, Eq, PartialEq, Debug)] pub enum NonNarrowChar { /// Represents a zero-width character. ZeroWidth(BytePos), @@ -960,7 +958,7 @@ impl Sub for NonNarrowChar { } /// Identifies an offset of a character that was normalized away from `SourceFile`. -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Eq, PartialEq, Debug)] +#[derive(Copy, Clone, Encodable, Decodable, Eq, PartialEq, Debug)] pub struct NormalizedPos { /// The absolute offset of the character in the `SourceMap`. pub pos: BytePos, @@ -1012,7 +1010,7 @@ impl ExternalSource { #[derive(Debug)] pub struct OffsetOverflowError; -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)] pub enum SourceFileHashAlgorithm { Md5, Sha1, @@ -1033,8 +1031,8 @@ impl FromStr for SourceFileHashAlgorithm { rustc_data_structures::impl_stable_hash_via_hash!(SourceFileHashAlgorithm); /// The hash of the on-disk source file used for debug info. -#[derive(Copy, Clone, PartialEq, Eq, Debug, RustcEncodable, RustcDecodable)] -#[derive(HashStable_Generic)] +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(HashStable_Generic, Encodable, Decodable)] pub struct SourceFileHash { pub kind: SourceFileHashAlgorithm, value: [u8; 20], @@ -1113,8 +1111,8 @@ pub struct SourceFile { pub cnum: CrateNum, } -impl Encodable for SourceFile { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for SourceFile { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_struct("SourceFile", 8, |s| { s.emit_struct_field("name", 0, |s| self.name.encode(s))?; s.emit_struct_field("name_was_remapped", 1, |s| self.name_was_remapped.encode(s))?; @@ -1183,8 +1181,8 @@ impl Encodable for SourceFile { } } -impl Decodable for SourceFile { - fn decode(d: &mut D) -> Result { +impl Decodable for SourceFile { + fn decode(d: &mut D) -> Result { d.read_struct("SourceFile", 8, |d| { let name: FileName = d.read_struct_field("name", 0, |d| Decodable::decode(d))?; let name_was_remapped: bool = @@ -1585,14 +1583,14 @@ impl Sub for BytePos { } } -impl Encodable for BytePos { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for BytePos { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_u32(self.0) } } -impl Decodable for BytePos { - fn decode(d: &mut D) -> Result { +impl Decodable for BytePos { + fn decode(d: &mut D) -> Result { Ok(BytePos(d.read_u32()?)) } } diff --git a/src/librustc_span/source_map.rs b/src/librustc_span/source_map.rs index e062c7766e7..29e589057b5 100644 --- a/src/librustc_span/source_map.rs +++ b/src/librustc_span/source_map.rs @@ -75,7 +75,7 @@ pub mod monotonic { impl !DerefMut for MonotonicVec {} } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, HashStable_Generic)] +#[derive(Clone, Encodable, Decodable, Debug, Copy, HashStable_Generic)] pub struct Spanned { pub node: T, pub span: Span, @@ -118,7 +118,7 @@ impl FileLoader for RealFileLoader { // This is a `SourceFile` identifier that is used to correlate `SourceFile`s between // subsequent compilation sessions (which is something we need to do during // incremental compilation). -#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable, Debug)] pub struct StableSourceFileId(u128); // FIXME: we need a more globally consistent approach to the problem solved by diff --git a/src/librustc_span/symbol.rs b/src/librustc_span/symbol.rs index caa6de09664..7843c04f255 100644 --- a/src/librustc_span/symbol.rs +++ b/src/librustc_span/symbol.rs @@ -5,9 +5,8 @@ use rustc_arena::DroplessArena; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; -use rustc_macros::{symbols, HashStable_Generic}; +use rustc_macros::HashStable_Generic; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; -use rustc_serialize::{UseSpecializedDecodable, UseSpecializedEncodable}; use std::cmp::{Ord, PartialEq, PartialOrd}; use std::fmt; @@ -1192,7 +1191,7 @@ symbols! { } } -#[derive(Copy, Clone, Eq, HashStable_Generic)] +#[derive(Copy, Clone, Eq, HashStable_Generic, Encodable, Decodable)] pub struct Ident { pub name: Symbol, pub span: Span, @@ -1289,26 +1288,6 @@ impl fmt::Display for Ident { } } -impl UseSpecializedEncodable for Ident { - fn default_encode(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_struct("Ident", 2, |s| { - s.emit_struct_field("name", 0, |s| self.name.encode(s))?; - s.emit_struct_field("span", 1, |s| self.span.encode(s)) - }) - } -} - -impl UseSpecializedDecodable for Ident { - fn default_decode(d: &mut D) -> Result { - d.read_struct("Ident", 2, |d| { - Ok(Ident { - name: d.read_struct_field("name", 0, Decodable::decode)?, - span: d.read_struct_field("span", 1, Decodable::decode)?, - }) - }) - } -} - /// This is the most general way to print identifiers. /// AST pretty-printer is used as a fallback for turning AST structures into token streams for /// proc macros. Additionally, proc macros may stringify their input and expect it survive the @@ -1452,15 +1431,15 @@ impl fmt::Display for Symbol { } } -impl Encodable for Symbol { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { +impl Encodable for Symbol { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { self.with(|string| s.emit_str(string)) } } -impl Decodable for Symbol { +impl Decodable for Symbol { #[inline] - fn decode(d: &mut D) -> Result { + fn decode(d: &mut D) -> Result { Ok(Symbol::intern(&d.read_str()?)) } } @@ -1549,7 +1528,7 @@ pub mod sym { use super::Symbol; use std::convert::TryInto; - symbols!(); + define_symbols!(); // Used from a macro in `librustc_feature/accepted.rs` pub use super::kw::MacroRules as macro_rules; diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index b3e5f5c0c74..4b565dd246f 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -235,7 +235,7 @@ pub enum Endian { } /// Size of a type in bytes. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)] #[derive(HashStable_Generic)] pub struct Size { raw: u64, @@ -358,7 +358,7 @@ impl AddAssign for Size { } /// Alignment of a type in bytes (always a power of two). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)] #[derive(HashStable_Generic)] pub struct Align { pow2: u8, @@ -415,7 +415,7 @@ impl Align { } /// A pair of alignments, ABI-mandated and preferred. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable)] #[derive(HashStable_Generic)] pub struct AbiAndPrefAlign { pub abi: Align, diff --git a/src/librustc_target/asm/mod.rs b/src/librustc_target/asm/mod.rs index ccec17817d3..c22644bf813 100644 --- a/src/librustc_target/asm/mod.rs +++ b/src/librustc_target/asm/mod.rs @@ -13,7 +13,7 @@ macro_rules! def_reg_class { $class:ident, )* }) => { - #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, Eq, PartialEq, Hash, HashStable_Generic)] + #[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash, HashStable_Generic)] #[allow(non_camel_case_types)] pub enum $arch_regclass { $($class,)* @@ -62,7 +62,7 @@ macro_rules! def_regs { )* }) => { #[allow(unreachable_code)] - #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, Eq, PartialEq, Hash, HashStable_Generic)] + #[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash, HashStable_Generic)] #[allow(non_camel_case_types)] pub enum $arch_reg { $($reg,)* @@ -163,7 +163,7 @@ pub use nvptx::{NvptxInlineAsmReg, NvptxInlineAsmRegClass}; pub use riscv::{RiscVInlineAsmReg, RiscVInlineAsmRegClass}; pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass}; -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, Eq, PartialEq, Hash)] +#[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash)] pub enum InlineAsmArch { X86, X86_64, @@ -193,17 +193,7 @@ impl FromStr for InlineAsmArch { } } -#[derive( - Copy, - Clone, - RustcEncodable, - RustcDecodable, - Debug, - Eq, - PartialEq, - Hash, - HashStable_Generic -)] +#[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash, HashStable_Generic)] pub enum InlineAsmReg { X86(X86InlineAsmReg), Arm(ArmInlineAsmReg), @@ -293,17 +283,7 @@ impl InlineAsmReg { } } -#[derive( - Copy, - Clone, - RustcEncodable, - RustcDecodable, - Debug, - Eq, - PartialEq, - Hash, - HashStable_Generic -)] +#[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash, HashStable_Generic)] pub enum InlineAsmRegClass { X86(X86InlineAsmRegClass), Arm(ArmInlineAsmRegClass), @@ -429,17 +409,7 @@ impl InlineAsmRegClass { } } -#[derive( - Copy, - Clone, - RustcEncodable, - RustcDecodable, - Debug, - Eq, - PartialEq, - Hash, - HashStable_Generic -)] +#[derive(Copy, Clone, Encodable, Decodable, Debug, Eq, PartialEq, Hash, HashStable_Generic)] pub enum InlineAsmRegOrRegClass { Reg(InlineAsmReg), RegClass(InlineAsmRegClass), diff --git a/src/librustc_target/lib.rs b/src/librustc_target/lib.rs index 1d0dc660ee6..62df63ceb1e 100644 --- a/src/librustc_target/lib.rs +++ b/src/librustc_target/lib.rs @@ -16,8 +16,7 @@ #![feature(associated_type_bounds)] #![feature(exhaustive_patterns)] -// FIXME(#56935): Work around ICEs during cross-compilation. -#[allow(unused)] +#[macro_use] extern crate rustc_macros; #[macro_use] diff --git a/src/librustc_target/spec/abi.rs b/src/librustc_target/spec/abi.rs index a5c874bb4ac..1e45739ca22 100644 --- a/src/librustc_target/spec/abi.rs +++ b/src/librustc_target/spec/abi.rs @@ -5,8 +5,8 @@ use rustc_macros::HashStable_Generic; #[cfg(test)] mod tests; -#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, Clone, Copy, Debug)] -#[derive(HashStable_Generic)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)] +#[derive(HashStable_Generic, Encodable, Decodable)] pub enum Abi { // N.B., this ordering MUST match the AbiDatas array below. // (This is ensured by the test indices_are_correct().) diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 961a438fd23..fa29ff3f8d8 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -161,7 +161,7 @@ flavor_mappings! { ((LinkerFlavor::Lld(LldFlavor::Link)), "lld-link"), } -#[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable, HashStable_Generic)] +#[derive(Clone, Copy, Debug, PartialEq, Hash, Encodable, Decodable, HashStable_Generic)] pub enum PanicStrategy { Unwind, Abort, @@ -185,7 +185,7 @@ impl ToJson for PanicStrategy { } } -#[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, Debug, PartialEq, Hash, Encodable, Decodable)] pub enum RelroLevel { Full, Partial, @@ -229,7 +229,7 @@ impl ToJson for RelroLevel { } } -#[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, Debug, PartialEq, Hash, Encodable, Decodable)] pub enum MergeFunctions { Disabled, Trampolines, @@ -1734,7 +1734,7 @@ impl ToJson for Target { } /// Either a target triple string or a path to a JSON file. -#[derive(PartialEq, Clone, Debug, Hash, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Clone, Debug, Hash, Encodable, Decodable)] pub enum TargetTriple { TargetTriple(String), TargetPath(PathBuf),