diff options
| author | varkor <github@varkor.com> | 2018-02-08 08:58:13 +0000 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2018-06-20 12:19:03 +0100 |
| commit | 494859e8dde5080534e94aba6d98affb921552f8 (patch) | |
| tree | 661fcf1caa265de43643abf07b854460d966b862 /src/libsyntax/ast.rs | |
| parent | cca43a7f977963ee497ca091fbdf3cea95abdf47 (diff) | |
| download | rust-494859e8dde5080534e94aba6d98affb921552f8.tar.gz rust-494859e8dde5080534e94aba6d98affb921552f8.zip | |
Consolidate PathParameters and AngleBracketedParameterData
Diffstat (limited to 'src/libsyntax/ast.rs')
| -rw-r--r-- | src/libsyntax/ast.rs | 34 |
1 files changed, 30 insertions, 4 deletions
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<Ty>), +} + /// 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<Lifetime>, - /// The type parameters for this path segment, if present. - pub types: Vec<P<Ty>>, + /// The parameters for this path segment. + pub parameters: Vec<GenericAngleBracketedParam>, /// Bindings (equality constraints) on associated types, if present. /// /// E.g., `Foo<A=Bar>`. pub bindings: Vec<TypeBinding>, } +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<Ty>> { + self.parameters.iter().filter_map(|p| { + if let GenericAngleBracketedParam::Type(ty) = p { + Some(ty) + } else { + None + } + }).collect() + } +} + impl Into<Option<P<PathParameters>>> for AngleBracketedParameterData { fn into(self) -> Option<P<PathParameters>> { Some(P(PathParameters::AngleBracketed(self))) |
