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

Commit

Permalink
Sync with rustc 1.16.0-nightly (4ecc85beb 2016-12-28)
Browse files Browse the repository at this point in the history
Blocked on serde-deprecated/syntex#108 landing.
  • Loading branch information
erickt committed Jan 2, 2017
1 parent 54e8784 commit d59cae0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aster"
version = "0.36.0"
version = "0.37.0"
authors = ["Erick Tryzelaar <[email protected]>"]
license = "MIT/Apache-2.0"
description = "A libsyntax ast builder"
Expand All @@ -12,7 +12,7 @@ with-syntex = ["syntex_syntax"]
unstable-testing = ["clippy", "compiletest_rs"]

[dependencies]
syntex_syntax = { version = "^0.52.0", optional = true }
syntex_syntax = { version = "^0.53.0", optional = true }
clippy = { version = "0.*", optional = true }
compiletest_rs = { version = "^0.2.0", optional = true }

Expand Down
45 changes: 29 additions & 16 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,16 @@ impl<F> PathBuilder<F>
-> PathSegmentBuilder<PathSegmentsBuilder<F>>
where I: ToIdent,
{
let mut segments = vec![];

if self.global {
segments.push(ast::PathSegment::crate_root());
}

PathSegmentBuilder::with_callback(id, PathSegmentsBuilder {
callback: self.callback,
span: self.span,
global: self.global,
segments: Vec::new(),
segments: segments,
})
}
}
Expand All @@ -122,7 +127,6 @@ impl<F> PathBuilder<F>
pub struct PathSegmentsBuilder<F=Identity> {
callback: F,
span: Span,
global: bool,
segments: Vec<ast::PathSegment>,
}

Expand Down Expand Up @@ -156,7 +160,6 @@ impl<F> PathSegmentsBuilder<F>
pub fn build(self) -> F::Result {
self.callback.invoke(ast::Path {
span: self.span,
global: self.global,
segments: self.segments,
})
}
Expand Down Expand Up @@ -285,29 +288,39 @@ impl<F> PathSegmentBuilder<F>
}

pub fn build_return(self, output: Option<P<ast::Ty>>) -> F::Result {
let data = ast::ParenthesizedParameterData {
span: self.span,
inputs: self.tys,
output: output,
let parameters = if self.tys.is_empty() {
None
} else {
let data = ast::ParenthesizedParameterData {
span: self.span,
inputs: self.tys,
output: output,
};

Some(P(ast::PathParameters::Parenthesized(data)))
};

let parameters = ast::PathParameters::Parenthesized(data);

self.callback.invoke(ast::PathSegment {
identifier: self.id,
parameters: parameters,
})
}

pub fn build(self) -> F::Result {
let data = ast::AngleBracketedParameterData {
lifetimes: self.lifetimes,
types: P::from_vec(self.tys),
bindings: P::from_vec(self.bindings),
let parameters = if self.lifetimes.is_empty() &&
self.tys.is_empty() &&
self.bindings.is_empty() {
None
} else {
let data = ast::AngleBracketedParameterData {
lifetimes: self.lifetimes,
types: P::from_vec(self.tys),
bindings: P::from_vec(self.bindings),
};

Some(P(ast::PathParameters::AngleBracketed(data)))
};

let parameters = ast::PathParameters::AngleBracketed(data);

self.callback.invoke(ast::PathSegment {
identifier: self.id,
parameters: parameters,
Expand Down
2 changes: 0 additions & 2 deletions src/qpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ impl<F> QPathTyBuilder<F>
{
let path = ast::Path {
span: self.builder.span,
global: false,
segments: vec![],
};
self.as_().build(path).id(id)
Expand All @@ -103,7 +102,6 @@ impl<F> QPathTyBuilder<F>
{
let path = ast::Path {
span: self.builder.span,
global: false,
segments: vec![],
};
self.as_().build(path).segment(id)
Expand Down
39 changes: 17 additions & 22 deletions tests/test_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ fn test_id() {
path,
ast::Path {
span: DUMMY_SP,
global: false,
segments: vec![
ast::PathSegment {
identifier: builder.id("isize"),
parameters: ast::PathParameters::none(),
parameters: None,
},
]
}
Expand All @@ -35,11 +34,10 @@ fn test_single_segment() {
path,
ast::Path {
span: DUMMY_SP,
global: false,
segments: vec![
ast::PathSegment {
identifier: builder.id("isize"),
parameters: ast::PathParameters::none(),
parameters: None,
},
]
}
Expand All @@ -59,19 +57,19 @@ fn test_multiple_segments() {
path,
ast::Path {
span: DUMMY_SP,
global: true,
segments: vec![
ast::PathSegment::crate_root(),
ast::PathSegment {
identifier: builder.id("std"),
parameters: ast::PathParameters::none(),
parameters: None,
},
ast::PathSegment {
identifier: builder.id("thread"),
parameters: ast::PathParameters::none(),
parameters: None,
},
ast::PathSegment {
identifier: builder.id("Thread"),
parameters: ast::PathParameters::none(),
parameters: None,
},
]
}
Expand All @@ -93,25 +91,25 @@ fn test_option() {
path,
ast::Path {
span: DUMMY_SP,
global: true,
segments: vec![
ast::PathSegment::crate_root(),
ast::PathSegment {
identifier: builder.id("std"),
parameters: ast::PathParameters::none(),
parameters: None,
},
ast::PathSegment {
identifier: builder.id("option"),
parameters: ast::PathParameters::none(),
parameters: None,
},
ast::PathSegment {
identifier: builder.id("Option"),
parameters: ast::AngleBracketed(ast::AngleBracketedParameterData {
parameters: Some(P(ast::AngleBracketed(ast::AngleBracketedParameterData {
lifetimes: vec![],
types: P::from_vec(vec![
builder.ty().isize(),
]),
bindings: P::new(),
}),
}))),
},
]
}
Expand All @@ -131,17 +129,16 @@ fn test_lifetimes() {
path,
ast::Path {
span: DUMMY_SP,
global: false,
segments: vec![
ast::PathSegment {
identifier: builder.id("Foo"),
parameters: ast::AngleBracketed(ast::AngleBracketedParameterData {
parameters: Some(P(ast::AngleBracketed(ast::AngleBracketedParameterData {
lifetimes: vec![
builder.lifetime("'a"),
],
types: P::new(),
bindings: P::new(),
}),
}))),
},
]
}
Expand All @@ -157,17 +154,16 @@ fn test_parenthesized_no_return() {
path,
ast::Path {
span: DUMMY_SP,
global: false,
segments: vec![
ast::PathSegment {
identifier: builder.id("Fn"),
parameters: ast::PathParameters::Parenthesized(
parameters: Some(P(ast::PathParameters::Parenthesized(
ast::ParenthesizedParameterData {
span: DUMMY_SP,
inputs: vec![builder.ty().u8()],
output: None,
}
),
))),
},
]
}
Expand All @@ -183,17 +179,16 @@ fn test_parenthesized_with_return() {
path,
ast::Path {
span: DUMMY_SP,
global: false,
segments: vec![
ast::PathSegment {
identifier: builder.id("FnMut"),
parameters: ast::PathParameters::Parenthesized(
parameters: Some(P(ast::PathParameters::Parenthesized(
ast::ParenthesizedParameterData {
span: DUMMY_SP,
inputs: vec![builder.ty().u16()],
output: Some(builder.ty().u32()),
}
),
))),
},
]
}
Expand Down

0 comments on commit d59cae0

Please sign in to comment.