diff --git a/src/attr.rs b/src/attr.rs index 9c2b62121..490d0328c 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -56,7 +56,8 @@ impl AttrBuilder let attr = ast::Attribute { id: attr::mk_attr_id(), style: self.style, - value: item, + path: ast::Path::from_ident(item.span, ast::Ident::with_empty_ctxt(item.name)), + tokens: item.node.tokens(item.span), is_sugared_doc: self.is_sugared_doc, span: self.span, }; diff --git a/src/item.rs b/src/item.rs index a03cdb9a7..3eca8fe56 100644 --- a/src/item.rs +++ b/src/item.rs @@ -262,6 +262,7 @@ impl ItemBuilder builder: self, unsafety: ast::Unsafety::Normal, polarity: ast::ImplPolarity::Positive, + defaultness: ast::Defaultness::Final, generics: generics, trait_ref: None, items: vec![], @@ -1167,6 +1168,7 @@ pub struct ItemImplBuilder { builder: ItemBuilder, unsafety: ast::Unsafety, polarity: ast::ImplPolarity, + defaultness: ast::Defaultness, generics: ast::Generics, trait_ref: Option, items: Vec, @@ -1212,6 +1214,7 @@ impl ItemImplBuilder let ty_ = ast::ItemKind::Impl( self.unsafety, self.polarity, + self.defaultness, self.generics, self.trait_ref, ty, diff --git a/src/mac.rs b/src/mac.rs index 28df86dff..0400635df 100644 --- a/src/mac.rs +++ b/src/mac.rs @@ -1,11 +1,11 @@ use syntax::ast; -use syntax::codemap::{self, DUMMY_SP, Span, respan}; +use syntax::codemap::{self, DUMMY_SP, FilePathMapping, Span, respan}; use syntax::ext::base::{DummyResolver, ExtCtxt}; use syntax::ext::expand; use syntax::ext::quote::rt::ToTokens; use syntax::parse::ParseSess; use syntax::ptr::P; -use syntax::tokenstream::TokenTree; +use syntax::tokenstream::{TokenStream, TokenTree}; use expr::ExprBuilder; use invoke::{Invoke, Identity}; @@ -90,7 +90,7 @@ impl MacPathBuilder pub fn with_arg(mut self, expr: T) -> Self where T: ToTokens { - let parse_sess = ParseSess::new(); + let parse_sess = ParseSess::new(FilePathMapping::empty()); let mut macro_loader = DummyResolver; let cx = make_ext_ctxt(&parse_sess, &mut macro_loader); let tokens = expr.to_tokens(&cx); @@ -107,7 +107,7 @@ impl MacPathBuilder pub fn build(self) -> F::Result { let mac = ast::Mac_ { path: self.path, - tts: self.tokens, + tts: self.tokens.into_iter().map(TokenStream::from).collect::().into(), }; self.callback.invoke(respan(self.span, mac)) } @@ -137,8 +137,8 @@ fn make_ext_ctxt<'a>(sess: &'a ParseSess, }; let ecfg = expand::ExpansionConfig::default(String::new()); - let mut cx = ExtCtxt::new(sess, ecfg, macro_loader); - cx.bt_push(info); + let cx = ExtCtxt::new(sess, ecfg, macro_loader); + cx.current_expansion.mark.set_expn_info(info); cx } diff --git a/src/path.rs b/src/path.rs index 6906e9f20..0373944f7 100644 --- a/src/path.rs +++ b/src/path.rs @@ -303,6 +303,7 @@ impl PathSegmentBuilder self.callback.invoke(ast::PathSegment { identifier: self.id, parameters: parameters, + span: self.span, }) } @@ -324,6 +325,7 @@ impl PathSegmentBuilder self.callback.invoke(ast::PathSegment { identifier: self.id, parameters: parameters, + span: self.span, }) } } diff --git a/tests/test_attr.rs b/tests/test_attr.rs index e5747039f..9ac4cfafe 100644 --- a/tests/test_attr.rs +++ b/tests/test_attr.rs @@ -6,18 +6,22 @@ use aster::AstBuilder; #[test] fn test_doc() { let builder = AstBuilder::new(); + + let item = ast::MetaItem { + name: builder.symbol("doc"), + node: ast::MetaItemKind::NameValue( + (*builder.lit().str("/// doc string")).clone(), + ), + span: DUMMY_SP, + }; + assert_eq!( builder.attr().doc("/// doc string"), ast::Attribute { id: ast::AttrId(0), style: ast::AttrStyle::Outer, - value: ast::MetaItem { - name: builder.symbol("doc"), - node: ast::MetaItemKind::NameValue( - (*builder.lit().str("/// doc string")).clone(), - ), - span: DUMMY_SP, - }, + path: ast::Path::from_ident(item.span, ast::Ident::with_empty_ctxt(item.name)), + tokens: item.node.tokens(item.span), is_sugared_doc: true, span: DUMMY_SP, } diff --git a/tests/test_item.rs b/tests/test_item.rs index 46a4389c2..a4ca9e85a 100644 --- a/tests/test_item.rs +++ b/tests/test_item.rs @@ -400,6 +400,14 @@ fn test_attr() { .field("y").ty().isize() .build(); + let item = ast::MetaItem { + name: builder.symbol("doc"), + node: ast::MetaItemKind::NameValue( + (*builder.lit().str("/// doc string")).clone(), + ), + span: DUMMY_SP, + }; + assert_eq!( struct_, P(ast::Item { @@ -408,13 +416,8 @@ fn test_attr() { ast::Attribute { id: ast::AttrId(0), style: ast::AttrStyle::Outer, - value: ast::MetaItem { - name: builder.symbol("doc"), - node: ast::MetaItemKind::NameValue( - (*builder.lit().str("/// doc string")).clone(), - ), - span: DUMMY_SP, - }, + path: ast::Path::from_ident(item.span, ast::Ident::with_empty_ctxt(item.name)), + tokens: item.node.tokens(item.span), is_sugared_doc: true, span: DUMMY_SP, } @@ -631,6 +634,7 @@ fn test_impl() { node: ast::ItemKind::Impl( ast::Unsafety::Normal, ast::ImplPolarity::Positive, + ast::Defaultness::Final, builder.generics().build(), Some(ast::TraitRef { path: builder.path().id("ser").id("Serialize").build(), diff --git a/tests/test_path.rs b/tests/test_path.rs index 9fef06f88..33b9fad0e 100644 --- a/tests/test_path.rs +++ b/tests/test_path.rs @@ -16,6 +16,7 @@ fn test_id() { segments: vec![ ast::PathSegment { identifier: builder.id("isize"), + span: DUMMY_SP, parameters: None, }, ] @@ -37,6 +38,7 @@ fn test_single_segment() { segments: vec![ ast::PathSegment { identifier: builder.id("isize"), + span: DUMMY_SP, parameters: None, }, ] @@ -61,14 +63,17 @@ fn test_multiple_segments() { ast::PathSegment::crate_root(), ast::PathSegment { identifier: builder.id("std"), + span: DUMMY_SP, parameters: None, }, ast::PathSegment { identifier: builder.id("thread"), + span: DUMMY_SP, parameters: None, }, ast::PathSegment { identifier: builder.id("Thread"), + span: DUMMY_SP, parameters: None, }, ] @@ -95,14 +100,17 @@ fn test_option() { ast::PathSegment::crate_root(), ast::PathSegment { identifier: builder.id("std"), + span: DUMMY_SP, parameters: None, }, ast::PathSegment { identifier: builder.id("option"), + span: DUMMY_SP, parameters: None, }, ast::PathSegment { identifier: builder.id("Option"), + span: DUMMY_SP, parameters: Some(P(ast::AngleBracketed(ast::AngleBracketedParameterData { lifetimes: vec![], types: vec![ @@ -132,6 +140,7 @@ fn test_lifetimes() { segments: vec![ ast::PathSegment { identifier: builder.id("Foo"), + span: DUMMY_SP, parameters: Some(P(ast::AngleBracketed(ast::AngleBracketedParameterData { lifetimes: vec![ builder.lifetime("'a"), @@ -157,6 +166,7 @@ fn test_parenthesized_no_return() { segments: vec![ ast::PathSegment { identifier: builder.id("Fn"), + span: DUMMY_SP, parameters: Some(P(ast::PathParameters::Parenthesized( ast::ParenthesizedParameterData { span: DUMMY_SP, @@ -182,6 +192,7 @@ fn test_parenthesized_with_return() { segments: vec![ ast::PathSegment { identifier: builder.id("FnMut"), + span: DUMMY_SP, parameters: Some(P(ast::PathParameters::Parenthesized( ast::ParenthesizedParameterData { span: DUMMY_SP, diff --git a/tests/test_struct_field.rs b/tests/test_struct_field.rs index 3eb64eebe..51d9ebf02 100644 --- a/tests/test_struct_field.rs +++ b/tests/test_struct_field.rs @@ -41,6 +41,20 @@ fn test_unnamed() { fn test_attrs() { let builder = AstBuilder::new(); + let item0 = ast::MetaItem { + name: builder.symbol("doc"), + node: ast::MetaItemKind::NameValue( + (*builder.lit().str("/// doc string")).clone(), + ), + span: DUMMY_SP, + }; + + let item1 = ast::MetaItem { + name: builder.symbol("automatically_derived"), + node: ast::MetaItemKind::Word, + span: DUMMY_SP, + }; + assert_eq!( builder.struct_field("x") .attr().doc("/// doc string") @@ -56,24 +70,16 @@ fn test_attrs() { ast::Attribute { id: ast::AttrId(0), style: ast::AttrStyle::Outer, - value: ast::MetaItem { - name: builder.symbol("doc"), - node: ast::MetaItemKind::NameValue( - (*builder.lit().str("/// doc string")).clone(), - ), - span: DUMMY_SP, - }, + path: ast::Path::from_ident(item0.span, ast::Ident::with_empty_ctxt(item0.name)), + tokens: item0.node.tokens(item0.span), is_sugared_doc: true, span: DUMMY_SP, }, ast::Attribute { id: ast::AttrId(1), style: ast::AttrStyle::Outer, - value: ast::MetaItem { - name: builder.symbol("automatically_derived"), - node: ast::MetaItemKind::Word, - span: DUMMY_SP, - }, + path: ast::Path::from_ident(item1.span, ast::Ident::with_empty_ctxt(item1.name)), + tokens: item1.node.tokens(item1.span), is_sugared_doc: false, span: DUMMY_SP, },