Skip to content

Commit 606848a

Browse files
committed
Fix all tests
1 parent 7381ea0 commit 606848a

File tree

4 files changed

+111
-35
lines changed

4 files changed

+111
-35
lines changed

src/test/ui-fulldeps/extern-mod-syntax.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#![allow(unused_imports)]
44
#![feature(rustc_private)]
55

6-
extern crate rustc_serialize;
7-
use rustc_serialize::json::Object;
6+
extern crate libc;
7+
use libc::c_void;
88

99
pub fn main() {
1010
println!("Hello world!");

src/test/ui-fulldeps/issue-11881.rs

+52-14
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,80 @@
33
#![allow(unused_must_use)]
44
#![allow(dead_code)]
55
#![allow(unused_imports)]
6-
#![feature(rustc_private)]
7-
8-
extern crate rustc_macros;
9-
extern crate rustc_serialize;
106

117
use std::fmt;
128
use std::io::prelude::*;
139
use std::io::Cursor;
1410
use std::slice;
11+
use std::marker::PhantomData;
12+
13+
trait Encoder {
14+
type Error;
15+
}
16+
17+
trait Encodable<S: Encoder> {
18+
fn encode(&self, s: &mut S) -> Result<(), S::Error>;
19+
}
20+
21+
struct JsonEncoder<'a>(PhantomData<&'a mut ()>);
22+
23+
impl Encoder for JsonEncoder<'_> {
24+
type Error = ();
25+
}
26+
27+
struct AsJson<'a, T> {
28+
inner: &'a T,
29+
}
30+
31+
impl<'a, T: for<'r> Encodable<JsonEncoder<'r>>> fmt::Display for AsJson<'a, T> {
32+
/// Encodes a json value into a string
33+
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
34+
Ok(())
35+
}
36+
}
37+
38+
fn as_json<T>(t: &T) -> AsJson<'_, T> {
39+
AsJson { inner: t }
40+
}
41+
42+
struct OpaqueEncoder(Vec<u8>);
43+
44+
impl Encoder for OpaqueEncoder {
45+
type Error = ();
46+
}
1547

16-
use rustc_macros::Encodable;
17-
use rustc_serialize::json;
18-
use rustc_serialize::opaque;
19-
use rustc_serialize::{Encodable, Encoder};
2048

21-
#[derive(Encodable)]
2249
struct Foo {
2350
baz: bool,
2451
}
2552

26-
#[derive(Encodable)]
53+
impl<S: Encoder> Encodable<S> for Foo {
54+
fn encode(&self, _s: &mut S) -> Result<(), S::Error> {
55+
Ok(())
56+
}
57+
}
58+
2759
struct Bar {
2860
froboz: usize,
2961
}
3062

63+
impl<S: Encoder> Encodable<S> for Bar {
64+
fn encode(&self, _s: &mut S) -> Result<(), S::Error> {
65+
Ok(())
66+
}
67+
}
68+
3169
enum WireProtocol {
3270
JSON,
3371
Opaque,
3472
// ...
3573
}
3674

37-
fn encode_json<T: for<'a> Encodable<json::Encoder<'a>>>(val: &T, wr: &mut Cursor<Vec<u8>>) {
38-
write!(wr, "{}", json::as_json(val));
75+
fn encode_json<T: for<'a> Encodable<JsonEncoder<'a>>>(val: &T, wr: &mut Cursor<Vec<u8>>) {
76+
write!(wr, "{}", as_json(val));
3977
}
40-
fn encode_opaque<T: Encodable<opaque::Encoder>>(val: &T, wr: Vec<u8>) {
41-
let mut encoder = opaque::Encoder::new(wr);
78+
fn encode_opaque<T: Encodable<OpaqueEncoder>>(val: &T, wr: Vec<u8>) {
79+
let mut encoder = OpaqueEncoder(wr);
4280
val.encode(&mut encoder);
4381
}
4482

src/test/ui-fulldeps/issue-15924.rs

+35-8
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,48 @@
33
#![allow(unused_imports)]
44
#![allow(unused_must_use)]
55
// pretty-expanded FIXME #23616
6-
#![feature(rustc_private)]
76

8-
extern crate rustc_serialize;
9-
10-
use rustc_serialize::json;
11-
use rustc_serialize::{Encodable, Encoder};
127
use std::fmt;
8+
use std::marker::PhantomData;
9+
10+
trait Encoder {
11+
type Error;
12+
}
13+
14+
trait Encodable<S: Encoder> {
15+
fn encode(&self, s: &mut S) -> Result<(), S::Error>;
16+
}
17+
18+
impl<S: Encoder> Encodable<S> for i32 {
19+
fn encode(&self, _s: &mut S) -> Result<(), S::Error> {
20+
Ok(())
21+
}
22+
}
23+
24+
struct JsonEncoder<'a>(PhantomData<&'a mut ()>);
25+
26+
impl Encoder for JsonEncoder<'_> {
27+
type Error = ();
28+
}
29+
30+
fn encode_json<T: for<'r> Encodable<JsonEncoder<'r>>>(
31+
object: &T,
32+
) -> Result<String, ()> {
33+
let s = String::new();
34+
{
35+
let mut encoder = JsonEncoder(PhantomData);
36+
object.encode(&mut encoder)?;
37+
}
38+
Ok(s)
39+
}
1340

