Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,12 @@ impl<F> Invoke<ast::Generics> for ItemStructBuilder<F>
}
}

impl<F> Invoke<P<ast::StructDef>> for ItemStructBuilder<F>
impl<F> Invoke<P<ast::VariantData>> for ItemStructBuilder<F>
where F: Invoke<P<ast::Item>>,
{
type Result = F::Result;

fn invoke(self, struct_def: P<ast::StructDef>) -> F::Result {
fn invoke(self, struct_def: P<ast::VariantData>) -> F::Result {
let struct_ = ast::ItemStruct(struct_def, self.generics);
self.builder.build_item_(self.id, struct_)
}
Expand Down Expand Up @@ -505,10 +505,10 @@ impl<F> ItemTupleStructBuilder<F>
}

pub fn build(self) -> F::Result {
let struct_def = ast::StructDef {
fields: self.fields,
ctor_id: Some(ast::DUMMY_NODE_ID),
};
let struct_def = ast::VariantData::Struct (
self.fields,
ast::DUMMY_NODE_ID,
);
let struct_ = ast::ItemStruct(P(struct_def), self.generics);
self.builder.build_item_(self.id, struct_)
}
Expand Down
12 changes: 6 additions & 6 deletions src/struct_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl StructDefBuilder {
}

impl<F> StructDefBuilder<F>
where F: Invoke<P<ast::StructDef>>
where F: Invoke<P<ast::VariantData>>
{
pub fn new_with_callback(callback: F) -> Self {
StructDefBuilder {
Expand Down Expand Up @@ -57,15 +57,15 @@ impl<F> StructDefBuilder<F>
}

pub fn build(self) -> F::Result {
self.callback.invoke(P(ast::StructDef {
fields: self.fields,
ctor_id: None,
}))
self.callback.invoke(P(ast::VariantData::Struct(
self.fields,
ast::DUMMY_NODE_ID,
)))
}
}

impl<F> Invoke<ast::StructField> for StructDefBuilder<F>
where F: Invoke<P<ast::StructDef>>,
where F: Invoke<P<ast::VariantData>>,
{
type Result = Self;

Expand Down
28 changes: 14 additions & 14 deletions src/variant.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::iter::IntoIterator;

use syntax::ast;
use syntax::codemap::{DUMMY_SP, Span, respan};
use syntax::codemap::{DUMMY_SP, Span, respan, Spanned};
use syntax::ptr::P;

use attr::AttrBuilder;
Expand Down Expand Up @@ -54,7 +54,7 @@ impl<F> VariantBuilder<F>
pub fn tuple(self) -> VariantTupleBuilder<F> {
VariantTupleBuilder {
builder: self,
args: vec![],
fields: vec![],
}
}

Expand All @@ -64,12 +64,11 @@ impl<F> VariantBuilder<F>
})
}

pub fn build_variant_kind(self, kind: ast::VariantKind) -> F::Result {
pub fn build_variant_kind(self, struct_def: P<ast::VariantData>) -> F::Result {
let variant_ = ast::Variant_ {
name: self.id,
attrs: self.attrs,
kind: kind,
id: ast::DUMMY_NODE_ID,
data: struct_def,
disr_expr: None,
};
let variant = P(respan(self.span, variant_));
Expand Down Expand Up @@ -101,7 +100,7 @@ impl<F> Invoke<ast::Attribute> for VariantBuilder<F>

pub struct VariantTupleBuilder<F> {
builder: VariantBuilder<F>,
args: Vec<ast::VariantArg>,
fields: Vec<Spanned<ast::StructField_>>,
}

impl<F> VariantTupleBuilder<F>
Expand All @@ -117,10 +116,12 @@ impl<F> VariantTupleBuilder<F>
}

pub fn with_ty(mut self, ty: P<ast::Ty>) -> Self {
self.args.push(ast::VariantArg {
self.fields.push(Spanned { span: ty.span, node: ast::StructField_ {
ty: ty,
kind: ast::UnnamedField(ast::Inherited),
attrs: Vec::new(),
id: ast::DUMMY_NODE_ID,
});
}});
self
}

Expand All @@ -129,8 +130,8 @@ impl<F> VariantTupleBuilder<F>
}

pub fn build(self) -> F::Result {
let kind = ast::TupleVariantKind(self.args);
self.builder.build_variant_kind(kind)
let kind = ast::VariantData::Tuple(self.fields, ast::DUMMY_NODE_ID);
self.builder.build_variant_kind(P(kind))
}
}

Expand Down Expand Up @@ -170,13 +171,12 @@ impl<F> VariantStructBuilder<F>
}
}

