From ce3beb609f75fb690d6980c9e6a62c6efa6f3d97 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 23 Jul 2017 19:32:36 +0300 Subject: Discern between `Path` and `Path<>` in AST --- src/libsyntax/ast.rs | 14 ++++++-------- src/libsyntax/ext/build.rs | 20 ++++++++------------ 2 files changed, 14 insertions(+), 20 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b8e371a4e76..544afc5d6f6 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -120,12 +120,11 @@ pub struct PathSegment { pub span: Span, /// Type/lifetime parameters attached to this path. They come in - /// two flavors: `Path` and `Path(A,B) -> C`. Note that - /// this is more than just simple syntactic sugar; the use of - /// parens affects the region binding rules, so we preserve the - /// distinction. - /// The `Option>` wrapper is purely a size optimization; - /// `None` is used to represent both `Path` and `Path<>`. + /// two flavors: `Path` and `Path(A,B) -> C`. + /// `None` means that no parameter list is supplied (`Path`), + /// `Some` means that parameter list is supplied (`Path`) + /// but it can be empty (`Path<>`). + /// `P` is used as a size optimization for the common case with no parameters. pub parameters: Option>, } @@ -181,8 +180,7 @@ pub struct AngleBracketedParameterData { impl Into>> for AngleBracketedParameterData { fn into(self) -> Option> { - let empty = self.lifetimes.is_empty() && self.types.is_empty() && self.bindings.is_empty(); - if empty { None } else { Some(P(PathParameters::AngleBracketed(self))) } + Some(P(PathParameters::AngleBracketed(self))) } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index d8140417214..af9143eadbc 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -326,14 +326,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } segments.extend(idents.into_iter().map(|i| ast::PathSegment::from_ident(i, sp))); - let parameters = if lifetimes.is_empty() && types.is_empty() && bindings.is_empty() { - None + let parameters = if !lifetimes.is_empty() || !types.is_empty() || !bindings.is_empty() { + ast::AngleBracketedParameterData { lifetimes, types, bindings }.into() } else { - Some(P(ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData { - lifetimes: lifetimes, - types: types, - bindings: bindings, - }))) + None }; segments.push(ast::PathSegment { identifier: last_identifier, @@ -369,15 +365,15 @@ impl<'a> AstBuilder for ExtCtxt<'a> { bindings: Vec) -> (ast::QSelf, ast::Path) { let mut path = trait_path; - let parameters = ast::AngleBracketedParameterData { - lifetimes: lifetimes, - types: types, - bindings: bindings, + let parameters = if !lifetimes.is_empty() || !types.is_empty() || !bindings.is_empty() { + ast::AngleBracketedParameterData { lifetimes, types, bindings }.into() + } else { + None }; path.segments.push(ast::PathSegment { identifier: ident.node, span: ident.span, - parameters: Some(P(ast::PathParameters::AngleBracketed(parameters))), + parameters: parameters, }); (ast::QSelf { -- cgit 1.4.1-3-g733a5