14-
struct Foo<T: for<'a> Encodable<json::Encoder<'a>>> {
41+
struct Foo<T: for<'a> Encodable<JsonEncoder<'a>>> {
1542
v: T,
1643
}
1744

18-
impl<T: for<'a> Encodable<json::Encoder<'a>>> Drop for Foo<T> {
45+
impl<T: for<'a> Encodable<JsonEncoder<'a>>> Drop for Foo<T> {
1946
fn drop(&mut self) {
20-
json::encode(&self.v);
47+
encode_json(&self.v);
2148
}
2249
}
2350

src/test/ui-fulldeps/issue-2804.rs

+22-11
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,38 @@
22

33
#![allow(non_camel_case_types)]
44
#![allow(dead_code)]
5-
#![feature(rustc_private)]
65

7-
extern crate rustc_serialize;
8-
9-
use std::collections::HashMap;
10-
use rustc_serialize::json::{self, Json};
6+
use std::collections::{BTreeMap, HashMap};
117
use std::option;
128

9+
#[derive(Clone, Debug)]
10+
enum Json {
11+
I64(i64),
12+
U64(u64),
13+
F64(f64),
14+
String(String),
15+
Boolean(bool),
16+
Array(Array),
17+
Object(Object),
18+
Null,
19+
}
20+
21+
type Array = Vec<Json>;
22+
type Object = BTreeMap<String, Json>;
23+
1324
enum object {
1425
bool_value(bool),
1526
int_value(i64),
1627
}
1728

18-
fn lookup(table: json::Object, key: String, default: String) -> String
29+
fn lookup(table: Object, key: String, default: String) -> String
1930
{
2031
match table.get(&key) {
2132
option::Option::Some(&Json::String(ref s)) => {
2233
s.to_string()
2334
}
2435
option::Option::Some(value) => {
25-
println!("{} was expected to be a string but is a {}", key, value);
36+
println!("{} was expected to be a string but is a {:?}", key, value);
2637
default
2738
}
2839
option::Option::None => {
@@ -31,7 +42,7 @@ fn lookup(table: json::Object, key: String, default: String) -> String
3142
}
3243
}
3344

34-
fn add_interface(_store: isize, managed_ip: String, data: json::Json) -> (String, object)
45+
fn add_interface(_store: isize, managed_ip: String, data: Json) -> (String, object)
3546
{
3647
match &data {
3748
&Json::Object(ref interface) => {
@@ -43,13 +54,13 @@ fn add_interface(_store: isize, managed_ip: String, data: json::Json) -> (String
4354
(label, object::bool_value(false))
4455
}
4556
_ => {
46-
println!("Expected dict for {} interfaces, found {}", managed_ip, data);
57+
println!("Expected dict for {} interfaces, found {:?}", managed_ip, data);
4758
("gnos:missing-interface".to_string(), object::bool_value(true))
4859
}
4960
}
5061
}
5162

52-
fn add_interfaces(store: isize, managed_ip: String, device: HashMap<String, json::Json>)
63+
fn add_interfaces(store: isize, managed_ip: String, device: HashMap<String, Json>)
5364
-> Vec<(String, object)> {
5465
match device["interfaces"] {
5566
Json::Array(ref interfaces) =>
@@ -60,7 +71,7 @@ fn add_interfaces(store: isize, managed_ip: String, device: HashMap<String, json
6071
}
6172
_ =>
6273
{
63-
println!("Expected list for {} interfaces, found {}", managed_ip,
74+
println!("Expected list for {} interfaces, found {:?}", managed_ip,
6475
device["interfaces"]);
6576
Vec::new()
6677
}

0 commit comments

Comments
 (0)