From 494859e8dde5080534e94aba6d98affb921552f8 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 8 Feb 2018 08:58:13 +0000 Subject: Consolidate PathParameters and AngleBracketedParameterData --- src/libsyntax/ast.rs | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'src/libsyntax/ast.rs') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 76fa463a631..1af4743cfe4 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -167,21 +167,47 @@ impl PathParameters { } } +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +pub enum GenericAngleBracketedParam { + Lifetime(Lifetime), + Type(P), +} + /// A path like `Foo<'a, T>` #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Default)] pub struct AngleBracketedParameterData { /// Overall span pub span: Span, - /// The lifetime parameters for this path segment. - pub lifetimes: Vec, - /// The type parameters for this path segment, if present. - pub types: Vec>, + /// The parameters for this path segment. + pub parameters: Vec, /// Bindings (equality constraints) on associated types, if present. /// /// E.g., `Foo`. pub bindings: Vec, } +impl AngleBracketedParameterData { + pub fn lifetimes(&self) -> Vec<&Lifetime> { + self.parameters.iter().filter_map(|p| { + if let GenericAngleBracketedParam::Lifetime(lt) = p { + Some(lt) + } else { + None + } + }).collect() + } + + pub fn types(&self) -> Vec<&P> { + self.parameters.iter().filter_map(|p| { + if let GenericAngleBracketedParam::Type(ty) = p { + Some(ty) + } else { + None + } + }).collect() + } +} + impl Into>> for AngleBracketedParameterData { fn into(self) -> Option> { Some(P(PathParameters::AngleBracketed(self))) -- cgit 1.4.1-3-g733a5