Skip to content
Prev Previous commit
Next Next commit
Remove redundant tests
Make From impl consistent with other types of types
  • Loading branch information
dvdplm committed Jan 18, 2021
commit efcbed837b90752f4de91eb9ce61b89429029a6d
6 changes: 1 addition & 5 deletions src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ impl From<TypeDefTuple> for Type {

impl From<TypeDefPhantom> for Type {
fn from(phantom: TypeDefPhantom) -> Self {
Self::new(
Path::prelude("PhantomData"),
vec![phantom.type_param],
phantom,
)
Self::new(Path::voldemort(), Vec::new(), phantom)
}
}

Expand Down
53 changes: 1 addition & 52 deletions test_suite/tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn struct_derive() {
}

#[test]
fn phantom_types_in_structs() {
fn phantom_data_is_part_of_the_type_info() {
#[allow(unused)]
#[derive(TypeInfo)]
struct P<T> {
Expand All @@ -97,57 +97,6 @@ fn phantom_types_in_structs() {
assert_type!(P<bool>, ty);
}

#[test]
fn nested_phantom_types_are_derived_in_structs() {
#[allow(unused)]
#[derive(TypeInfo)]
struct Door<Size> {
size: PhantomData<Size>,
b: u16,
}
#[allow(unused)]
#[derive(TypeInfo)]
struct House<TDoor> {
a: u8,
door: TDoor,
}

let house = Type::builder()
.path(Path::new("House", "derive"))
.type_params(tuple_meta_type!(Door<u16>))
.composite(
Fields::named()
.field_of::<u8>("a", "u8")
.field_of::<Door<u16>>("door", "TDoor"),
);

assert_type!(House<Door<u16>>, house);
}

#[test]
fn phantoms_in_nested_tuples() {
#[allow(unused)]
#[derive(TypeInfo)]
struct A<T> {
is_a: bool,
teeth: (u8, u16, (u32, (PhantomData<T>, bool))),
}

let ty = Type::builder()
.path(Path::new("A", "derive"))
.type_params(tuple_meta_type!(u64))
.composite(
Fields::named()
.field_of::<bool>("is_a", "bool")
.field_of::<(u8, u16, (u32, (PhantomData<u64>, bool)))>(
"teeth",
"(u8, u16, (u32, (PhantomData<T>, bool)))",
),
);

assert_type!(A<u64>, ty);
}

#[test]
fn tuple_struct_derive() {
#[allow(unused)]
Expand Down
6 changes: 1 addition & 5 deletions test_suite/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ fn test_builtins() {
assert_json_for_type::<String>(json!({ "def": { "primitive": "str" } }));
assert_json_for_type::<str>(json!({ "def": { "primitive": "str" } }));
// PhantomData
assert_json_for_type::<PhantomData<bool>>(json!({
"path": ["PhantomData"],
"def": { "phantom": { "type": 1 } },
"params": [1]
}))
assert_json_for_type::<PhantomData<bool>>(json!({ "def": { "phantom": { "type": 1 } }, }))
}

#[test]
Expand Down