impl<F> Invoke<P<ast::StructDef>> for VariantStructBuilder<F>
impl<F> Invoke<P<ast::VariantData>> for VariantStructBuilder<F>
where F: Invoke<P<ast::Variant>>,
{
type Result = F::Result;

fn invoke(self, struct_def: P<ast::StructDef>) -> F::Result {
let kind = ast::StructVariantKind(struct_def);
self.builder.build_variant_kind(kind)
fn invoke(self, struct_def: P<ast::VariantData>) -> F::Result {
self.builder.build_variant_kind(struct_def)
}
}
8 changes: 4 additions & 4 deletions tests/test_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ fn test_tuple_struct() {
attrs: vec![],
id: ast::DUMMY_NODE_ID,
node: ast::ItemStruct(
P(ast::StructDef {
fields: vec![
P(ast::VariantData::Struct(
vec![
Spanned {
span: DUMMY_SP,
node: ast::StructField_ {
Expand All @@ -193,8 +193,8 @@ fn test_tuple_struct() {
},
},
],
ctor_id: Some(ast::DUMMY_NODE_ID),
}),
ast::DUMMY_NODE_ID,
)),
builder.generics().build(),
),
vis: ast::Inherited,
Expand Down
24 changes: 12 additions & 12 deletions tests/test_struct_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ fn test_empty() {

assert_eq!(
struct_def,
P(ast::StructDef {
fields: vec![],
ctor_id: None,
})
P(ast::VariantData::Struct(
vec![],
ast::DUMMY_NODE_ID,
))
);
}

Expand All @@ -28,8 +28,8 @@ fn test_fields() {

assert_eq!(
struct_def,
P(ast::StructDef {
fields: vec![
P(ast::VariantData::Struct(
vec![
Spanned {
span: DUMMY_SP,
node: ast::StructField_ {
Expand All @@ -55,8 +55,8 @@ fn test_fields() {
},
},
],
ctor_id: None,
})
ast::DUMMY_NODE_ID,
))
);
}

Expand All @@ -72,8 +72,8 @@ fn test_attrs() {

assert_eq!(
struct_def,
P(ast::StructDef {
fields: vec![
P(ast::VariantData::Struct (
vec![
Spanned {
span: DUMMY_SP,
node: ast::StructField_ {
Expand Down Expand Up @@ -115,8 +115,8 @@ fn test_attrs() {
},
},
],
ctor_id: None,
})
ast::DUMMY_NODE_ID,
))
);
}

Expand Down
42 changes: 22 additions & 20 deletions tests/test_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ fn test_empty_tuple_variant() {
node: ast::Variant_ {
name: builder.id("A"),
attrs: vec![],
kind: ast::TupleVariantKind(vec![]),
id: ast::DUMMY_NODE_ID,
data: P(ast::VariantData::Tuple(vec![], ast::DUMMY_NODE_ID)),
disr_expr: None,
},
})
Expand All @@ -39,17 +38,23 @@ fn test_tuple_variant() {
node: ast::Variant_ {
name: builder.id("A"),
attrs: vec![],
kind: ast::TupleVariantKind(vec![
ast::VariantArg {
ty: builder.ty().isize(),
id: ast::DUMMY_NODE_ID,
},
ast::VariantArg {
ty: builder.ty().isize(),
id: ast::DUMMY_NODE_ID,
},
]),
id: ast::DUMMY_NODE_ID,
data: P(ast::VariantData::Tuple(
vec![
Spanned { span: DUMMY_SP, node: ast::StructField_ {
ty: builder.ty().isize(),
kind: ast::UnnamedField(ast::Inherited),
attrs: Vec::new(),
id: ast::DUMMY_NODE_ID,
}},
Spanned { span: DUMMY_SP, node: ast::StructField_ {
ty: builder.ty().isize(),
kind: ast::UnnamedField(ast::Inherited),
attrs: Vec::new(),
id: ast::DUMMY_NODE_ID,
}},
],
ast::DUMMY_NODE_ID,
)),
disr_expr: None,
},
})
Expand All @@ -71,13 +76,10 @@ fn test_struct_variant() {
node: ast::Variant_ {
name: builder.id("A"),
attrs: vec![],
kind: ast::StructVariantKind(
builder.struct_def()
.field("a").ty().isize()
.field("b").ty().isize()
.build()
),
id: ast::DUMMY_NODE_ID,
data: builder.struct_def()
.field("a").ty().isize()
.field("b").ty().isize()
.build(),
disr_expr: None,
},
})
Expand Down