Skip to content

Commit c4f91bb

Browse files
committed
Fix rustc_serialize unit tests
1 parent ae7951e commit c4f91bb

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3877,6 +3877,7 @@ name = "rustc_serialize"
38773877
version = "0.0.0"
38783878
dependencies = [
38793879
"indexmap",
3880+
"rustc_macros",
38803881
"smallvec 1.4.0",
38813882
]
38823883

src/librustc_serialize/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ path = "lib.rs"
1111
[dependencies]
1212
indexmap = "1"
1313
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
14+
15+
[dev-dependencies]
16+
rustc_macros = { path = "../librustc_macros" }

src/librustc_serialize/json.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@
4747
//!
4848
//! Rust provides a mechanism for low boilerplate encoding & decoding of values to and from JSON via
4949
//! the serialization API.
50-
//! To be able to encode a piece of data, it must implement the `serialize::RustcEncodable` trait.
51-
//! To be able to decode a piece of data, it must implement the `serialize::RustcDecodable` trait.
50+
//! To be able to encode a piece of data, it must implement the `serialize::Encodable` trait.
51+
//! To be able to decode a piece of data, it must implement the `serialize::Decodable` trait.
5252
//! The Rust compiler provides an annotation to automatically generate the code for these traits:
53-
//! `#[derive(RustcDecodable, RustcEncodable)]`
53+
//! `#[derive(Decodable, Encodable)]`
5454
//!
5555
//! The JSON API provides an enum `json::Json` and a trait `ToJson` to encode objects.
5656
//! The `ToJson` trait provides a `to_json` method to convert an object into a `json::Json` value.
5757
//! A `json::Json` value can be encoded as a string or buffer using the functions described above.
5858
//! You can also use the `json::Encoder` object, which implements the `Encoder` trait.
5959
//!
60-
//! When using `ToJson` the `RustcEncodable` trait implementation is not mandatory.
60+
//! When using `ToJson` the `Encodable` trait implementation is not mandatory.
6161
//!
6262
//! # Examples of use
6363
//!
@@ -68,10 +68,11 @@
6868
//!
6969
//! ```rust
7070
//! # #![feature(rustc_private)]
71+
//! use rustc_macros::{Decodable, Encodable};
7172
//! use rustc_serialize::json;
7273
//!
7374
//! // Automatically generate `Decodable` and `Encodable` trait implementations
74-
//! #[derive(RustcDecodable, RustcEncodable)]
75+
//! #[derive(Decodable, Encodable)]
7576
//! pub struct TestStruct {
7677
//! data_int: u8,
7778
//! data_str: String,
@@ -100,6 +101,7 @@
100101
//!
101102
//! ```rust
102103
//! # #![feature(rustc_private)]
104+
//! use rustc_macros::Encodable;
103105
//! use rustc_serialize::json::{self, ToJson, Json};
104106
//!
105107
//! // A custom data structure
@@ -115,8 +117,8 @@
115117
//! }
116118
//! }
117119
//!
118-
//! // Only generate `RustcEncodable` trait implementation
119-
//! #[derive(RustcEncodable)]
120+
//! // Only generate `Encodable` trait implementation
121+
//! #[derive(Encodable)]
120122
//! pub struct ComplexNumRecord {
121123
//! uid: u8,
122124
//! dsc: String,
@@ -137,11 +139,12 @@
137139
//!
138140
//! ```rust
139141
//! # #![feature(rustc_private)]
142+
//! use rustc_macros::Decodable;
140143
//! use std::collections::BTreeMap;
141144
//! use rustc_serialize::json::{self, Json, ToJson};
142145
//!
143-
//! // Only generate `RustcDecodable` trait implementation
144-
//! #[derive(RustcDecodable)]
146+
//! // Only generate `Decodable` trait implementation
147+
//! #[derive(Decodable)]
145148
//! pub struct TestStruct {
146149
//! data_int: u8,
147150
//! data_str: String,

src/librustc_serialize/tests/json.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use json::{
99
from_str, DecodeResult, Decoder, DecoderError, Encoder, EncoderError, Json, JsonEvent, Parser,
1010
StackElement,
1111
};
12+
use rustc_macros::{Decodable, Encodable};
1213
use rustc_serialize::json;
1314
use rustc_serialize::{Decodable, Encodable};
1415

@@ -17,7 +18,7 @@ use std::io::prelude::*;
1718
use std::string;
1819
use Animal::*;
1920

20-
#[derive(RustcDecodable, Eq, PartialEq, Debug)]
21+
#[derive(Decodable, Eq, PartialEq, Debug)]
2122
struct OptionData {
2223
opt: Option<usize>,
2324
}
@@ -48,20 +49,20 @@ fn test_decode_option_malformed() {
4849
);
4950
}
5051

