about summary refs log tree commit diff
path: root/src/libsyntax/ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsyntax/ast.rs')
-rw-r--r--src/libsyntax/ast.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index f7d9d532062..b8e371a4e76 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -153,6 +153,19 @@ pub enum PathParameters {
     Parenthesized(ParenthesizedParameterData),
 }
 
+impl PathParameters {
+    pub fn span(&self, fallback: Span) -> Span {
+        match *self {
+            AngleBracketed(ref data) => {
+                data.lifetimes.get(0).map(|x| x.span).or_else(||
+                data.types.get(0).map(|x| x.span)).or_else(||
+                data.bindings.get(0).map(|x| x.span)).unwrap_or(fallback)
+            }
+            Parenthesized(ref data) => data.span
+        }
+    }
+}
+
 /// A path like `Foo<'a, T>`
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Default)]
 pub struct AngleBracketedParameterData {
@@ -173,6 +186,12 @@ impl Into<Option<P<PathParameters>>> for AngleBracketedParameterData {
     }
 }
 
+impl Into<Option<P<PathParameters>>> for ParenthesizedParameterData {
+    fn into(self) -> Option<P<PathParameters>> {
+        Some(P(PathParameters::Parenthesized(self)))
+    }
+}
+
 /// A path like `Foo(A,B) -> C`
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
 pub struct ParenthesizedParameterData {