From cbcef3effcf64bd0d89ea2dc8973e18d7fcf94c3 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Thu, 11 Jun 2020 15:49:57 +0100 Subject: [PATCH 1/8] 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 | 236 ++++---- src/librustc_metadata/rmeta/encoder.rs | 210 +++---- 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 | 524 +++++++----------- 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 | 363 ++++++------ 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, 1907 insertions(+), 1937 deletions(-) create mode 100644 src/librustc_macros/src/serialize.rs diff --git a/Cargo.lock b/Cargo.lock index f6b5b317646c3..564c3da522342 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 a0541158bc2c5..6dff02486ff19 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 95d4c09dac311..bd7d85167140d 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 3f876169d2236..fb5ce31182627 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 cd562c48e9115..1035e945538f5 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 4597624ef88b0..e4a3cccb7ead1 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 bcce881ed48c5..46c4be0a33bf7 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 9d0199078fa6a..151acddae840e 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 5f131fae385b0..3ddabcc17f8b6 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 5754bb48d24e1..149a950f7d417 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 8fa0de37648f3..ff9dac372ab95 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 f9a782af24cda..5100ef8ad4fd7 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 85260d30a3d7c..6bfbda0f1d7f2 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 36c32e6003112..1926dbf06e726 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 282626611d50b..f8d631ce01e78 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 3884fc051056e..017511cc50d20 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 652268dcee884..856eb73e6297a 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 476eb9e14f98f..02103de2e8df9 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 43002178eb971..4d673fd5cf983 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 7d137a55033f7..fe60a99dde072 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 d0f04c3fe7647..c17d61dae9faf 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 acaa26c6ad2fc..cd4b5d56f36e6 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 24186198fd2b1..750d36d3d891a 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 dcfcdbc63f29f..e69e868c8ede5 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 73d71063b2362..98e9972530ebd 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 0660590a72570..160bf57779970 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 bdf039c36abf6..fbdb65b558790 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 1e3ab2c5ec2db..7f631cb71afa8 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 6f2daaa81c02f..9920e0650a7f7 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 618f3e99c3f04..c4877be3f6415 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 79b7068273932..5604e3a8dcaf9 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 6474dc318d329..928235adac30c 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 b0fb179b18bdf..7456020ee9b67 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 2def000da6480..e6dafd4965bc9 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 5aa94ba3d09fd..16e65d2cca4cb 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 92d6dbb5f90f5..fe390adf89f9f 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 6798addb8aaa3..ff6f0d346f7dc 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 08b0bfecf4909..007b46b117694 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> FingerprintDecoder for CacheDecoder<'a, 'tcx> { + fn decode_fingerprint(&mut self) -> Result { + Fingerprint::decode_opaque(&mut self.opaque) } } -impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { - fn specialized_decode(&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() } -} - -impl<'a, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> -where - E: 'a + TyEncoder, -{ - #[inline] - fn specialized_encode(&mut self, cnum: &CrateNum) -> Result<(), Self::Error> { - self.emit_u32(cnum.as_u32()) + fn type_shorthands(&mut self) -> &mut FxHashMap, usize> { + &mut self.type_shorthands } -} - -impl<'a, 'b, 'c, 'tcx, E> SpecializedEncoder<&'b ty::TyS<'c>> for CacheEncoder<'a, 'tcx, E> -where - E: 'a + TyEncoder, - &'b ty::TyS<'c>: UseSpecializedEncodable, -{ - #[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 - }) + 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); -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) + 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, id: &LocalDefId) -> Result<(), Self::Error> { - id.to_def_id().encode(self) + 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, 'tcx, E> SpecializedEncoder for CacheEncoder<'a, 'tcx, E> +impl<'a, 'tcx, E> Encodable> for DefIndex where - E: 'a + TyEncoder, + E: 'a + OpaqueEncoder, { - 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 310ab4f7235eb..dc979e52c5761 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 866b529f35ec3..acd58ab7f967a 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 f93cce3f4da7f..86fe3ac3751af 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 07221082048fb..23507ac830d55 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 64af9c5f1a152..c1ec452e001bb 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 002b0f9c165dd..e302784cc3e5f 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 04a45090b7226..d70306b486921 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 5cba64cac4b34..29357ce9449ce 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 4a89da23ea6a5..932c6d2a2f184 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 4bbba7befe93f..db104398f16ef 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 49b8094abd0eb..3d274cb01507b 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 ab7f6975325bc..dafeb053d83d3 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 3dc3e78382096..265b3b95e956a 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 29c5737ad895a..d279954bf91bf 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> { - (**self).encode(s) - } -} -impl UseSpecializedEncodable for Box { - 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 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 35c227df8500a..cb6626d0f4bd5 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 9fcdd46539c46..c26c9bde3ee85 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 be9d2e7be2777..c2ea141a06fe3 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 4ff06acaa1fd4..e12364b7dac7c 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 b97308c22cb7d..15447c01d1e55 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 a874f81868f15..aae778217d3f1 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 b1ac7f04321eb..4d0c92f51d7ca 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 f52b2195c2f6e..e8f4606b518cf 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 697d88ad06395..c654dade2abd4 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 e062c7766e7dc..29e589057b5e2 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 caa6de09664bc..7843c04f25596 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 b3e5f5c0c74b1..4b565dd246f6d 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 ccec17817d37d..c22644bf813a4 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 1d0dc660ee616..62df63ceb1efd 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 a5c874bb4ac05..1e45739ca22b4 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 961a438fd233c..fa29ff3f8d80f 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), From b90018e987d65f386e66a52fd0197c4bfe36d022 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Mon, 15 Jun 2020 17:29:14 +0100 Subject: [PATCH 2/8] Simplify arena_types macros --- src/librustc_arena/lib.rs | 6 +- src/librustc_hir/arena.rs | 70 +++++++++++------------ src/librustc_middle/arena.rs | 99 ++++++++++----------------------- src/librustc_middle/ty/codec.rs | 2 +- 4 files changed, 65 insertions(+), 112 deletions(-) diff --git a/src/librustc_arena/lib.rs b/src/librustc_arena/lib.rs index 5cf4f97fb8863..5e6a0340d12a0 100644 --- a/src/librustc_arena/lib.rs +++ b/src/librustc_arena/lib.rs @@ -611,11 +611,7 @@ macro_rules! which_arena_for_type { #[macro_export] macro_rules! declare_arena { - // This macro has to take the same input as - // `impl_arena_allocatable_decoders` which requires a second version of - // each type. We ignore that type until we can fix - // `impl_arena_allocatable_decoders`. - ([], [$($a:tt $name:ident: $ty:ty, $_gen_ty:ty;)*], $tcx:lifetime) => { + ([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => { #[derive(Default)] pub struct Arena<$tcx> { pub dropless: $crate::DroplessArena, diff --git a/src/librustc_hir/arena.rs b/src/librustc_hir/arena.rs index f439db715310c..6ba396666070a 100644 --- a/src/librustc_hir/arena.rs +++ b/src/librustc_hir/arena.rs @@ -12,41 +12,41 @@ macro_rules! arena_types { ($macro:path, $args:tt, $tcx:lifetime) => ( $macro!($args, [ // HIR types - [few] hir_krate: rustc_hir::Crate<$tcx>, rustc_hir::Crate<'_x>; - [] arm: rustc_hir::Arm<$tcx>, rustc_hir::Arm<'_x>; - [] asm_operand: rustc_hir::InlineAsmOperand<$tcx>, rustc_hir::InlineAsmOperand<'_x>; - [] asm_template: rustc_ast::ast::InlineAsmTemplatePiece, rustc_ast::ast::InlineAsmTemplatePiece; - [] attribute: rustc_ast::ast::Attribute, rustc_ast::ast::Attribute; - [] block: rustc_hir::Block<$tcx>, rustc_hir::Block<'_x>; - [] bare_fn_ty: rustc_hir::BareFnTy<$tcx>, rustc_hir::BareFnTy<'_x>; - [few] global_asm: rustc_hir::GlobalAsm, rustc_hir::GlobalAsm; - [] generic_arg: rustc_hir::GenericArg<$tcx>, rustc_hir::GenericArg<'_x>; - [] generic_args: rustc_hir::GenericArgs<$tcx>, rustc_hir::GenericArgs<'_x>; - [] generic_bound: rustc_hir::GenericBound<$tcx>, rustc_hir::GenericBound<'_x>; - [] generic_param: rustc_hir::GenericParam<$tcx>, rustc_hir::GenericParam<'_x>; - [] expr: rustc_hir::Expr<$tcx>, rustc_hir::Expr<'_x>; - [] field: rustc_hir::Field<$tcx>, rustc_hir::Field<'_x>; - [] field_pat: rustc_hir::FieldPat<$tcx>, rustc_hir::FieldPat<'_x>; - [] fn_decl: rustc_hir::FnDecl<$tcx>, rustc_hir::FnDecl<'_x>; - [] foreign_item: rustc_hir::ForeignItem<$tcx>, rustc_hir::ForeignItem<'_x>; - [] impl_item_ref: rustc_hir::ImplItemRef<$tcx>, rustc_hir::ImplItemRef<'_x>; - [few] inline_asm: rustc_hir::InlineAsm<$tcx>, rustc_hir::InlineAsm<'_x>; - [few] llvm_inline_asm: rustc_hir::LlvmInlineAsm<$tcx>, rustc_hir::LlvmInlineAsm<'_x>; - [] local: rustc_hir::Local<$tcx>, rustc_hir::Local<'_x>; - [few] macro_def: rustc_hir::MacroDef<$tcx>, rustc_hir::MacroDef<'_x>; - [] param: rustc_hir::Param<$tcx>, rustc_hir::Param<'_x>; - [] pat: rustc_hir::Pat<$tcx>, rustc_hir::Pat<'_x>; - [] path: rustc_hir::Path<$tcx>, rustc_hir::Path<'_x>; - [] path_segment: rustc_hir::PathSegment<$tcx>, rustc_hir::PathSegment<'_x>; - [] poly_trait_ref: rustc_hir::PolyTraitRef<$tcx>, rustc_hir::PolyTraitRef<'_x>; - [] qpath: rustc_hir::QPath<$tcx>, rustc_hir::QPath<'_x>; - [] stmt: rustc_hir::Stmt<$tcx>, rustc_hir::Stmt<'_x>; - [] struct_field: rustc_hir::StructField<$tcx>, rustc_hir::StructField<'_x>; - [] trait_item_ref: rustc_hir::TraitItemRef, rustc_hir::TraitItemRef; - [] ty: rustc_hir::Ty<$tcx>, rustc_hir::Ty<'_x>; - [] type_binding: rustc_hir::TypeBinding<$tcx>, rustc_hir::TypeBinding<'_x>; - [] variant: rustc_hir::Variant<$tcx>, rustc_hir::Variant<'_x>; - [] where_predicate: rustc_hir::WherePredicate<$tcx>, rustc_hir::WherePredicate<'_x>; + [few] hir_krate: rustc_hir::Crate<$tcx>, + [] arm: rustc_hir::Arm<$tcx>, + [] asm_operand: rustc_hir::InlineAsmOperand<$tcx>, + [] asm_template: rustc_ast::ast::InlineAsmTemplatePiece, + [] attribute: rustc_ast::ast::Attribute, + [] block: rustc_hir::Block<$tcx>, + [] bare_fn_ty: rustc_hir::BareFnTy<$tcx>, + [few] global_asm: rustc_hir::GlobalAsm, + [] generic_arg: rustc_hir::GenericArg<$tcx>, + [] generic_args: rustc_hir::GenericArgs<$tcx>, + [] generic_bound: rustc_hir::GenericBound<$tcx>, + [] generic_param: rustc_hir::GenericParam<$tcx>, + [] expr: rustc_hir::Expr<$tcx>, + [] field: rustc_hir::Field<$tcx>, + [] field_pat: rustc_hir::FieldPat<$tcx>, + [] fn_decl: rustc_hir::FnDecl<$tcx>, + [] foreign_item: rustc_hir::ForeignItem<$tcx>, + [] impl_item_ref: rustc_hir::ImplItemRef<$tcx>, + [few] inline_asm: rustc_hir::InlineAsm<$tcx>, + [few] llvm_inline_asm: rustc_hir::LlvmInlineAsm<$tcx>, + [] local: rustc_hir::Local<$tcx>, + [few] macro_def: rustc_hir::MacroDef<$tcx>, + [] param: rustc_hir::Param<$tcx>, + [] pat: rustc_hir::Pat<$tcx>, + [] path: rustc_hir::Path<$tcx>, + [] path_segment: rustc_hir::PathSegment<$tcx>, + [] poly_trait_ref: rustc_hir::PolyTraitRef<$tcx>, + [] qpath: rustc_hir::QPath<$tcx>, + [] stmt: rustc_hir::Stmt<$tcx>, + [] struct_field: rustc_hir::StructField<$tcx>, + [] trait_item_ref: rustc_hir::TraitItemRef, + [] ty: rustc_hir::Ty<$tcx>, + [] type_binding: rustc_hir::TypeBinding<$tcx>, + [] variant: rustc_hir::Variant<$tcx>, + [] where_predicate: rustc_hir::WherePredicate<$tcx>, ], $tcx); ) } diff --git a/src/librustc_middle/arena.rs b/src/librustc_middle/arena.rs index a08941469edd9..99889c74da0ec 100644 --- a/src/librustc_middle/arena.rs +++ b/src/librustc_middle/arena.rs @@ -11,13 +11,11 @@ macro_rules! arena_types { ($macro:path, $args:tt, $tcx:lifetime) => ( $macro!($args, [ - [] layouts: rustc_target::abi::Layout, rustc_target::abi::Layout; + [] layouts: rustc_target::abi::Layout, // AdtDef are interned and compared by address - [] adt_def: rustc_middle::ty::AdtDef, rustc_middle::ty::AdtDef; - [] steal_mir: - rustc_middle::ty::steal::Steal>, - rustc_middle::ty::steal::Steal>; - [decode] mir: rustc_middle::mir::Body<$tcx>, rustc_middle::mir::Body<'_x>; + [] adt_def: rustc_middle::ty::AdtDef, + [] steal_mir: rustc_middle::ty::steal::Steal>, + [decode] mir: rustc_middle::mir::Body<$tcx>, [] steal_promoted: rustc_middle::ty::steal::Steal< rustc_index::vec::IndexVec< @@ -25,127 +23,86 @@ macro_rules! arena_types { rustc_middle::mir::Body<$tcx> > >, - rustc_middle::ty::steal::Steal< - rustc_index::vec::IndexVec< - rustc_middle::mir::Promoted, - rustc_middle::mir::Body<$tcx> - > - >; [decode] promoted: rustc_index::vec::IndexVec< rustc_middle::mir::Promoted, rustc_middle::mir::Body<$tcx> >, - rustc_index::vec::IndexVec< - rustc_middle::mir::Promoted, - rustc_middle::mir::Body<'_x> - >; - [decode] typeck_results: rustc_middle::ty::TypeckResults<$tcx>, rustc_middle::ty::TypeckResults<'_x>; + [decode] typeck_results: rustc_middle::ty::TypeckResults<$tcx>, [decode] borrowck_result: rustc_middle::mir::BorrowCheckResult<$tcx>, - rustc_middle::mir::BorrowCheckResult<'_x>; - [decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult, rustc_middle::mir::UnsafetyCheckResult; - [] const_allocs: rustc_middle::mir::interpret::Allocation, rustc_middle::mir::interpret::Allocation; + [decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult, + [] const_allocs: rustc_middle::mir::interpret::Allocation, // Required for the incremental on-disk cache - [few] mir_keys: rustc_hir::def_id::DefIdSet, rustc_hir::def_id::DefIdSet; - [] region_scope_tree: rustc_middle::middle::region::ScopeTree, rustc_middle::middle::region::ScopeTree; + [few] mir_keys: rustc_hir::def_id::DefIdSet, + [] region_scope_tree: rustc_middle::middle::region::ScopeTree, [] dropck_outlives: rustc_middle::infer::canonical::Canonical<'tcx, rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::traits::query::DropckOutlivesResult<'tcx> > >, - rustc_middle::infer::canonical::Canonical<'_x, - rustc_middle::infer::canonical::QueryResponse<'_y, - rustc_middle::traits::query::DropckOutlivesResult<'_z> - > - >; [] normalize_projection_ty: rustc_middle::infer::canonical::Canonical<'tcx, rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::traits::query::NormalizationResult<'tcx> > >, - rustc_middle::infer::canonical::Canonical<'_x, - rustc_middle::infer::canonical::QueryResponse<'_y, - rustc_middle::traits::query::NormalizationResult<'_z> - > - >; [] implied_outlives_bounds: rustc_middle::infer::canonical::Canonical<'tcx, rustc_middle::infer::canonical::QueryResponse<'tcx, Vec> > >, - rustc_middle::infer::canonical::Canonical<'_x, - rustc_middle::infer::canonical::QueryResponse<'_y, - Vec> - > - >; [] type_op_subtype: rustc_middle::infer::canonical::Canonical<'tcx, rustc_middle::infer::canonical::QueryResponse<'tcx, ()> >, - rustc_middle::infer::canonical::Canonical<'_x, - rustc_middle::infer::canonical::QueryResponse<'_y, ()> - >; [] type_op_normalize_poly_fn_sig: rustc_middle::infer::canonical::Canonical<'tcx, rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::ty::PolyFnSig<'tcx>> >, - rustc_middle::infer::canonical::Canonical<'_x, - rustc_middle::infer::canonical::QueryResponse<'_y, rustc_middle::ty::PolyFnSig<'_z>> - >; [] type_op_normalize_fn_sig: rustc_middle::infer::canonical::Canonical<'tcx, rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::ty::FnSig<'tcx>> >, - rustc_middle::infer::canonical::Canonical<'_x, - rustc_middle::infer::canonical::QueryResponse<'_y, rustc_middle::ty::FnSig<'_z>> - >; [] type_op_normalize_predicate: rustc_middle::infer::canonical::Canonical<'tcx, rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::ty::Predicate<'tcx>> >, - rustc_middle::infer::canonical::Canonical<'_x, - rustc_middle::infer::canonical::QueryResponse<'_y, rustc_middle::ty::Predicate<'_z>> - >; [] type_op_normalize_ty: rustc_middle::infer::canonical::Canonical<'tcx, rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::ty::Ty<'tcx>> >, - rustc_middle::infer::canonical::Canonical<'_x, - rustc_middle::infer::canonical::QueryResponse<'_y, &'_z rustc_middle::ty::TyS<'_w>> - >; - [few] all_traits: Vec, Vec; - [few] privacy_access_levels: rustc_middle::middle::privacy::AccessLevels, rustc_middle::middle::privacy::AccessLevels; - [few] foreign_module: rustc_middle::middle::cstore::ForeignModule, rustc_middle::middle::cstore::ForeignModule; - [few] foreign_modules: Vec, Vec; - [] upvars_mentioned: rustc_data_structures::fx::FxIndexMap, rustc_data_structures::fx::FxIndexMap; - [] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation, rustc_middle::traits::ObjectSafetyViolation; - [] codegen_unit: rustc_middle::mir::mono::CodegenUnit<$tcx>, rustc_middle::mir::mono::CodegenUnit<'_x>; - [] attribute: rustc_ast::ast::Attribute, rustc_ast::ast::Attribute; - [] name_set: rustc_data_structures::fx::FxHashSet, rustc_data_structures::fx::FxHashSet; - [] hir_id_set: rustc_hir::HirIdSet, rustc_hir::HirIdSet; + [few] all_traits: Vec, + [few] privacy_access_levels: rustc_middle::middle::privacy::AccessLevels, + [few] foreign_module: rustc_middle::middle::cstore::ForeignModule, + [few] foreign_modules: Vec, + [] upvars_mentioned: rustc_data_structures::fx::FxIndexMap, + [] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation, + [] codegen_unit: rustc_middle::mir::mono::CodegenUnit<$tcx>, + [] attribute: rustc_ast::ast::Attribute, + [] name_set: rustc_data_structures::fx::FxHashSet, + [] hir_id_set: rustc_hir::HirIdSet, // Interned types - [] tys: rustc_middle::ty::TyS<$tcx>, rustc_middle::ty::TyS<'_x>; - [] predicates: rustc_middle::ty::PredicateInner<$tcx>, rustc_middle::ty::PredicateInner<'_x>; + [] tys: rustc_middle::ty::TyS<$tcx>, + [] predicates: rustc_middle::ty::PredicateInner<$tcx>, // HIR query types - [few] indexed_hir: rustc_middle::hir::map::IndexedHir<$tcx>, rustc_middle::hir::map::IndexedHir<'_x>; - [few] hir_definitions: rustc_hir::definitions::Definitions, rustc_hir::definitions::Definitions; - [] hir_owner: rustc_middle::hir::Owner<$tcx>, rustc_middle::hir::Owner<'_x>; - [] hir_owner_nodes: rustc_middle::hir::OwnerNodes<$tcx>, rustc_middle::hir::OwnerNodes<'_x>; + [few] indexed_hir: rustc_middle::hir::map::IndexedHir<$tcx>, + [few] hir_definitions: rustc_hir::definitions::Definitions, + [] hir_owner: rustc_middle::hir::Owner<$tcx>, + [] hir_owner_nodes: rustc_middle::hir::OwnerNodes<$tcx>, // Note that this deliberately duplicates items in the `rustc_hir::arena`, // since we need to allocate this type on both the `rustc_hir` arena // (during lowering) and the `librustc_middle` arena (for decoding MIR) - [decode] asm_template: rustc_ast::ast::InlineAsmTemplatePiece, rustc_ast::ast::InlineAsmTemplatePiece; + [decode] asm_template: rustc_ast::ast::InlineAsmTemplatePiece, // This is used to decode the &'tcx [Span] for InlineAsm's line_spans. - [decode] span: rustc_span::Span, rustc_span::Span; - [decode] used_trait_imports: rustc_data_structures::fx::FxHashSet, rustc_data_structures::fx::FxHashSet; + [decode] span: rustc_span::Span, + [decode] used_trait_imports: rustc_data_structures::fx::FxHashSet, ], $tcx); ) } diff --git a/src/librustc_middle/ty/codec.rs b/src/librustc_middle/ty/codec.rs index 42f55e9f5f9c7..270eb42b0c739 100644 --- a/src/librustc_middle/ty/codec.rs +++ b/src/librustc_middle/ty/codec.rs @@ -390,7 +390,7 @@ macro_rules! impl_arena_allocatable_decoder { } macro_rules! impl_arena_allocatable_decoders { - ([], [$($a:tt $name:ident: $ty:ty, $_gen_ty:ty;)*], $tcx:lifetime) => { + ([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => { $( impl_arena_allocatable_decoder!($a [[$name: $ty], $tcx]); )* From a225dddc2e0cdb3a0165dec25eceb1ad411f46cf Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Mon, 22 Jun 2020 19:32:46 +0100 Subject: [PATCH 3/8] Add some documentation for (De|En)codable --- src/librustc_middle/ty/codec.rs | 11 +++++++++++ src/librustc_serialize/serialize.rs | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/librustc_middle/ty/codec.rs b/src/librustc_middle/ty/codec.rs index 270eb42b0c739..291648869fb69 100644 --- a/src/librustc_middle/ty/codec.rs +++ b/src/librustc_middle/ty/codec.rs @@ -74,6 +74,16 @@ pub trait TyEncoder<'tcx>: Encoder { fn encode_alloc_id(&mut self, alloc_id: &AllocId) -> Result<(), Self::Error>; } +/// Trait for decoding to a reference. +/// +/// This is a separate trait from `Decodable` so that we can implement it for +/// upstream types, such as `FxHashSet`. +/// +/// The `TyDecodable` derive macro will use this trait for fields that are +/// references (and don't use a type alias to hide that). +/// +/// `Decodable` can still be implemented in cases where `Decodable` is required +/// by a trait bound. pub trait RefDecodable<'tcx, D: TyDecoder<'tcx>> { fn decode(d: &mut D) -> Result<&'tcx Self, D::Error>; } @@ -301,6 +311,7 @@ macro_rules! impl_decodable_via_ref { })* } } + impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::AdtDef { fn decode(decoder: &mut D) -> Result<&'tcx Self, D::Error> { let def_id = >::decode(decoder)?; diff --git a/src/librustc_serialize/serialize.rs b/src/librustc_serialize/serialize.rs index d279954bf91bf..05c9cf3981b6e 100644 --- a/src/librustc_serialize/serialize.rs +++ b/src/librustc_serialize/serialize.rs @@ -379,10 +379,32 @@ pub trait Decoder { fn error(&mut self, err: &str) -> Self::Error; } +/// Trait for types that can be serialized +/// +/// This can be implemented using the `Encodable`, `TyEncodable` and +/// `MetadataEncodable` macros. +/// +/// * `Encodable` should be used in crates that don't depend on +/// `librustc_middle`. +/// * `TyEncodable` should be used for types that are only serialized in crate +/// metadata or the incremental cache, except for simple enums.where +/// * `MetadataEncodable` is used in `rustc_metadata` for types that are only +/// serialized in crate metadata. pub trait Encodable { fn encode(&self, s: &mut S) -> Result<(), S::Error>; } +/// Trait for types that can be deserialized +/// +/// This can be implemented using the `Decodable`, `TyDecodable` and +/// `MetadataDecodable` macros. +/// +/// * `Decodable` should be used in crates that don't depend on +/// `librustc_middle`. +/// * `TyDecodable` should be used for types that are only serialized in crate +/// metadata or the incremental cache, except for simple enums.where +/// * `MetadataDecodable` is used in `rustc_metadata` for types that are only +/// serialized in crate metadata. pub trait Decodable: Sized { fn decode(d: &mut D) -> Result; } From e46c58fa7e092eb7316bee958d4ad99e5ec0a9c5 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Mon, 29 Jun 2020 21:09:54 +0100 Subject: [PATCH 4/8] Fix tests and address review comments --- .../middle/codegen_fn_attrs.rs | 4 +- .../middle/exported_symbols.rs | 2 +- src/librustc_middle/mir/mono.rs | 2 +- src/librustc_middle/ty/mod.rs | 2 +- src/librustc_middle/ty/sty.rs | 2 +- src/librustc_serialize/serialize.rs | 233 +++--------------- .../ast-json/ast-json-noexpand-output.stdout | 2 +- src/test/ui/ast-json/ast-json-output.stdout | 2 +- 8 files changed, 47 insertions(+), 202 deletions(-) diff --git a/src/librustc_middle/middle/codegen_fn_attrs.rs b/src/librustc_middle/middle/codegen_fn_attrs.rs index 43712de34e90a..62a6198b9b402 100644 --- a/src/librustc_middle/middle/codegen_fn_attrs.rs +++ b/src/librustc_middle/middle/codegen_fn_attrs.rs @@ -3,7 +3,7 @@ use rustc_attr::{InlineAttr, OptimizeAttr}; use rustc_session::config::SanitizerSet; use rustc_span::symbol::Symbol; -#[derive(Clone, Encodable, Decodable, HashStable)] +#[derive(Clone, TyEncodable, TyDecodable, HashStable)] pub struct CodegenFnAttrs { pub flags: CodegenFnAttrFlags, /// Parsed representation of the `#[inline]` attribute @@ -37,7 +37,7 @@ pub struct CodegenFnAttrs { } bitflags! { - #[derive(Encodable, Decodable, HashStable)] + #[derive(TyEncodable, TyDecodable, HashStable)] pub struct CodegenFnAttrFlags: u32 { /// `#[cold]`: a hint to LLVM that this function, when called, is never on /// the hot path. diff --git a/src/librustc_middle/middle/exported_symbols.rs b/src/librustc_middle/middle/exported_symbols.rs index f961cdd90862f..276e45ce99b29 100644 --- a/src/librustc_middle/middle/exported_symbols.rs +++ b/src/librustc_middle/middle/exported_symbols.rs @@ -8,7 +8,7 @@ use rustc_macros::HashStable; /// kind of crate, including cdylibs which export very few things. /// `Rust` will only be exported if the crate produced is a Rust /// dylib. -#[derive(Eq, PartialEq, Debug, Copy, Clone, Encodable, Decodable, HashStable)] +#[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)] pub enum SymbolExportLevel { C, Rust, diff --git a/src/librustc_middle/mir/mono.rs b/src/librustc_middle/mir/mono.rs index 009240d056160..5081295ab3f74 100644 --- a/src/librustc_middle/mir/mono.rs +++ b/src/librustc_middle/mir/mono.rs @@ -242,7 +242,7 @@ pub struct CodegenUnit<'tcx> { /// Specifies the linkage type for a `MonoItem`. /// /// See https://llvm.org/docs/LangRef.html#linkage-types for more details about these variants. -#[derive(Copy, Clone, PartialEq, Debug, Encodable, Decodable, HashStable)] +#[derive(Copy, Clone, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)] pub enum Linkage { External, AvailableExternally, diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index ff6f0d346f7dc..81e60a7fd3743 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -2098,7 +2098,7 @@ impl<'tcx> VariantDef { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, Encodable, Decodable, HashStable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)] pub enum VariantDiscr { /// Explicit value for this variant, i.e., `X = 123`. /// The `DefId` corresponds to the embedded constant. diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index dc979e52c5761..05cd1ae456b35 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -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(Encodable, Decodable, HashStable)] +#[derive(TyEncodable, TyDecodable, HashStable)] pub struct DelaySpanBugEmitted(pub(super) ()); // `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger. diff --git a/src/librustc_serialize/serialize.rs b/src/librustc_serialize/serialize.rs index 05c9cf3981b6e..c0e23b89a60df 100644 --- a/src/librustc_serialize/serialize.rs +++ b/src/librustc_serialize/serialize.rs @@ -385,11 +385,11 @@ pub trait Decoder { /// `MetadataEncodable` macros. /// /// * `Encodable` should be used in crates that don't depend on -/// `librustc_middle`. +/// `rustc_middle`. +/// * `MetadataEncodable` is used in `rustc_metadata` for types that contain +/// `rustc_metadata::rmeta::Lazy`. /// * `TyEncodable` should be used for types that are only serialized in crate -/// metadata or the incremental cache, except for simple enums.where -/// * `MetadataEncodable` is used in `rustc_metadata` for types that are only -/// serialized in crate metadata. +/// metadata or the incremental cache. This is most types in `rustc_middle`. pub trait Encodable { fn encode(&self, s: &mut S) -> Result<(), S::Error>; } @@ -400,61 +400,50 @@ pub trait Encodable { /// `MetadataDecodable` macros. /// /// * `Decodable` should be used in crates that don't depend on -/// `librustc_middle`. +/// `rustc_middle`. +/// * `MetadataDecodable` is used in `rustc_metadata` for types that contain +/// `rustc_metadata::rmeta::Lazy`. /// * `TyDecodable` should be used for types that are only serialized in crate -/// metadata or the incremental cache, except for simple enums.where -/// * `MetadataDecodable` is used in `rustc_metadata` for types that are only -/// serialized in crate metadata. +/// metadata or the incremental cache. This is most types in `rustc_middle`. pub trait Decodable: Sized { fn decode(d: &mut D) -> Result; } -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 { - d.read_usize() - } -} - -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 { - d.read_u8() - } -} - -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 { - d.read_u16() - } -} +macro_rules! direct_serialize_impls { + ($($ty:ident $emit_method:ident $read_method:ident),*) => { + $( + impl Encodable for $ty { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { + s.$emit_method(*self) + } + } -impl Encodable for u32 { - fn encode(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_u32(*self) + impl Decodable for $ty { + fn decode(d: &mut D) -> Result<$ty, D::Error> { + d.$read_method() + } + } + )* } } -impl Decodable for u32 { - fn decode(d: &mut D) -> Result { - d.read_u32() - } +direct_serialize_impls! { + usize emit_usize read_usize, + u8 emit_u8 read_u8, + u16 emit_u16 read_u16, + u32 emit_u32 read_u32, + u64 emit_u64 read_u64, + u128 emit_u128 read_u128, + isize emit_isize read_isize, + i8 emit_i8 read_i8, + i16 emit_i16 read_i16, + i32 emit_i32 read_i32, + i64 emit_i64 read_i64, + i128 emit_i128 read_i128, + f32 emit_f32 read_f32, + f64 emit_f64 read_f64, + bool emit_bool read_bool, + char emit_char read_char } impl Encodable for ::std::num::NonZeroU32 { @@ -469,102 +458,6 @@ impl Decodable for ::std::num::NonZeroU32 { } } -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 { - d.read_u64() - } -} - -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 { - d.read_u128() - } -} - -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 { - d.read_isize() - } -} - -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 { - d.read_i8() - } -} - -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 { - d.read_i16() - } -} - -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 { - d.read_i32() - } -} - -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 { - d.read_i64() - } -} - -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 { - d.read_i128() - } -} - impl Encodable for str { fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_str(self) @@ -589,54 +482,6 @@ impl Decodable for String { } } -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 { - d.read_f32() - } -} - -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 { - d.read_f64() - } -} - -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 { - d.read_bool() - } -} - -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 { - d.read_char() - } -} - impl Encodable for () { fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_unit() diff --git a/src/test/ui/ast-json/ast-json-noexpand-output.stdout b/src/test/ui/ast-json/ast-json-noexpand-output.stdout index c7b0fbeb0e39b..d0942f78bb86c 100644 --- a/src/test/ui/ast-json/ast-json-noexpand-output.stdout +++ b/src/test/ui/ast-json/ast-json-noexpand-output.stdout @@ -1 +1 @@ -{"module":{"inner":{"lo":0,"hi":0},"items":[{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"core","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null}],"inline":true},"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"crate_type","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":{"variant":"Eq","fields":[{"lo":0,"hi":0},{"_field0":[[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"NonJoint"]]}]}}]},"id":null,"style":"Inner","span":{"lo":0,"hi":0}}],"span":{"lo":0,"hi":0},"proc_macros":[]} +{"module":{"inner":{"lo":0,"hi":0},"items":[{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"core","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null}],"inline":true},"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"crate_type","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":{"variant":"Eq","fields":[{"lo":0,"hi":0},{"0":[[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"NonJoint"]]}]}}]},"id":null,"style":"Inner","span":{"lo":0,"hi":0}}],"span":{"lo":0,"hi":0},"proc_macros":[]} diff --git a/src/test/ui/ast-json/ast-json-output.stdout b/src/test/ui/ast-json/ast-json-output.stdout index 59ed68c2a773f..dc06fd74a4bb5 100644 --- a/src/test/ui/ast-json/ast-json-output.stdout +++ b/src/test/ui/ast-json/ast-json-output.stdout @@ -1 +1 @@ -{"module":{"inner":{"lo":0,"hi":0},"items":[{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"prelude_import","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":"Empty"}]},"id":null,"style":"Outer","span":{"lo":0,"hi":0}}],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"","span":{"lo":0,"hi":0}},"kind":{"variant":"Use","fields":[{"prefix":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"{{root}}","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"std","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"prelude","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"v1","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"kind":"Glob","span":{"lo":0,"hi":0}}]},"tokens":null},{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"macro_use","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":"Empty"}]},"id":null,"style":"Outer","span":{"lo":0,"hi":0}}],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"std","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null},{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"core","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null}],"inline":true},"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"crate_type","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":{"variant":"Eq","fields":[{"lo":0,"hi":0},{"_field0":[[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"NonJoint"]]}]}}]},"id":null,"style":"Inner","span":{"lo":0,"hi":0}}],"span":{"lo":0,"hi":0},"proc_macros":[]} +{"module":{"inner":{"lo":0,"hi":0},"items":[{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"prelude_import","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":"Empty"}]},"id":null,"style":"Outer","span":{"lo":0,"hi":0}}],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"","span":{"lo":0,"hi":0}},"kind":{"variant":"Use","fields":[{"prefix":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"{{root}}","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"std","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"prelude","span":{"lo":0,"hi":0}},"id":0,"args":null},{"ident":{"name":"v1","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"kind":"Glob","span":{"lo":0,"hi":0}}]},"tokens":null},{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"macro_use","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":"Empty"}]},"id":null,"style":"Outer","span":{"lo":0,"hi":0}}],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"std","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null},{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"core","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null}],"inline":true},"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"crate_type","span":{"lo":0,"hi":0}},"id":0,"args":null}]},"args":{"variant":"Eq","fields":[{"lo":0,"hi":0},{"0":[[{"variant":"Token","fields":[{"kind":{"variant":"Literal","fields":[{"kind":"Str","symbol":"lib","suffix":null}]},"span":{"lo":0,"hi":0}}]},"NonJoint"]]}]}}]},"id":null,"style":"Inner","span":{"lo":0,"hi":0}}],"span":{"lo":0,"hi":0},"proc_macros":[]} From 5cb4f4ed7d3959cced8e04f2802595059f2f680d Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 4 Jul 2020 16:20:24 +0100 Subject: [PATCH 5/8] Fix ui fulldeps tests --- .../derive-no-std-not-supported.rs | 22 ------------- .../deriving-encodable-decodable-box.rs | 7 ++-- ...riving-encodable-decodable-cell-refcell.rs | 19 +++++------ src/test/ui-fulldeps/deriving-global.rs | 32 ++++++++----------- src/test/ui-fulldeps/deriving-hygiene.rs | 8 +++-- .../ui-fulldeps/empty-struct-braces-derive.rs | 12 +++---- src/test/ui-fulldeps/issue-11881.rs | 21 ++++++------ src/test/ui-fulldeps/issue-14021.rs | 6 ++-- src/test/ui-fulldeps/issue-15924.rs | 9 +++--- src/test/ui-fulldeps/issue-24972.rs | 18 ++++++++--- src/test/ui-fulldeps/issue-4016.rs | 3 +- .../ui-fulldeps/rustc_encodable_hygiene.rs | 6 ++-- 12 files changed, 75 insertions(+), 88 deletions(-) delete mode 100644 src/test/ui-fulldeps/derive-no-std-not-supported.rs diff --git a/src/test/ui-fulldeps/derive-no-std-not-supported.rs b/src/test/ui-fulldeps/derive-no-std-not-supported.rs deleted file mode 100644 index 1299d82d9c4b9..0000000000000 --- a/src/test/ui-fulldeps/derive-no-std-not-supported.rs +++ /dev/null @@ -1,22 +0,0 @@ -// run-pass - -#![allow(dead_code)] -#![feature(rustc_private)] -#![no_std] - -extern crate rustc_serialize; - -#[derive(RustcEncodable)] -struct Bar { - x: u32, -} - -#[derive(RustcDecodable)] -struct Baz { - x: u32, -} - -fn main() { - Bar { x: 0 }; - Baz { x: 0 }; -} diff --git a/src/test/ui-fulldeps/deriving-encodable-decodable-box.rs b/src/test/ui-fulldeps/deriving-encodable-decodable-box.rs index 2b349ae9556c3..119fa3d6fa8ef 100644 --- a/src/test/ui-fulldeps/deriving-encodable-decodable-box.rs +++ b/src/test/ui-fulldeps/deriving-encodable-decodable-box.rs @@ -1,16 +1,17 @@ // run-pass #![allow(unused_imports)] - #![feature(box_syntax)] #![feature(rustc_private)] +extern crate rustc_macros; extern crate rustc_serialize; -use rustc_serialize::{Encodable, Decodable}; +use rustc_macros::{Decodable, Encodable}; use rustc_serialize::json; +use rustc_serialize::{Decodable, Encodable}; -#[derive(RustcEncodable, RustcDecodable)] +#[derive(Encodable, Decodable)] struct A { foo: Box<[bool]>, } diff --git a/src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs b/src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs index c2aecbdc16793..9dedf990f25ec 100644 --- a/src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs +++ b/src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs @@ -3,32 +3,29 @@ #![allow(unused_imports)] // This briefly tests the capability of `Cell` and `RefCell` to implement the // `Encodable` and `Decodable` traits via `#[derive(Encodable, Decodable)]` - - #![feature(rustc_private)] +extern crate rustc_macros; extern crate rustc_serialize; -use std::cell::{Cell, RefCell}; -use rustc_serialize::{Encodable, Decodable}; +use rustc_macros::{Decodable, Encodable}; use rustc_serialize::json; +use rustc_serialize::{Decodable, Encodable}; +use std::cell::{Cell, RefCell}; -#[derive(RustcEncodable, RustcDecodable)] +#[derive(Encodable, Decodable)] struct A { - baz: isize + baz: isize, } -#[derive(RustcEncodable, RustcDecodable)] +#[derive(Encodable, Decodable)] struct B { foo: Cell, bar: RefCell, } fn main() { - let obj = B { - foo: Cell::new(true), - bar: RefCell::new( A { baz: 2 } ) - }; + let obj = B { foo: Cell::new(true), bar: RefCell::new(A { baz: 2 }) }; let s = json::encode(&obj).unwrap(); let obj2: B = json::decode(&s).unwrap(); assert_eq!(obj.foo.get(), obj2.foo.get()); diff --git a/src/test/ui-fulldeps/deriving-global.rs b/src/test/ui-fulldeps/deriving-global.rs index 5ba34a7af6bf5..921767af981ad 100644 --- a/src/test/ui-fulldeps/deriving-global.rs +++ b/src/test/ui-fulldeps/deriving-global.rs @@ -2,33 +2,29 @@ #![feature(rustc_private)] +extern crate rustc_macros; extern crate rustc_serialize; mod submod { + use rustc_macros::{Decodable, Encodable}; + // if any of these are implemented without global calls for any // function calls, then being in a submodule will (correctly) // cause errors about unrecognised module `std` (or `extra`) - #[derive(PartialEq, PartialOrd, Eq, Ord, - Hash, - Clone, - Debug, - RustcEncodable, RustcDecodable)] - enum A { A1(usize), A2(isize) } + #[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Encodable, Decodable)] + enum A { + A1(usize), + A2(isize), + } - #[derive(PartialEq, PartialOrd, Eq, Ord, - Hash, - Clone, - Debug, - RustcEncodable, RustcDecodable)] - struct B { x: usize, y: isize } + #[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Encodable, Decodable)] + struct B { + x: usize, + y: isize, + } - #[derive(PartialEq, PartialOrd, Eq, Ord, - Hash, - Clone, - Debug, - RustcEncodable, RustcDecodable)] + #[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Encodable, Decodable)] struct C(usize, isize); - } pub fn main() {} diff --git a/src/test/ui-fulldeps/deriving-hygiene.rs b/src/test/ui-fulldeps/deriving-hygiene.rs index 85ef217e7671e..8486b8b6e481a 100644 --- a/src/test/ui-fulldeps/deriving-hygiene.rs +++ b/src/test/ui-fulldeps/deriving-hygiene.rs @@ -2,8 +2,11 @@ #![allow(non_upper_case_globals)] #![feature(rustc_private)] +extern crate rustc_macros; extern crate rustc_serialize; +use rustc_macros::{Decodable, Encodable}; + pub const other: u8 = 1; pub const f: u8 = 1; pub const d: u8 = 1; @@ -11,8 +14,7 @@ pub const s: u8 = 1; pub const state: u8 = 1; pub const cmp: u8 = 1; -#[derive(Ord,Eq,PartialOrd,PartialEq,Debug,RustcDecodable,RustcEncodable,Hash)] +#[derive(Ord, Eq, PartialOrd, PartialEq, Debug, Decodable, Encodable, Hash)] struct Foo {} -fn main() { -} +fn main() {} diff --git a/src/test/ui-fulldeps/empty-struct-braces-derive.rs b/src/test/ui-fulldeps/empty-struct-braces-derive.rs index fc85765eea4a5..6e5eb54629ccd 100644 --- a/src/test/ui-fulldeps/empty-struct-braces-derive.rs +++ b/src/test/ui-fulldeps/empty-struct-braces-derive.rs @@ -3,18 +3,18 @@ #![feature(rustc_private)] +extern crate rustc_macros; extern crate rustc_serialize; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, - Default, Debug, RustcEncodable, RustcDecodable)] +use rustc_macros::{Decodable, Encodable}; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug, Encodable, Decodable)] struct S {} -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, - Default, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug, Encodable, Decodable)] struct Z(); -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, - Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)] enum E { V {}, U, diff --git a/src/test/ui-fulldeps/issue-11881.rs b/src/test/ui-fulldeps/issue-11881.rs index 7b0abba4d16c8..6d64aeeda7e11 100644 --- a/src/test/ui-fulldeps/issue-11881.rs +++ b/src/test/ui-fulldeps/issue-11881.rs @@ -3,26 +3,27 @@ #![allow(unused_must_use)] #![allow(dead_code)] #![allow(unused_imports)] - #![feature(rustc_private)] +extern crate rustc_macros; extern crate rustc_serialize; -use std::io::Cursor; -use std::io::prelude::*; use std::fmt; +use std::io::prelude::*; +use std::io::Cursor; use std::slice; -use rustc_serialize::{Encodable, Encoder}; +use rustc_macros::Encodable; use rustc_serialize::json; use rustc_serialize::opaque; +use rustc_serialize::{Encodable, Encoder}; -#[derive(RustcEncodable)] +#[derive(Encodable)] struct Foo { baz: bool, } -#[derive(RustcEncodable)] +#[derive(Encodable)] struct Bar { froboz: usize, } @@ -33,19 +34,19 @@ enum WireProtocol { // ... } -fn encode_json(val: &T, wr: &mut Cursor>) { +fn encode_json Encodable>>(val: &T, wr: &mut Cursor>) { write!(wr, "{}", json::as_json(val)); } -fn encode_opaque(val: &T, wr: Vec) { +fn encode_opaque>(val: &T, wr: Vec) { let mut encoder = opaque::Encoder::new(wr); val.encode(&mut encoder); } pub fn main() { - let target = Foo{baz: false,}; + let target = Foo { baz: false }; let proto = WireProtocol::JSON; match proto { WireProtocol::JSON => encode_json(&target, &mut Cursor::new(Vec::new())), - WireProtocol::Opaque => encode_opaque(&target, Vec::new()) + WireProtocol::Opaque => encode_opaque(&target, Vec::new()), } } diff --git a/src/test/ui-fulldeps/issue-14021.rs b/src/test/ui-fulldeps/issue-14021.rs index 1898b12c70385..be88a593962cc 100644 --- a/src/test/ui-fulldeps/issue-14021.rs +++ b/src/test/ui-fulldeps/issue-14021.rs @@ -4,12 +4,14 @@ #![allow(unused_imports)] #![feature(rustc_private)] +extern crate rustc_macros; extern crate rustc_serialize; -use rustc_serialize::{Encodable, Decodable}; +use rustc_macros::{Decodable, Encodable}; use rustc_serialize::json; +use rustc_serialize::{Decodable, Encodable}; -#[derive(RustcEncodable, RustcDecodable, PartialEq, Debug)] +#[derive(Encodable, Decodable, PartialEq, Debug)] struct UnitLikeStruct; pub fn main() { diff --git a/src/test/ui-fulldeps/issue-15924.rs b/src/test/ui-fulldeps/issue-15924.rs index e3d4b0eb4460d..5adc2c482f5e8 100644 --- a/src/test/ui-fulldeps/issue-15924.rs +++ b/src/test/ui-fulldeps/issue-15924.rs @@ -3,20 +3,19 @@ #![allow(unused_imports)] #![allow(unused_must_use)] // pretty-expanded FIXME #23616 - #![feature(rustc_private)] extern crate rustc_serialize; -use std::fmt; -use rustc_serialize::{Encoder, Encodable}; use rustc_serialize::json; +use rustc_serialize::{Encodable, Encoder}; +use std::fmt; -struct Foo { +struct Foo Encodable>> { v: T, } -impl Drop for Foo { +impl Encodable>> Drop for Foo { fn drop(&mut self) { json::encode(&self.v); } diff --git a/src/test/ui-fulldeps/issue-24972.rs b/src/test/ui-fulldeps/issue-24972.rs index 51e134fbf8871..044a0c5000e31 100644 --- a/src/test/ui-fulldeps/issue-24972.rs +++ b/src/test/ui-fulldeps/issue-24972.rs @@ -5,11 +5,18 @@ extern crate rustc_serialize; -use rustc_serialize::{Encodable, Decodable}; +use rustc_serialize::{json, Decodable, Encodable}; use std::fmt::Display; -pub trait Entity : Decodable + Encodable + Sized { - type Key: Clone + Decodable + Encodable + ToString + Display + Eq + Ord + Sized; +pub trait Entity: Decodable + for<'a> Encodable> + Sized { + type Key: Clone + + Decodable + + for<'a> Encodable> + + ToString + + Display + + Eq + + Ord + + Sized; fn id(&self) -> Self::Key; @@ -20,7 +27,10 @@ pub struct DbRef { pub id: E::Key, } -impl DbRef where E: Entity { +impl DbRef +where + E: Entity, +{ fn get(self) -> Option { E::find_by_id(self.id) } diff --git a/src/test/ui-fulldeps/issue-4016.rs b/src/test/ui-fulldeps/issue-4016.rs index 96157c2f426c0..4fd192497a0a3 100644 --- a/src/test/ui-fulldeps/issue-4016.rs +++ b/src/test/ui-fulldeps/issue-4016.rs @@ -1,14 +1,13 @@ // run-pass #![allow(dead_code)] - #![feature(rustc_private)] extern crate rustc_serialize; use rustc_serialize::{json, Decodable}; -trait JD : Decodable {} +trait JD: Decodable {} fn exec() { let doc = json::from_str("").unwrap(); diff --git a/src/test/ui-fulldeps/rustc_encodable_hygiene.rs b/src/test/ui-fulldeps/rustc_encodable_hygiene.rs index b49135cb60b29..452110a65e4aa 100644 --- a/src/test/ui-fulldeps/rustc_encodable_hygiene.rs +++ b/src/test/ui-fulldeps/rustc_encodable_hygiene.rs @@ -2,11 +2,13 @@ #![feature(rustc_private)] +extern crate rustc_macros; #[allow(dead_code)] - extern crate rustc_serialize; -#[derive(RustcDecodable, RustcEncodable,Debug)] +use rustc_macros::{Decodable, Encodable}; + +#[derive(Decodable, Encodable, Debug)] struct A { a: String, } From e80654a4f177303967ba735a0dd58035c1effaed Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 4 Jul 2020 16:59:14 +0100 Subject: [PATCH 6/8] Fix run-make test --- .../run-make-fulldeps/save-analysis/foo.rs | 116 +++++++++--------- 1 file changed, 60 insertions(+), 56 deletions(-) diff --git a/src/test/run-make-fulldeps/save-analysis/foo.rs b/src/test/run-make-fulldeps/save-analysis/foo.rs index 789ab686e3f8e..483eeed0b39f0 100644 --- a/src/test/run-make-fulldeps/save-analysis/foo.rs +++ b/src/test/run-make-fulldeps/save-analysis/foo.rs @@ -1,4 +1,4 @@ -#![ crate_name = "test" ] +#![crate_name = "test"] #![feature(box_syntax)] #![feature(rustc_private)] #![feature(associated_type_defaults)] @@ -11,11 +11,10 @@ extern crate krate2; extern crate krate2 as krate3; use rustc_graphviz::RenderOption; -use std::collections::{HashMap,HashSet}; use std::cell::RefCell; +use std::collections::{HashMap, HashSet}; use std::io::Write; - use sub::sub2 as msalias; use sub::sub2; use sub::sub2::nested_struct as sub_struct; @@ -32,7 +31,7 @@ static bob: Option = None; // buglink test - see issue #1337. fn test_alias(i: Option<::Item>) { - let s = sub_struct{ field2: 45u32, }; + let s = sub_struct { field2: 45u32 }; // import tests fn foo(x: &Write) {} @@ -82,7 +81,7 @@ mod sub { pub enum nested_enum { Nest2 = 2, - Nest3 = 3 + Nest3 = 3, } } } @@ -103,7 +102,9 @@ struct some_fields { type SF = some_fields; trait SuperTrait { - fn qux(&self) { panic!(); } + fn qux(&self) { + panic!(); + } } trait SomeTrait: SuperTrait { @@ -131,8 +132,7 @@ impl SomeTrait for some_fields { } } -impl SuperTrait for some_fields { -} +impl SuperTrait for some_fields {} impl SubTrait for some_fields {} @@ -145,17 +145,14 @@ impl some_fields { 42 } - fn align_to(&mut self) { - - } + fn align_to(&mut self) {} fn test(&mut self) { self.align_to::(); } } -impl SuperTrait for nofields { -} +impl SuperTrait for nofields {} impl SomeTrait for nofields { fn Method(&self, x: u32) -> u32 { self.Method(x); @@ -181,59 +178,70 @@ enum SomeEnum<'a> { Ints(isize, isize), Floats(f64, f64), Strings(&'a str, &'a str, &'a str), - MyTypes(MyType, MyType) + MyTypes(MyType, MyType), } #[derive(Copy, Clone)] enum SomeOtherEnum { SomeConst1, SomeConst2, - SomeConst3 + SomeConst3, } enum SomeStructEnum { - EnumStruct{a:isize, b:isize}, - EnumStruct2{f1:MyType, f2:MyType}, - EnumStruct3{f1:MyType, f2:MyType, f3:SomeEnum<'static>} + EnumStruct { a: isize, b: isize }, + EnumStruct2 { f1: MyType, f2: MyType }, + EnumStruct3 { f1: MyType, f2: MyType, f3: SomeEnum<'static> }, } fn matchSomeEnum(val: SomeEnum) { match val { - SomeEnum::Ints(int1, int2) => { println(&(int1+int2).to_string()); } - SomeEnum::Floats(float1, float2) => { println(&(float2*float1).to_string()); } - SomeEnum::Strings(.., s3) => { println(s3); } - SomeEnum::MyTypes(mt1, mt2) => { println(&(mt1.field1 - mt2.field1).to_string()); } + SomeEnum::Ints(int1, int2) => { + println(&(int1 + int2).to_string()); + } + SomeEnum::Floats(float1, float2) => { + println(&(float2 * float1).to_string()); + } + SomeEnum::Strings(.., s3) => { + println(s3); + } + SomeEnum::MyTypes(mt1, mt2) => { + println(&(mt1.field1 - mt2.field1).to_string()); + } } } fn matchSomeStructEnum(se: SomeStructEnum) { match se { - SomeStructEnum::EnumStruct{a:a, ..} => println(&a.to_string()), - SomeStructEnum::EnumStruct2{f1:f1, f2:f_2} => println(&f_2.field1.to_string()), - SomeStructEnum::EnumStruct3{f1, ..} => println(&f1.field1.to_string()), + SomeStructEnum::EnumStruct { a: a, .. } => println(&a.to_string()), + SomeStructEnum::EnumStruct2 { f1: f1, f2: f_2 } => println(&f_2.field1.to_string()), + SomeStructEnum::EnumStruct3 { f1, .. } => println(&f1.field1.to_string()), } } - fn matchSomeStructEnum2(se: SomeStructEnum) { use SomeStructEnum::*; match se { - EnumStruct{a: ref aaa, ..} => println(&aaa.to_string()), - EnumStruct2{f1, f2: f2} => println(&f1.field1.to_string()), - EnumStruct3{f1, f3: SomeEnum::Ints(..), f2} => println(&f1.field1.to_string()), - _ => {}, + EnumStruct { a: ref aaa, .. } => println(&aaa.to_string()), + EnumStruct2 { f1, f2: f2 } => println(&f1.field1.to_string()), + EnumStruct3 { f1, f3: SomeEnum::Ints(..), f2 } => println(&f1.field1.to_string()), + _ => {} } } fn matchSomeOtherEnum(val: SomeOtherEnum) { use SomeOtherEnum::{SomeConst2, SomeConst3}; match val { - SomeOtherEnum::SomeConst1 => { println("I'm const1."); } - SomeConst2 | SomeConst3 => { println("I'm const2 or const3."); } + SomeOtherEnum::SomeConst1 => { + println("I'm const1."); + } + SomeConst2 | SomeConst3 => { + println("I'm const2 or const3."); + } } } -fn hello((z, a) : (u32, String), ex: X) { +fn hello((z, a): (u32, String), ex: X) { SameDir2::hello(43); println(&yy.to_string()); @@ -248,8 +256,8 @@ fn hello((z, a) : (u32, String), ex: X) { let x = 32.0f32; let _ = (x + ((x * x) + 1.0).sqrt()).ln(); - let s: Box = box some_fields {field1: 43}; - let s2: Box = box some_fields {field1: 43}; + let s: Box = box some_fields { field1: 43 }; + let s2: Box = box some_fields { field1: 43 }; let s3 = box nofields; s.Method(43); @@ -302,8 +310,9 @@ mod macro_use_test { } } -fn main() { // foo - let s = box some_fields {field1: 43}; +fn main() { + // foo + let s = box some_fields { field1: 43 }; hello((43, "a".to_string()), *s); sub::sub2::hello(); sub2::sub3::hello(); @@ -324,26 +333,24 @@ fn main() { // foo let vs = variable_str!(32); let mut candidates: RefCell> = RefCell::new(HashMap::new()); - let _ = blah { - used_link_args: RefCell::new([]), - }; + let _ = blah { used_link_args: RefCell::new([]) }; let s1 = nofields; - let s2 = SF { field1: 55}; - let s3: some_fields = some_fields{ field1: 55}; - let s4: msalias::nested_struct = sub::sub2::nested_struct{ field2: 55}; - let s4: msalias::nested_struct = sub2::nested_struct{ field2: 55}; + let s2 = SF { field1: 55 }; + let s3: some_fields = some_fields { field1: 55 }; + let s4: msalias::nested_struct = sub::sub2::nested_struct { field2: 55 }; + let s4: msalias::nested_struct = sub2::nested_struct { field2: 55 }; println(&s2.field1.to_string()); - let s5: MyType = box some_fields{ field1: 55}; - let s = SameDir::SameStruct{name: "Bob".to_string()}; - let s = SubDir::SubStruct{name:"Bob".to_string()}; + let s5: MyType = box some_fields { field1: 55 }; + let s = SameDir::SameStruct { name: "Bob".to_string() }; + let s = SubDir::SubStruct { name: "Bob".to_string() }; let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5); let s7: SomeEnum = SomeEnum::Strings("one", "two", "three"); matchSomeEnum(s6); matchSomeEnum(s7); let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2; matchSomeOtherEnum(s8); - let s9: SomeStructEnum = SomeStructEnum::EnumStruct2{ f1: box some_fields{ field1:10 }, - f2: box s2 }; + let s9: SomeStructEnum = + SomeStructEnum::EnumStruct2 { f1: box some_fields { field1: 10 }, f2: box s2 }; matchSomeStructEnum(s9); for x in &vec![1, 2, 3] { @@ -404,8 +411,7 @@ impl<'a> Pattern<'a> for CharEqPattern { struct CharSearcher<'a>(>::Searcher); -pub trait Error { -} +pub trait Error {} impl Error + 'static { pub fn is(&self) -> bool { @@ -419,8 +425,7 @@ impl Error + 'static + Send { } } extern crate rustc_serialize; -#[derive(Clone, Copy, Hash, RustcEncodable, RustcDecodable, - PartialEq, Eq, PartialOrd, Ord, Debug, Default)] +#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Default)] struct AllDerives(i32); fn test_format_args() { @@ -433,9 +438,8 @@ fn test_format_args() { print!("x is {}, y is {1}, name is {n}", x, y, n = name); } - union TestUnion { - f1: u32 + f1: u32, } struct FrameBuffer; @@ -454,5 +458,5 @@ trait Foo { type Bar = FrameBuffer; } -#[doc(include="extra-docs.md")] +#[doc(include = "extra-docs.md")] struct StructWithDocs; From ae7951ed43558fa887f52b0786237935d11cb5c3 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 18 Jul 2020 15:12:52 +0100 Subject: [PATCH 7/8] Fix rustc_ast unit test --- src/librustc_ast/ast/tests.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustc_ast/ast/tests.rs b/src/librustc_ast/ast/tests.rs index 7558e9cc3a3af..8ba55bf037b12 100644 --- a/src/librustc_ast/ast/tests.rs +++ b/src/librustc_ast/ast/tests.rs @@ -3,6 +3,9 @@ use super::*; // Are ASTs encodable? #[test] fn check_asts_encodable() { - fn assert_encodable() {} + fn assert_encodable< + T: for<'a> rustc_serialize::Encodable>, + >() { + } assert_encodable::(); } From c4f91bb28102e88d4ab94e8d3b2dbc25e02dfa53 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 18 Jul 2020 20:14:50 +0100 Subject: [PATCH 8/8] Fix rustc_serialize unit tests --- Cargo.lock | 1 + src/librustc_serialize/Cargo.toml | 3 +++ src/librustc_serialize/json.rs | 21 ++++++++++++--------- src/librustc_serialize/tests/json.rs | 21 +++++++++++---------- src/librustc_serialize/tests/opaque.rs | 11 +++++++---- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 564c3da522342..c1fa3bef07c7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3877,6 +3877,7 @@ name = "rustc_serialize" version = "0.0.0" dependencies = [ "indexmap", + "rustc_macros", "smallvec 1.4.0", ] diff --git a/src/librustc_serialize/Cargo.toml b/src/librustc_serialize/Cargo.toml index 84206df50ccee..939e6a59ba099 100644 --- a/src/librustc_serialize/Cargo.toml +++ b/src/librustc_serialize/Cargo.toml @@ -11,3 +11,6 @@ path = "lib.rs" [dependencies] indexmap = "1" smallvec = { version = "1.0", features = ["union", "may_dangle"] } + +[dev-dependencies] +rustc_macros = { path = "../librustc_macros" } diff --git a/src/librustc_serialize/json.rs b/src/librustc_serialize/json.rs index dafeb053d83d3..6c8965aa2e31f 100644 --- a/src/librustc_serialize/json.rs +++ b/src/librustc_serialize/json.rs @@ -47,17 +47,17 @@ //! //! Rust provides a mechanism for low boilerplate encoding & decoding of values to and from JSON via //! the serialization API. -//! To be able to encode a piece of data, it must implement the `serialize::RustcEncodable` trait. -//! To be able to decode a piece of data, it must implement the `serialize::RustcDecodable` trait. +//! To be able to encode a piece of data, it must implement the `serialize::Encodable` trait. +//! To be able to decode a piece of data, it must implement the `serialize::Decodable` trait. //! The Rust compiler provides an annotation to automatically generate the code for these traits: -//! `#[derive(RustcDecodable, RustcEncodable)]` +//! `#[derive(Decodable, Encodable)]` //! //! The JSON API provides an enum `json::Json` and a trait `ToJson` to encode objects. //! The `ToJson` trait provides a `to_json` method to convert an object into a `json::Json` value. //! A `json::Json` value can be encoded as a string or buffer using the functions described above. //! You can also use the `json::Encoder` object, which implements the `Encoder` trait. //! -//! When using `ToJson` the `RustcEncodable` trait implementation is not mandatory. +//! When using `ToJson` the `Encodable` trait implementation is not mandatory. //! //! # Examples of use //! @@ -68,10 +68,11 @@ //! //! ```rust //! # #![feature(rustc_private)] +//! use rustc_macros::{Decodable, Encodable}; //! use rustc_serialize::json; //! //! // Automatically generate `Decodable` and `Encodable` trait implementations -//! #[derive(RustcDecodable, RustcEncodable)] +//! #[derive(Decodable, Encodable)] //! pub struct TestStruct { //! data_int: u8, //! data_str: String, @@ -100,6 +101,7 @@ //! //! ```rust //! # #![feature(rustc_private)] +//! use rustc_macros::Encodable; //! use rustc_serialize::json::{self, ToJson, Json}; //! //! // A custom data structure @@ -115,8 +117,8 @@ //! } //! } //! -//! // Only generate `RustcEncodable` trait implementation -//! #[derive(RustcEncodable)] +//! // Only generate `Encodable` trait implementation +//! #[derive(Encodable)] //! pub struct ComplexNumRecord { //! uid: u8, //! dsc: String, @@ -137,11 +139,12 @@ //! //! ```rust //! # #![feature(rustc_private)] +//! use rustc_macros::Decodable; //! use std::collections::BTreeMap; //! use rustc_serialize::json::{self, Json, ToJson}; //! -//! // Only generate `RustcDecodable` trait implementation -//! #[derive(RustcDecodable)] +//! // Only generate `Decodable` trait implementation +//! #[derive(Decodable)] //! pub struct TestStruct { //! data_int: u8, //! data_str: String, diff --git a/src/librustc_serialize/tests/json.rs b/src/librustc_serialize/tests/json.rs index 59c481edbca3a..e3a823127d93e 100644 --- a/src/librustc_serialize/tests/json.rs +++ b/src/librustc_serialize/tests/json.rs @@ -9,6 +9,7 @@ use json::{ from_str, DecodeResult, Decoder, DecoderError, Encoder, EncoderError, Json, JsonEvent, Parser, StackElement, }; +use rustc_macros::{Decodable, Encodable}; use rustc_serialize::json; use rustc_serialize::{Decodable, Encodable}; @@ -17,7 +18,7 @@ use std::io::prelude::*; use std::string; use Animal::*; -#[derive(RustcDecodable, Eq, PartialEq, Debug)] +#[derive(Decodable, Eq, PartialEq, Debug)] struct OptionData { opt: Option, } @@ -48,20 +49,20 @@ fn test_decode_option_malformed() { ); } -#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(PartialEq, Encodable, Decodable, Debug)] enum Animal { Dog, Frog(string::String, isize), } -#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(PartialEq, Encodable, Decodable, Debug)] struct Inner { a: (), b: usize, c: Vec, } -#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(PartialEq, Encodable, Decodable, Debug)] struct Outer { inner: Vec, } @@ -568,7 +569,7 @@ fn test_decode_struct() { ); } -#[derive(RustcDecodable)] +#[derive(Decodable)] struct FloatStruct { f: f64, a: Vec, @@ -616,7 +617,7 @@ fn test_multiline_errors() { assert_eq!(from_str("{\n \"foo\":\n \"bar\""), Err(SyntaxError(EOFWhileParsingObject, 3, 8))); } -#[derive(RustcDecodable)] +#[derive(Decodable)] #[allow(dead_code)] struct DecodeStruct { x: f64, @@ -624,12 +625,12 @@ struct DecodeStruct { z: string::String, w: Vec, } -#[derive(RustcDecodable)] +#[derive(Decodable)] enum DecodeEnum { A(f64), B(string::String), } -fn check_err(to_parse: &'static str, expected: DecoderError) { +fn check_err>(to_parse: &'static str, expected: DecoderError) { let res: DecodeResult = match from_str(to_parse) { Err(e) => Err(ParseError(e)), Ok(json) => Decodable::decode(&mut Decoder::new(json)), @@ -933,7 +934,7 @@ fn test_prettyencoder_indent_level_param() { #[test] fn test_hashmap_with_enum_key() { use std::collections::HashMap; - #[derive(RustcEncodable, Eq, Hash, PartialEq, RustcDecodable, Debug)] + #[derive(Encodable, Eq, Hash, PartialEq, Decodable, Debug)] enum Enum { Foo, #[allow(dead_code)] @@ -1254,7 +1255,7 @@ fn test_to_json() { #[test] fn test_encode_hashmap_with_arbitrary_key() { use std::collections::HashMap; - #[derive(PartialEq, Eq, Hash, RustcEncodable)] + #[derive(PartialEq, Eq, Hash, Encodable)] struct ArbitraryType(usize); let mut hm: HashMap = HashMap::new(); hm.insert(ArbitraryType(1), true); diff --git a/src/librustc_serialize/tests/opaque.rs b/src/librustc_serialize/tests/opaque.rs index c827391700709..13b3676a56cd5 100644 --- a/src/librustc_serialize/tests/opaque.rs +++ b/src/librustc_serialize/tests/opaque.rs @@ -1,10 +1,11 @@ #![allow(rustc::internal)] +use rustc_macros::{Decodable, Encodable}; use rustc_serialize::opaque::{Decoder, Encoder}; use rustc_serialize::{Decodable, Encodable}; use std::fmt::Debug; -#[derive(PartialEq, Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Clone, Debug, Encodable, Decodable)] struct Struct { a: (), b: u8, @@ -27,11 +28,13 @@ struct Struct { q: Option, } -fn check_round_trip(values: Vec) { +fn check_round_trip + for<'a> Decodable> + PartialEq + Debug>( + values: Vec, +) { let mut encoder = Encoder::new(Vec::new()); for value in &values { - Encodable::encode(&value, &mut encoder).unwrap(); + Encodable::encode(value, &mut encoder).unwrap(); } let data = encoder.into_inner(); @@ -225,7 +228,7 @@ fn test_struct() { }]); } -#[derive(PartialEq, Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Clone, Debug, Encodable, Decodable)] enum Enum { Variant1, Variant2(usize, f32),