Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

update for latest nightly rustc #134

Closed
wants to merge 1 commit into from
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
3 changes: 2 additions & 1 deletion src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ impl<F> AttrBuilder<F>
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,
};
Expand Down
3 changes: 3 additions & 0 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ impl<F> ItemBuilder<F>
builder: self,
unsafety: ast::Unsafety::Normal,
polarity: ast::ImplPolarity::Positive,
defaultness: ast::Defaultness::Final,
generics: generics,
trait_ref: None,
items: vec![],
Expand Down Expand Up @@ -1167,6 +1168,7 @@ pub struct ItemImplBuilder<F> {
builder: ItemBuilder<F>,
unsafety: ast::Unsafety,
polarity: ast::ImplPolarity,
defaultness: ast::Defaultness,
generics: ast::Generics,
trait_ref: Option<ast::TraitRef>,
items: Vec<ast::ImplItem>,
Expand Down Expand Up @@ -1212,6 +1214,7 @@ impl<F> ItemImplBuilder<F>
let ty_ = ast::ItemKind::Impl(
self.unsafety,
self.polarity,
self.defaultness,
self.generics,
self.trait_ref,
ty,
Expand Down
12 changes: 6 additions & 6 deletions src/mac.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<F> MacPathBuilder<F>
pub fn with_arg<T>(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);
Expand All @@ -107,7 +107,7 @@ impl<F> MacPathBuilder<F>
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::<TokenStream>().into(),
};
self.callback.invoke(respan(self.span, mac))
}
Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ impl<F> PathSegmentBuilder<F>
self.callback.invoke(ast::PathSegment {
identifier: self.id,
parameters: parameters,
span: self.span,
})
}

Expand All @@ -324,6 +325,7 @@ impl<F> PathSegmentBuilder<F>
self.callback.invoke(ast::PathSegment {
identifier: self.id,
parameters: parameters,
span: self.span,
})
}
}
Expand Down
18 changes: 11 additions & 7 deletions tests/test_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
18 changes: 11 additions & 7 deletions tests/test_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
}
Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 11 additions & 0 deletions tests/test_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn test_id() {
segments: vec![
ast::PathSegment {
identifier: builder.id("isize"),
span: DUMMY_SP,
parameters: None,
},
]
Expand All @@ -37,6 +38,7 @@ fn test_single_segment() {
segments: vec![
ast::PathSegment {
identifier: builder.id("isize"),
span: DUMMY_SP,
parameters: None,
},
]
Expand All @@ -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,
},
]
Expand All @@ -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![
Expand Down Expand Up @@ -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"),
Expand All @@ -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,
Expand All @@ -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,
Expand Down
30 changes: 18 additions & 12 deletions tests/test_struct_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
},
Expand Down