From d59cae0969a79d0ad1de569c7f9ca52c75f07e7b Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 2 Jan 2017 13:59:34 -0800 Subject: [PATCH] Sync with rustc 1.16.0-nightly (4ecc85beb 2016-12-28) Blocked on https://github.com/serde-rs/syntex/pull/108 landing. --- Cargo.toml | 4 ++-- src/path.rs | 45 +++++++++++++++++++++++++++++---------------- src/qpath.rs | 2 -- tests/test_path.rs | 39 +++++++++++++++++---------------------- 4 files changed, 48 insertions(+), 42 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f779da1b1..08f200448 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aster" -version = "0.36.0" +version = "0.37.0" authors = ["Erick Tryzelaar "] license = "MIT/Apache-2.0" description = "A libsyntax ast builder" @@ -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 } diff --git a/src/path.rs b/src/path.rs index 5e0b2cfae..ab7d5d56f 100644 --- a/src/path.rs +++ b/src/path.rs @@ -108,11 +108,16 @@ impl PathBuilder -> PathSegmentBuilder> 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, }) } } @@ -122,7 +127,6 @@ impl PathBuilder pub struct PathSegmentsBuilder { callback: F, span: Span, - global: bool, segments: Vec, } @@ -156,7 +160,6 @@ impl PathSegmentsBuilder pub fn build(self) -> F::Result { self.callback.invoke(ast::Path { span: self.span, - global: self.global, segments: self.segments, }) } @@ -285,14 +288,18 @@ impl PathSegmentBuilder } pub fn build_return(self, output: Option>) -> 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, @@ -300,14 +307,20 @@ impl PathSegmentBuilder } 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, diff --git a/src/qpath.rs b/src/qpath.rs index 46191b000..dcd1a1fe9 100644 --- a/src/qpath.rs +++ b/src/qpath.rs @@ -92,7 +92,6 @@ impl QPathTyBuilder { let path = ast::Path { span: self.builder.span, - global: false, segments: vec![], }; self.as_().build(path).id(id) @@ -103,7 +102,6 @@ impl QPathTyBuilder { let path = ast::Path { span: self.builder.span, - global: false, segments: vec![], }; self.as_().build(path).segment(id) diff --git a/tests/test_path.rs b/tests/test_path.rs index e0afe2426..bd59d2c53 100644 --- a/tests/test_path.rs +++ b/tests/test_path.rs @@ -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, }, ] } @@ -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, }, ] } @@ -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, }, ] } @@ -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(), - }), + }))), }, ] } @@ -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(), - }), + }))), }, ] } @@ -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, } - ), + ))), }, ] } @@ -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()), } - ), + ))), }, ] }