about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2020-07-18 20:14:50 +0100
committerMatthew Jasper <mjjasper1@gmail.com>2020-08-14 17:34:32 +0100
commitc4f91bb28102e88d4ab94e8d3b2dbc25e02dfa53 (patch)
tree61e39e76fdfef89fa7dce7db6276088240536b36
parentae7951ed43558fa887f52b0786237935d11cb5c3 (diff)
downloadrust-c4f91bb28102e88d4ab94e8d3b2dbc25e02dfa53.tar.gz
rust-c4f91bb28102e88d4ab94e8d3b2dbc25e02dfa53.zip
Fix rustc_serialize unit tests
-rw-r--r--Cargo.lock1
-rw-r--r--src/librustc_serialize/Cargo.toml3
-rw-r--r--src/librustc_serialize/json.rs21
-rw-r--r--src/librustc_serialize/tests/json.rs21
-rw-r--r--src/librustc_serialize/tests/opaque.rs11
5 files changed, 34 insertions, 23 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 564c3da5223..c1fa3bef07c 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 84206df50cc..939e6a59ba0 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 dafeb053d83..6c8965aa2e3 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 59c481edbca..e3a823127d9 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<usize>,
 }
@@ -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<string::String>,
 }
 
-#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)]
+#[derive(PartialEq, Encodable, Decodable, Debug)]
 struct Outer {
     inner: Vec<Inner>,
 }
@@ -568,7 +569,7 @@ fn test_decode_struct() {
     );
 }
 
-#[derive(RustcDecodable)]
+#[derive(Decodable)]
 struct FloatStruct {
     f: f64,
     a: Vec<f64>,
@@ -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<DecodeStruct>,
 }
-#[derive(RustcDecodable)]
+#[derive(Decodable)]
 enum DecodeEnum {
     A(f64),
     B(string::String),
 }
-fn check_err<T: Decodable>(to_parse: &'static str, expected: DecoderError) {
+fn check_err<T: Decodable<Decoder>>(to_parse: &'static str, expected: DecoderError) {
     let res: DecodeResult<T> = 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<ArbitraryType, bool> = HashMap::new();
     hm.insert(ArbitraryType(1), true);
diff --git a/src/librustc_serialize/tests/opaque.rs b/src/librustc_serialize/tests/opaque.rs
index c8273917007..13b3676a56c 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<u32>,
 }
 
-fn check_round_trip<T: Encodable + Decodable + PartialEq + Debug>(values: Vec<T>) {
+fn check_round_trip<T: Encodable<Encoder> + for<'a> Decodable<Decoder<'a>> + PartialEq + Debug>(
+    values: Vec<T>,
+) {
     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),