pub span: Span,
/// Type/lifetime parameters attached to this path. They come in
- /// two flavors: `Path<A,B,C>` 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<P<..>>` wrapper is purely a size optimization;
- /// `None` is used to represent both `Path` and `Path<>`.
+ /// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`.
+ /// `None` means that no parameter list is supplied (`Path`),
+ /// `Some` means that parameter list is supplied (`Path<X, Y>`)
+ /// but it can be empty (`Path<>`).
+ /// `P` is used as a size optimization for the common case with no parameters.
pub parameters: Option<P<PathParameters>>,
}
pub fn crate_root(span: Span) -> Self {
PathSegment {
identifier: Ident { ctxt: span.ctxt, ..keywords::CrateRoot.ident() },
- span: span,
+ span,
parameters: None,
}
}
Parenthesized(ParenthesizedParameterData),
}
+impl PathParameters {
+ pub fn span(&self) -> Span {
+ match *self {
+ AngleBracketed(ref data) => data.span,
+ Parenthesized(ref data) => data.span,
+ }
+ }
+}
+
/// 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.
impl Into<Option<P<PathParameters>>> for AngleBracketedParameterData {
fn into(self) -> Option<P<PathParameters>> {
- 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)))
+ }
+}
+
+impl Into<Option<P<PathParameters>>> for ParenthesizedParameterData {
+ fn into(self) -> Option<P<PathParameters>> {
+ Some(P(PathParameters::Parenthesized(self)))
}
}
where_clause: WhereClause {
id: DUMMY_NODE_ID,
predicates: Vec::new(),
+ span: DUMMY_SP,
},
span: DUMMY_SP,
}
pub struct WhereClause {
pub id: NodeId,
pub predicates: Vec<WherePredicate>,
+ pub span: Span,
}
/// A single predicate in a `where` clause
TupleStruct(Path, Vec<P<Pat>>, Option<usize>),
/// A possibly qualified path pattern.
- /// Unquailfied path patterns `A::B::C` can legally refer to variants, structs, constants
- /// or associated constants. Quailfied path patterns `<A>::B::C`/`<A as Trait>::B::C` can
+ /// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants
+ /// or associated constants. Qualified path patterns `<A>::B::C`/`<A as Trait>::B::C` can
/// only legally refer to associated constants.
Path(Option<QSelf>, Path),
};
self
}
+
+ pub fn is_item(&self) -> bool {
+ match self.node {
+ StmtKind::Local(_) => true,
+ _ => false,
+ }
+ }
}
impl fmt::Debug for Stmt {
/// The first field resolves to the function itself,
/// and the second field is the list of arguments
Call(P<Expr>, Vec<P<Expr>>),
- /// A method call (`x.foo::<Bar, Baz>(a, b, c, d)`)
+ /// A method call (`x.foo::<'static, Bar, Baz>(a, b, c, d)`)
///
- /// The `SpannedIdent` is the identifier for the method name.
- /// The vector of `Ty`s are the ascripted type parameters for the method
+ /// The `PathSegment` represents the method name and its generic arguments
/// (within the angle brackets).
- ///
/// The first element of the vector of `Expr`s is the expression that evaluates
/// to the object on which the method is being called on (the receiver),
/// and the remaining elements are the rest of the arguments.
- ///
/// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as
- /// `ExprKind::MethodCall(foo, [Bar, Baz], [x, a, b, c, d])`.
- MethodCall(SpannedIdent, Vec<P<Ty>>, Vec<P<Expr>>),
+ /// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, [x, a, b, c, d])`.
+ MethodCall(PathSegment, Vec<P<Expr>>),
/// A tuple (`(a, b, c ,d)`)
Tup(Vec<P<Expr>>),
/// A binary operation (For example: `a + b`, `a * b`)
pub attrs: Vec<Attribute>,
pub node: TraitItemKind,
pub span: Span,
+ /// See `Item::tokens` for what this is
+ pub tokens: Option<TokenStream>,
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub attrs: Vec<Attribute>,
pub node: ImplItemKind,
pub span: Span,
+ /// See `Item::tokens` for what this is
+ pub tokens: Option<TokenStream>,
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
let infer_ty = P(Ty {
id: DUMMY_NODE_ID,
node: TyKind::ImplicitSelf,
- span: span,
+ span,
});
let arg = |mutbl, ty| Arg {
pat: P(Pat {
id: DUMMY_NODE_ID,
node: PatKind::Ident(BindingMode::ByValue(mutbl), eself_ident, None),
- span: span,
+ span,
}),
- ty: ty,
+ ty,
id: DUMMY_NODE_ID,
};
match eself.node {
SelfKind::Region(lt, mutbl) => arg(Mutability::Immutable, P(Ty {
id: DUMMY_NODE_ID,
node: TyKind::Rptr(lt, MutTy { ty: infer_ty, mutbl: mutbl }),
- span: span,
+ span,
})),
}
}
PolyTraitRef {
bound_lifetimes: lifetimes,
trait_ref: TraitRef { path: path, ref_id: DUMMY_NODE_ID },
- span: span,
+ span,
}
}
}
pub node: ItemKind,
pub vis: Visibility,
pub span: Span,
+
+ /// Original tokens this item was parsed from. This isn't necessarily
+ /// available for all items, although over time more and more items should
+ /// have this be `Some`. Right now this is primarily used for procedural
+ /// macros, notably custom attributes.
+ ///
+ /// Note that the tokens here do not include the outer attributes, but will
+ /// include inner attributes.
+ pub tokens: Option<TokenStream>,
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum ItemKind {
- /// An`extern crate` item, with optional original crate name.
+ /// An `extern crate` item, with optional original crate name.
///
/// E.g. `extern crate foo` or `extern crate foo_bar as foo`
ExternCrate(Option<Name>),