Skip to content

Commit da77a1a

Browse files
committed
Simplify parsing of paths
1 parent 5cc1baa commit da77a1a

File tree

6 files changed

+152
-255
lines changed

6 files changed

+152
-255
lines changed

src/libsyntax/ast.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ pub enum PathParameters {
153153
Parenthesized(ParenthesizedParameterData),
154154
}
155155

156+
impl PathParameters {
157+
pub fn span(&self, fallback: Span) -> Span {
158+
match *self {
159+
AngleBracketed(ref data) => {
160+
data.lifetimes.get(0).map(|x| x.span).or_else(||
161+
data.types.get(0).map(|x| x.span)).or_else(||
162+
data.bindings.get(0).map(|x| x.span)).unwrap_or(fallback)
163+
}
164+
Parenthesized(ref data) => data.span
165+
}
166+
}
167+
}
168+
156169
/// A path like `Foo<'a, T>`
157170
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Default)]
158171
pub struct AngleBracketedParameterData {
@@ -173,6 +186,12 @@ impl Into<Option<P<PathParameters>>> for AngleBracketedParameterData {
173186
}
174187
}
175188

189+
impl Into<Option<P<PathParameters>>> for ParenthesizedParameterData {
190+
fn into(self) -> Option<P<PathParameters>> {
191+
Some(P(PathParameters::Parenthesized(self)))
192+
}
193+
}
194+
176195
/// A path like `Foo(A,B) -> C`
177196
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
178197
pub struct ParenthesizedParameterData {

0 commit comments

Comments
 (0)