51-
#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)]
52+
#[derive(PartialEq, Encodable, Decodable, Debug)]
5253
enum Animal {
5354
Dog,
5455
Frog(string::String, isize),
5556
}
5657

57-
#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)]
58+
#[derive(PartialEq, Encodable, Decodable, Debug)]
5859
struct Inner {
5960
a: (),
6061
b: usize,
6162
c: Vec<string::String>,
6263
}
6364

64-
#[derive(PartialEq, RustcEncodable, RustcDecodable, Debug)]
65+
#[derive(PartialEq, Encodable, Decodable, Debug)]
6566
struct Outer {
6667
inner: Vec<Inner>,
6768
}
@@ -568,7 +569,7 @@ fn test_decode_struct() {
568569
);
569570
}
570571

571-
#[derive(RustcDecodable)]
572+
#[derive(Decodable)]
572573
struct FloatStruct {
573574
f: f64,
574575
a: Vec<f64>,
@@ -616,20 +617,20 @@ fn test_multiline_errors() {
616617
assert_eq!(from_str("{\n \"foo\":\n \"bar\""), Err(SyntaxError(EOFWhileParsingObject, 3, 8)));
617618
}
618619

619-
#[derive(RustcDecodable)]
620+
#[derive(Decodable)]
620621
#[allow(dead_code)]
621622
struct DecodeStruct {
622623
x: f64,
623624
y: bool,
624625
z: string::String,
625626
w: Vec<DecodeStruct>,
626627
}
627-
#[derive(RustcDecodable)]
628+
#[derive(Decodable)]
628629
enum DecodeEnum {
629630
A(f64),
630631
B(string::String),
631632
}
632-
fn check_err<T: Decodable>(to_parse: &'static str, expected: DecoderError) {
633+
fn check_err<T: Decodable<Decoder>>(to_parse: &'static str, expected: DecoderError) {
633634
let res: DecodeResult<T> = match from_str(to_parse) {
634635
Err(e) => Err(ParseError(e)),
635636
Ok(json) => Decodable::decode(&mut Decoder::new(json)),
@@ -933,7 +934,7 @@ fn test_prettyencoder_indent_level_param() {
933934
#[test]
934935
fn test_hashmap_with_enum_key() {
935936
use std::collections::HashMap;
936-
#[derive(RustcEncodable, Eq, Hash, PartialEq, RustcDecodable, Debug)]
937+
#[derive(Encodable, Eq, Hash, PartialEq, Decodable, Debug)]
937938
enum Enum {
938939
Foo,
939940
#[allow(dead_code)]
@@ -1254,7 +1255,7 @@ fn test_to_json() {
12541255
#[test]
12551256
fn test_encode_hashmap_with_arbitrary_key() {
12561257
use std::collections::HashMap;
1257-
#[derive(PartialEq, Eq, Hash, RustcEncodable)]
1258+
#[derive(PartialEq, Eq, Hash, Encodable)]
12581259
struct ArbitraryType(usize);
12591260
let mut hm: HashMap<ArbitraryType, bool> = HashMap::new();
12601261
hm.insert(ArbitraryType(1), true);

src/librustc_serialize/tests/opaque.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#![allow(rustc::internal)]
22

3+
use rustc_macros::{Decodable, Encodable};
34
use rustc_serialize::opaque::{Decoder, Encoder};
45
use rustc_serialize::{Decodable, Encodable};
56
use std::fmt::Debug;
67

7-
#[derive(PartialEq, Clone, Debug, RustcEncodable, RustcDecodable)]
8+
#[derive(PartialEq, Clone, Debug, Encodable, Decodable)]
89
struct Struct {
910
a: (),
1011
b: u8,
@@ -27,11 +28,13 @@ struct Struct {
2728
q: Option<u32>,
2829
}
2930

30-
fn check_round_trip<T: Encodable + Decodable + PartialEq + Debug>(values: Vec<T>) {
31+
fn check_round_trip<T: Encodable<Encoder> + for<'a> Decodable<Decoder<'a>> + PartialEq + Debug>(
32+
values: Vec<T>,
33+
) {
3134
let mut encoder = Encoder::new(Vec::new());
3235

3336
for value in &values {
34-
Encodable::encode(&value, &mut encoder).unwrap();
37+
Encodable::encode(value, &mut encoder).unwrap();
3538
}
3639

3740
let data = encoder.into_inner();
@@ -225,7 +228,7 @@ fn test_struct() {
225228
}]);
226229
}
227230

228-
#[derive(PartialEq, Clone, Debug, RustcEncodable, RustcDecodable)]
231+
#[derive(PartialEq, Clone, Debug, Encodable, Decodable)]
229232
enum Enum {
230233
Variant1,
231234
Variant2(usize, f32),

0 commit comments

Comments
 (0)