rustfmt librustc_front
This commit is contained in:
parent
c2be91ede0
commit
869e9719fd
7 changed files with 1261 additions and 1117 deletions
File diff suppressed because it is too large
Load diff
|
@ -56,12 +56,15 @@ use serialize::{Encodable, Encoder, Decoder};
|
||||||
pub struct Lifetime {
|
pub struct Lifetime {
|
||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub name: Name
|
pub name: Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Lifetime {
|
impl fmt::Debug for Lifetime {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "lifetime({}: {})", self.id, pprust::lifetime_to_string(self))
|
write!(f,
|
||||||
|
"lifetime({}: {})",
|
||||||
|
self.id,
|
||||||
|
pprust::lifetime_to_string(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +72,7 @@ impl fmt::Debug for Lifetime {
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
pub struct LifetimeDef {
|
pub struct LifetimeDef {
|
||||||
pub lifetime: Lifetime,
|
pub lifetime: Lifetime,
|
||||||
pub bounds: Vec<Lifetime>
|
pub bounds: Vec<Lifetime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A "Path" is essentially Rust's notion of a name; for instance:
|
/// A "Path" is essentially Rust's notion of a name; for instance:
|
||||||
|
@ -161,7 +164,8 @@ impl PathParameters {
|
||||||
data.types.iter().collect()
|
data.types.iter().collect()
|
||||||
}
|
}
|
||||||
ParenthesizedParameters(ref data) => {
|
ParenthesizedParameters(ref data) => {
|
||||||
data.inputs.iter()
|
data.inputs
|
||||||
|
.iter()
|
||||||
.chain(data.output.iter())
|
.chain(data.output.iter())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -229,7 +233,7 @@ pub struct ParenthesizedParameterData {
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
pub enum TyParamBound {
|
pub enum TyParamBound {
|
||||||
TraitTyParamBound(PolyTraitRef, TraitBoundModifier),
|
TraitTyParamBound(PolyTraitRef, TraitBoundModifier),
|
||||||
RegionTyParamBound(Lifetime)
|
RegionTyParamBound(Lifetime),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A modifier on a bound, currently this is only used for `?Sized`, where the
|
/// A modifier on a bound, currently this is only used for `?Sized`, where the
|
||||||
|
@ -248,7 +252,7 @@ pub struct TyParam {
|
||||||
pub id: NodeId,
|
pub id: NodeId,
|
||||||
pub bounds: TyParamBounds,
|
pub bounds: TyParamBounds,
|
||||||
pub default: Option<P<Ty>>,
|
pub default: Option<P<Ty>>,
|
||||||
pub span: Span
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents lifetimes and type parameters attached to a declaration
|
/// Represents lifetimes and type parameters attached to a declaration
|
||||||
|
@ -287,7 +291,7 @@ pub enum WherePredicate {
|
||||||
/// A lifetime predicate, e.g. `'a: 'b+'c`
|
/// A lifetime predicate, e.g. `'a: 'b+'c`
|
||||||
RegionPredicate(WhereRegionPredicate),
|
RegionPredicate(WhereRegionPredicate),
|
||||||
/// An equality predicate (unsupported)
|
/// An equality predicate (unsupported)
|
||||||
EqPredicate(WhereEqPredicate)
|
EqPredicate(WhereEqPredicate),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A type bound, eg `for<'c> Foo: Send+Clone+'c`
|
/// A type bound, eg `for<'c> Foo: Send+Clone+'c`
|
||||||
|
@ -496,7 +500,7 @@ pub enum UnOp {
|
||||||
/// The `!` operator for logical inversion
|
/// The `!` operator for logical inversion
|
||||||
UnNot,
|
UnNot,
|
||||||
/// The `-` operator for negation
|
/// The `-` operator for negation
|
||||||
UnNeg
|
UnNeg,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A statement
|
/// A statement
|
||||||
|
@ -506,7 +510,8 @@ impl fmt::Debug for Stmt_ {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
// Sadness.
|
// Sadness.
|
||||||
let spanned = codemap::dummy_spanned(self.clone());
|
let spanned = codemap::dummy_spanned(self.clone());
|
||||||
write!(f, "stmt({}: {})",
|
write!(f,
|
||||||
|
"stmt({}: {})",
|
||||||
util::stmt_id(&spanned),
|
util::stmt_id(&spanned),
|
||||||
pprust::stmt_to_string(&spanned))
|
pprust::stmt_to_string(&spanned))
|
||||||
}
|
}
|
||||||
|
@ -709,13 +714,15 @@ pub enum Expr_ {
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
pub struct QSelf {
|
pub struct QSelf {
|
||||||
pub ty: P<Ty>,
|
pub ty: P<Ty>,
|
||||||
pub position: usize
|
pub position: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||||
pub enum MatchSource {
|
pub enum MatchSource {
|
||||||
Normal,
|
Normal,
|
||||||
IfLetDesugar { contains_else_clause: bool },
|
IfLetDesugar {
|
||||||
|
contains_else_clause: bool,
|
||||||
|
},
|
||||||
WhileLetDesugar,
|
WhileLetDesugar,
|
||||||
ForLoopDesugar,
|
ForLoopDesugar,
|
||||||
}
|
}
|
||||||
|
@ -815,7 +822,7 @@ pub enum PrimTy {
|
||||||
TyFloat(FloatTy),
|
TyFloat(FloatTy),
|
||||||
TyStr,
|
TyStr,
|
||||||
TyBool,
|
TyBool,
|
||||||
TyChar
|
TyChar,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
|
@ -823,7 +830,7 @@ pub struct BareFnTy {
|
||||||
pub unsafety: Unsafety,
|
pub unsafety: Unsafety,
|
||||||
pub abi: Abi,
|
pub abi: Abi,
|
||||||
pub lifetimes: Vec<LifetimeDef>,
|
pub lifetimes: Vec<LifetimeDef>,
|
||||||
pub decl: P<FnDecl>
|
pub decl: P<FnDecl>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
|
@ -839,7 +846,7 @@ pub enum Ty_ {
|
||||||
/// A bare function (e.g. `fn(usize) -> bool`)
|
/// A bare function (e.g. `fn(usize) -> bool`)
|
||||||
TyBareFn(P<BareFnTy>),
|
TyBareFn(P<BareFnTy>),
|
||||||
/// A tuple (`(A, B, C, D,...)`)
|
/// A tuple (`(A, B, C, D,...)`)
|
||||||
TyTup(Vec<P<Ty>> ),
|
TyTup(Vec<P<Ty>>),
|
||||||
/// A path (`module::module::...::Type`), optionally
|
/// A path (`module::module::...::Type`), optionally
|
||||||
/// "qualified", e.g. `<Vec<T> as SomeTrait>::SomeType`.
|
/// "qualified", e.g. `<Vec<T> as SomeTrait>::SomeType`.
|
||||||
///
|
///
|
||||||
|
@ -881,7 +888,10 @@ pub struct Arg {
|
||||||
|
|
||||||
impl Arg {
|
impl Arg {
|
||||||
pub fn new_self(span: Span, mutability: Mutability, self_ident: Ident) -> Arg {
|
pub fn new_self(span: Span, mutability: Mutability, self_ident: Ident) -> Arg {
|
||||||
let path = Spanned{span:span,node:self_ident};
|
let path = Spanned {
|
||||||
|
span: span,
|
||||||
|
node: self_ident,
|
||||||
|
};
|
||||||
Arg {
|
Arg {
|
||||||
// HACK(eddyb) fake type for the self argument.
|
// HACK(eddyb) fake type for the self argument.
|
||||||
ty: P(Ty {
|
ty: P(Ty {
|
||||||
|
@ -892,9 +902,9 @@ impl Arg {
|
||||||
pat: P(Pat {
|
pat: P(Pat {
|
||||||
id: DUMMY_NODE_ID,
|
id: DUMMY_NODE_ID,
|
||||||
node: PatIdent(BindByValue(mutability), path, None),
|
node: PatIdent(BindByValue(mutability), path, None),
|
||||||
span: span
|
span: span,
|
||||||
}),
|
}),
|
||||||
id: DUMMY_NODE_ID
|
id: DUMMY_NODE_ID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -904,7 +914,7 @@ impl Arg {
|
||||||
pub struct FnDecl {
|
pub struct FnDecl {
|
||||||
pub inputs: Vec<Arg>,
|
pub inputs: Vec<Arg>,
|
||||||
pub output: FunctionRetTy,
|
pub output: FunctionRetTy,
|
||||||
pub variadic: bool
|
pub variadic: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
|
@ -922,9 +932,10 @@ pub enum Constness {
|
||||||
impl fmt::Display for Unsafety {
|
impl fmt::Display for Unsafety {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fmt::Display::fmt(match *self {
|
fmt::Display::fmt(match *self {
|
||||||
Unsafety::Normal => "normal",
|
Unsafety::Normal => "normal",
|
||||||
Unsafety::Unsafe => "unsafe",
|
Unsafety::Unsafe => "unsafe",
|
||||||
}, f)
|
},
|
||||||
|
f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -966,7 +977,7 @@ impl FunctionRetTy {
|
||||||
match *self {
|
match *self {
|
||||||
NoReturn(span) => span,
|
NoReturn(span) => span,
|
||||||
DefaultReturn(span) => span,
|
DefaultReturn(span) => span,
|
||||||
Return(ref ty) => ty.span
|
Return(ref ty) => ty.span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1038,19 +1049,19 @@ pub enum PathListItem_ {
|
||||||
name: Name,
|
name: Name,
|
||||||
/// renamed in list, eg `use foo::{bar as baz};`
|
/// renamed in list, eg `use foo::{bar as baz};`
|
||||||
rename: Option<Name>,
|
rename: Option<Name>,
|
||||||
id: NodeId
|
id: NodeId,
|
||||||
},
|
},
|
||||||
PathListMod {
|
PathListMod {
|
||||||
/// renamed in list, eg `use foo::{self as baz};`
|
/// renamed in list, eg `use foo::{self as baz};`
|
||||||
rename: Option<Name>,
|
rename: Option<Name>,
|
||||||
id: NodeId
|
id: NodeId,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PathListItem_ {
|
impl PathListItem_ {
|
||||||
pub fn id(&self) -> NodeId {
|
pub fn id(&self) -> NodeId {
|
||||||
match *self {
|
match *self {
|
||||||
PathListIdent { id, .. } | PathListMod { id, .. } => id
|
PathListIdent { id, .. } | PathListMod { id, .. } => id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1063,7 +1074,7 @@ impl PathListItem_ {
|
||||||
|
|
||||||
pub fn rename(&self) -> Option<Name> {
|
pub fn rename(&self) -> Option<Name> {
|
||||||
match *self {
|
match *self {
|
||||||
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename
|
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1086,7 +1097,7 @@ pub enum ViewPath_ {
|
||||||
ViewPathGlob(Path),
|
ViewPathGlob(Path),
|
||||||
|
|
||||||
/// `foo::bar::{a,b,c}`
|
/// `foo::bar::{a,b,c}`
|
||||||
ViewPathList(Path, Vec<PathListItem>)
|
ViewPathList(Path, Vec<PathListItem>),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TraitRef's appear in impls.
|
/// TraitRef's appear in impls.
|
||||||
|
@ -1122,7 +1133,7 @@ impl Visibility {
|
||||||
pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
|
pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
|
||||||
match self {
|
match self {
|
||||||
&Inherited => parent_visibility,
|
&Inherited => parent_visibility,
|
||||||
&Public => *self
|
&Public => *self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1139,7 +1150,7 @@ impl StructField_ {
|
||||||
pub fn name(&self) -> Option<Name> {
|
pub fn name(&self) -> Option<Name> {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
NamedField(name, _) => Some(name),
|
NamedField(name, _) => Some(name),
|
||||||
UnnamedField(_) => None
|
UnnamedField(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1214,10 +1225,7 @@ pub enum Item_ {
|
||||||
/// A struct definition, e.g. `struct Foo<A> {x: A}`
|
/// A struct definition, e.g. `struct Foo<A> {x: A}`
|
||||||
ItemStruct(P<StructDef>, Generics),
|
ItemStruct(P<StructDef>, Generics),
|
||||||
/// Represents a Trait Declaration
|
/// Represents a Trait Declaration
|
||||||
ItemTrait(Unsafety,
|
ItemTrait(Unsafety, Generics, TyParamBounds, Vec<P<TraitItem>>),
|
||||||
Generics,
|
|
||||||
TyParamBounds,
|
|
||||||
Vec<P<TraitItem>>),
|
|
||||||
|
|
||||||
// Default trait implementations
|
// Default trait implementations
|
||||||
///
|
///
|
||||||
|
@ -1247,7 +1255,7 @@ impl Item_ {
|
||||||
ItemStruct(..) => "struct",
|
ItemStruct(..) => "struct",
|
||||||
ItemTrait(..) => "trait",
|
ItemTrait(..) => "trait",
|
||||||
ItemImpl(..) |
|
ItemImpl(..) |
|
||||||
ItemDefaultImpl(..) => "item"
|
ItemDefaultImpl(..) => "item",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1276,7 +1284,7 @@ impl ForeignItem_ {
|
||||||
pub fn descriptive_variant(&self) -> &str {
|
pub fn descriptive_variant(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
ForeignItemFn(..) => "foreign function",
|
ForeignItemFn(..) => "foreign function",
|
||||||
ForeignItemStatic(..) => "foreign static item"
|
ForeignItemStatic(..) => "foreign static item",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,13 @@
|
||||||
#![feature(filling_drop)]
|
#![feature(filling_drop)]
|
||||||
|
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use]
|
||||||
#[macro_use] extern crate syntax;
|
extern crate log;
|
||||||
#[macro_use] #[no_link] extern crate rustc_bitflags;
|
#[macro_use]
|
||||||
|
extern crate syntax;
|
||||||
|
#[macro_use]
|
||||||
|
#[no_link]
|
||||||
|
extern crate rustc_bitflags;
|
||||||
|
|
||||||
extern crate serialize as rustc_serialize; // used by deriving
|
extern crate serialize as rustc_serialize; // used by deriving
|
||||||
|
|
||||||
|
|
|
@ -29,24 +29,26 @@ pub fn lower_view_path(view_path: &ViewPath) -> P<hir::ViewPath> {
|
||||||
}
|
}
|
||||||
ViewPathList(ref path, ref path_list_idents) => {
|
ViewPathList(ref path, ref path_list_idents) => {
|
||||||
hir::ViewPathList(lower_path(path),
|
hir::ViewPathList(lower_path(path),
|
||||||
path_list_idents.iter().map(|path_list_ident| {
|
path_list_idents.iter()
|
||||||
Spanned {
|
.map(|path_list_ident| {
|
||||||
node: match path_list_ident.node {
|
Spanned {
|
||||||
PathListIdent { id, name, rename } =>
|
node: match path_list_ident.node {
|
||||||
hir::PathListIdent {
|
PathListIdent { id, name, rename } =>
|
||||||
id: id,
|
hir::PathListIdent {
|
||||||
name: name.name,
|
id: id,
|
||||||
rename: rename.map(|x| x.name),
|
name: name.name,
|
||||||
},
|
rename: rename.map(|x| x.name),
|
||||||
PathListMod { id, rename } =>
|
},
|
||||||
hir::PathListMod {
|
PathListMod { id, rename } =>
|
||||||
id: id,
|
hir::PathListMod {
|
||||||
rename: rename.map(|x| x.name)
|
id: id,
|
||||||
}
|
rename: rename.map(|x| x.name),
|
||||||
},
|
},
|
||||||
span: path_list_ident.span
|
},
|
||||||
}
|
span: path_list_ident.span,
|
||||||
}).collect())
|
}
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
span: view_path.span,
|
span: view_path.span,
|
||||||
|
@ -66,17 +68,22 @@ pub fn lower_decl(d: &Decl) -> P<hir::Decl> {
|
||||||
match d.node {
|
match d.node {
|
||||||
DeclLocal(ref l) => P(Spanned {
|
DeclLocal(ref l) => P(Spanned {
|
||||||
node: hir::DeclLocal(lower_local(l)),
|
node: hir::DeclLocal(lower_local(l)),
|
||||||
span: d.span
|
span: d.span,
|
||||||
}),
|
}),
|
||||||
DeclItem(ref it) => P(Spanned {
|
DeclItem(ref it) => P(Spanned {
|
||||||
node: hir::DeclItem(lower_item(it)),
|
node: hir::DeclItem(lower_item(it)),
|
||||||
span: d.span
|
span: d.span,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_ty_binding(b: &TypeBinding) -> P<hir::TypeBinding> {
|
pub fn lower_ty_binding(b: &TypeBinding) -> P<hir::TypeBinding> {
|
||||||
P(hir::TypeBinding { id: b.id, name: b.ident.name, ty: lower_ty(&b.ty), span: b.span })
|
P(hir::TypeBinding {
|
||||||
|
id: b.id,
|
||||||
|
name: b.ident.name,
|
||||||
|
ty: lower_ty(&b.ty),
|
||||||
|
span: b.span,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_ty(t: &Ty) -> P<hir::Ty> {
|
pub fn lower_ty(t: &Ty) -> P<hir::Ty> {
|
||||||
|
@ -94,7 +101,7 @@ pub fn lower_ty(t: &Ty) -> P<hir::Ty> {
|
||||||
lifetimes: lower_lifetime_defs(&f.lifetimes),
|
lifetimes: lower_lifetime_defs(&f.lifetimes),
|
||||||
unsafety: lower_unsafety(f.unsafety),
|
unsafety: lower_unsafety(f.unsafety),
|
||||||
abi: f.abi,
|
abi: f.abi,
|
||||||
decl: lower_fn_decl(&f.decl)
|
decl: lower_fn_decl(&f.decl),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
TyTup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(ty)).collect()),
|
TyTup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(ty)).collect()),
|
||||||
|
@ -103,14 +110,13 @@ pub fn lower_ty(t: &Ty) -> P<hir::Ty> {
|
||||||
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
|
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
|
||||||
hir::QSelf {
|
hir::QSelf {
|
||||||
ty: lower_ty(ty),
|
ty: lower_ty(ty),
|
||||||
position: position
|
position: position,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
hir::TyPath(qself, lower_path(path))
|
hir::TyPath(qself, lower_path(path))
|
||||||
}
|
}
|
||||||
TyObjectSum(ref ty, ref bounds) => {
|
TyObjectSum(ref ty, ref bounds) => {
|
||||||
hir::TyObjectSum(lower_ty(ty),
|
hir::TyObjectSum(lower_ty(ty), lower_bounds(bounds))
|
||||||
lower_bounds(bounds))
|
|
||||||
}
|
}
|
||||||
TyFixedLengthVec(ref ty, ref e) => {
|
TyFixedLengthVec(ref ty, ref e) => {
|
||||||
hir::TyFixedLengthVec(lower_ty(ty), lower_expr(e))
|
hir::TyFixedLengthVec(lower_ty(ty), lower_expr(e))
|
||||||
|
@ -142,8 +148,9 @@ pub fn lower_variant(v: &Variant) -> P<hir::Variant> {
|
||||||
attrs: v.node.attrs.clone(),
|
attrs: v.node.attrs.clone(),
|
||||||
kind: match v.node.kind {
|
kind: match v.node.kind {
|
||||||
TupleVariantKind(ref variant_args) => {
|
TupleVariantKind(ref variant_args) => {
|
||||||
hir::TupleVariantKind(variant_args.iter().map(|ref x|
|
hir::TupleVariantKind(variant_args.iter()
|
||||||
lower_variant_arg(x)).collect())
|
.map(|ref x| lower_variant_arg(x))
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
StructVariantKind(ref struct_def) => {
|
StructVariantKind(ref struct_def) => {
|
||||||
hir::StructVariantKind(lower_struct_def(struct_def))
|
hir::StructVariantKind(lower_struct_def(struct_def))
|
||||||
|
@ -158,11 +165,15 @@ pub fn lower_variant(v: &Variant) -> P<hir::Variant> {
|
||||||
pub fn lower_path(p: &Path) -> hir::Path {
|
pub fn lower_path(p: &Path) -> hir::Path {
|
||||||
hir::Path {
|
hir::Path {
|
||||||
global: p.global,
|
global: p.global,
|
||||||
segments: p.segments.iter().map(|&PathSegment {identifier, ref parameters}|
|
segments: p.segments
|
||||||
hir::PathSegment {
|
.iter()
|
||||||
identifier: identifier,
|
.map(|&PathSegment { identifier, ref parameters }| {
|
||||||
parameters: lower_path_parameters(parameters),
|
hir::PathSegment {
|
||||||
}).collect(),
|
identifier: identifier,
|
||||||
|
parameters: lower_path_parameters(parameters),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
span: p.span,
|
span: p.span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,12 +209,12 @@ pub fn lower_parenthesized_parameter_data(data: &ParenthesizedParameterData)
|
||||||
|
|
||||||
pub fn lower_local(l: &Local) -> P<hir::Local> {
|
pub fn lower_local(l: &Local) -> P<hir::Local> {
|
||||||
P(hir::Local {
|
P(hir::Local {
|
||||||
id: l.id,
|
id: l.id,
|
||||||
ty: l.ty.as_ref().map(|t| lower_ty(t)),
|
ty: l.ty.as_ref().map(|t| lower_ty(t)),
|
||||||
pat: lower_pat(&l.pat),
|
pat: lower_pat(&l.pat),
|
||||||
init: l.init.as_ref().map(|e| lower_expr(e)),
|
init: l.init.as_ref().map(|e| lower_expr(e)),
|
||||||
span: l.span,
|
span: l.span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_explicit_self_underscore(es: &ExplicitSelf_) -> hir::ExplicitSelf_ {
|
pub fn lower_explicit_self_underscore(es: &ExplicitSelf_) -> hir::ExplicitSelf_ {
|
||||||
|
@ -211,7 +222,9 @@ pub fn lower_explicit_self_underscore(es: &ExplicitSelf_) -> hir::ExplicitSelf_
|
||||||
SelfStatic => hir::SelfStatic,
|
SelfStatic => hir::SelfStatic,
|
||||||
SelfValue(v) => hir::SelfValue(v.name),
|
SelfValue(v) => hir::SelfValue(v.name),
|
||||||
SelfRegion(ref lifetime, m, ident) => {
|
SelfRegion(ref lifetime, m, ident) => {
|
||||||
hir::SelfRegion(lower_opt_lifetime(lifetime), lower_mutability(m), ident.name)
|
hir::SelfRegion(lower_opt_lifetime(lifetime),
|
||||||
|
lower_mutability(m),
|
||||||
|
ident.name)
|
||||||
}
|
}
|
||||||
SelfExplicit(ref typ, ident) => {
|
SelfExplicit(ref typ, ident) => {
|
||||||
hir::SelfExplicit(lower_ty(typ), ident.name)
|
hir::SelfExplicit(lower_ty(typ), ident.name)
|
||||||
|
@ -227,11 +240,18 @@ pub fn lower_mutability(m: Mutability) -> hir::Mutability {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_explicit_self(s: &ExplicitSelf) -> hir::ExplicitSelf {
|
pub fn lower_explicit_self(s: &ExplicitSelf) -> hir::ExplicitSelf {
|
||||||
Spanned { node: lower_explicit_self_underscore(&s.node), span: s.span }
|
Spanned {
|
||||||
|
node: lower_explicit_self_underscore(&s.node),
|
||||||
|
span: s.span,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_arg(arg: &Arg) -> hir::Arg {
|
pub fn lower_arg(arg: &Arg) -> hir::Arg {
|
||||||
hir::Arg { id: arg.id, pat: lower_pat(&arg.pat), ty: lower_ty(&arg.ty) }
|
hir::Arg {
|
||||||
|
id: arg.id,
|
||||||
|
pat: lower_pat(&arg.pat),
|
||||||
|
ty: lower_ty(&arg.ty),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_fn_decl(decl: &FnDecl) -> P<hir::FnDecl> {
|
pub fn lower_fn_decl(decl: &FnDecl) -> P<hir::FnDecl> {
|
||||||
|
@ -240,7 +260,7 @@ pub fn lower_fn_decl(decl: &FnDecl) -> P<hir::FnDecl> {
|
||||||
output: match decl.output {
|
output: match decl.output {
|
||||||
Return(ref ty) => hir::Return(lower_ty(ty)),
|
Return(ref ty) => hir::Return(lower_ty(ty)),
|
||||||
DefaultReturn(span) => hir::DefaultReturn(span),
|
DefaultReturn(span) => hir::DefaultReturn(span),
|
||||||
NoReturn(span) => hir::NoReturn(span)
|
NoReturn(span) => hir::NoReturn(span),
|
||||||
},
|
},
|
||||||
variadic: decl.variadic,
|
variadic: decl.variadic,
|
||||||
})
|
})
|
||||||
|
@ -249,7 +269,8 @@ pub fn lower_fn_decl(decl: &FnDecl) -> P<hir::FnDecl> {
|
||||||
pub fn lower_ty_param_bound(tpb: &TyParamBound) -> hir::TyParamBound {
|
pub fn lower_ty_param_bound(tpb: &TyParamBound) -> hir::TyParamBound {
|
||||||
match *tpb {
|
match *tpb {
|
||||||
TraitTyParamBound(ref ty, modifier) => {
|
TraitTyParamBound(ref ty, modifier) => {
|
||||||
hir::TraitTyParamBound(lower_poly_trait_ref(ty), lower_trait_bound_modifier(modifier))
|
hir::TraitTyParamBound(lower_poly_trait_ref(ty),
|
||||||
|
lower_trait_bound_modifier(modifier))
|
||||||
}
|
}
|
||||||
RegionTyParamBound(ref lifetime) => hir::RegionTyParamBound(lower_lifetime(lifetime)),
|
RegionTyParamBound(ref lifetime) => hir::RegionTyParamBound(lower_lifetime(lifetime)),
|
||||||
}
|
}
|
||||||
|
@ -270,11 +291,18 @@ pub fn lower_ty_params(tps: &OwnedSlice<TyParam>) -> OwnedSlice<hir::TyParam> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_lifetime(l: &Lifetime) -> hir::Lifetime {
|
pub fn lower_lifetime(l: &Lifetime) -> hir::Lifetime {
|
||||||
hir::Lifetime { id: l.id, name: l.name, span: l.span }
|
hir::Lifetime {
|
||||||
|
id: l.id,
|
||||||
|
name: l.name,
|
||||||
|
span: l.span,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_lifetime_def(l: &LifetimeDef) -> hir::LifetimeDef {
|
pub fn lower_lifetime_def(l: &LifetimeDef) -> hir::LifetimeDef {
|
||||||
hir::LifetimeDef { lifetime: lower_lifetime(&l.lifetime), bounds: lower_lifetimes(&l.bounds) }
|
hir::LifetimeDef {
|
||||||
|
lifetime: lower_lifetime(&l.lifetime),
|
||||||
|
bounds: lower_lifetimes(&l.bounds),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_lifetimes(lts: &Vec<Lifetime>) -> Vec<hir::Lifetime> {
|
pub fn lower_lifetimes(lts: &Vec<Lifetime>) -> Vec<hir::Lifetime> {
|
||||||
|
@ -300,8 +328,10 @@ pub fn lower_generics(g: &Generics) -> hir::Generics {
|
||||||
pub fn lower_where_clause(wc: &WhereClause) -> hir::WhereClause {
|
pub fn lower_where_clause(wc: &WhereClause) -> hir::WhereClause {
|
||||||
hir::WhereClause {
|
hir::WhereClause {
|
||||||
id: wc.id,
|
id: wc.id,
|
||||||
predicates: wc.predicates.iter().map(|predicate|
|
predicates: wc.predicates
|
||||||
lower_where_predicate(predicate)).collect(),
|
.iter()
|
||||||
|
.map(|predicate| lower_where_predicate(predicate))
|
||||||
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +345,7 @@ pub fn lower_where_predicate(pred: &WherePredicate) -> hir::WherePredicate {
|
||||||
bound_lifetimes: lower_lifetime_defs(bound_lifetimes),
|
bound_lifetimes: lower_lifetime_defs(bound_lifetimes),
|
||||||
bounded_ty: lower_ty(bounded_ty),
|
bounded_ty: lower_ty(bounded_ty),
|
||||||
bounds: bounds.iter().map(|x| lower_ty_param_bound(x)).collect(),
|
bounds: bounds.iter().map(|x| lower_ty_param_bound(x)).collect(),
|
||||||
span: span
|
span: span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
WherePredicate::RegionPredicate(WhereRegionPredicate{ ref lifetime,
|
WherePredicate::RegionPredicate(WhereRegionPredicate{ ref lifetime,
|
||||||
|
@ -324,18 +354,18 @@ pub fn lower_where_predicate(pred: &WherePredicate) -> hir::WherePredicate {
|
||||||
hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
||||||
span: span,
|
span: span,
|
||||||
lifetime: lower_lifetime(lifetime),
|
lifetime: lower_lifetime(lifetime),
|
||||||
bounds: bounds.iter().map(|bound| lower_lifetime(bound)).collect()
|
bounds: bounds.iter().map(|bound| lower_lifetime(bound)).collect(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
WherePredicate::EqPredicate(WhereEqPredicate{ id,
|
WherePredicate::EqPredicate(WhereEqPredicate{ id,
|
||||||
ref path,
|
ref path,
|
||||||
ref ty,
|
ref ty,
|
||||||
span}) => {
|
span}) => {
|
||||||
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate{
|
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
|
||||||
id: id,
|
id: id,
|
||||||
path: lower_path(path),
|
path: lower_path(path),
|
||||||
ty:lower_ty(ty),
|
ty: lower_ty(ty),
|
||||||
span: span
|
span: span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,7 +379,10 @@ pub fn lower_struct_def(sd: &StructDef) -> P<hir::StructDef> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_trait_ref(p: &TraitRef) -> hir::TraitRef {
|
pub fn lower_trait_ref(p: &TraitRef) -> hir::TraitRef {
|
||||||
hir::TraitRef { path: lower_path(&p.path), ref_id: p.ref_id }
|
hir::TraitRef {
|
||||||
|
path: lower_path(&p.path),
|
||||||
|
ref_id: p.ref_id,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_poly_trait_ref(p: &PolyTraitRef) -> hir::PolyTraitRef {
|
pub fn lower_poly_trait_ref(p: &PolyTraitRef) -> hir::PolyTraitRef {
|
||||||
|
@ -375,12 +408,16 @@ pub fn lower_struct_field(f: &StructField) -> hir::StructField {
|
||||||
pub fn lower_field(f: &Field) -> hir::Field {
|
pub fn lower_field(f: &Field) -> hir::Field {
|
||||||
hir::Field {
|
hir::Field {
|
||||||
name: respan(f.ident.span, f.ident.node.name),
|
name: respan(f.ident.span, f.ident.node.name),
|
||||||
expr: lower_expr(&f.expr), span: f.span
|
expr: lower_expr(&f.expr),
|
||||||
|
span: f.span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_mt(mt: &MutTy) -> hir::MutTy {
|
pub fn lower_mt(mt: &MutTy) -> hir::MutTy {
|
||||||
hir::MutTy { ty: lower_ty(&mt.ty), mutbl: lower_mutability(mt.mutbl) }
|
hir::MutTy {
|
||||||
|
ty: lower_ty(&mt.ty),
|
||||||
|
mutbl: lower_mutability(mt.mutbl),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_opt_bounds(b: &Option<OwnedSlice<TyParamBound>>)
|
pub fn lower_opt_bounds(b: &Option<OwnedSlice<TyParamBound>>)
|
||||||
|
@ -393,7 +430,10 @@ fn lower_bounds(bounds: &TyParamBounds) -> hir::TyParamBounds {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_variant_arg(va: &VariantArg) -> hir::VariantArg {
|
fn lower_variant_arg(va: &VariantArg) -> hir::VariantArg {
|
||||||
hir::VariantArg { id: va.id, ty: lower_ty(&va.ty) }
|
hir::VariantArg {
|
||||||
|
id: va.id,
|
||||||
|
ty: lower_ty(&va.ty),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_block(b: &Block) -> P<hir::Block> {
|
pub fn lower_block(b: &Block) -> P<hir::Block> {
|
||||||
|
@ -419,14 +459,12 @@ pub fn lower_item_underscore(i: &Item_) -> hir::Item_ {
|
||||||
hir::ItemConst(lower_ty(t), lower_expr(e))
|
hir::ItemConst(lower_ty(t), lower_expr(e))
|
||||||
}
|
}
|
||||||
ItemFn(ref decl, unsafety, constness, abi, ref generics, ref body) => {
|
ItemFn(ref decl, unsafety, constness, abi, ref generics, ref body) => {
|
||||||
hir::ItemFn(
|
hir::ItemFn(lower_fn_decl(decl),
|
||||||
lower_fn_decl(decl),
|
lower_unsafety(unsafety),
|
||||||
lower_unsafety(unsafety),
|
lower_constness(constness),
|
||||||
lower_constness(constness),
|
abi,
|
||||||
abi,
|
lower_generics(generics),
|
||||||
lower_generics(generics),
|
lower_block(body))
|
||||||
lower_block(body)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
ItemMod(ref m) => hir::ItemMod(lower_mod(m)),
|
ItemMod(ref m) => hir::ItemMod(lower_mod(m)),
|
||||||
ItemForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(nm)),
|
ItemForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(nm)),
|
||||||
|
@ -434,11 +472,13 @@ pub fn lower_item_underscore(i: &Item_) -> hir::Item_ {
|
||||||
hir::ItemTy(lower_ty(t), lower_generics(generics))
|
hir::ItemTy(lower_ty(t), lower_generics(generics))
|
||||||
}
|
}
|
||||||
ItemEnum(ref enum_definition, ref generics) => {
|
ItemEnum(ref enum_definition, ref generics) => {
|
||||||
hir::ItemEnum(
|
hir::ItemEnum(hir::EnumDef {
|
||||||
hir::EnumDef {
|
variants: enum_definition.variants
|
||||||
variants: enum_definition.variants.iter().map(|x| lower_variant(x)).collect(),
|
.iter()
|
||||||
},
|
.map(|x| lower_variant(x))
|
||||||
lower_generics(generics))
|
.collect(),
|
||||||
|
},
|
||||||
|
lower_generics(generics))
|
||||||
}
|
}
|
||||||
ItemStruct(ref struct_def, ref generics) => {
|
ItemStruct(ref struct_def, ref generics) => {
|
||||||
let struct_def = lower_struct_def(struct_def);
|
let struct_def = lower_struct_def(struct_def);
|
||||||
|
@ -471,10 +511,10 @@ pub fn lower_item_underscore(i: &Item_) -> hir::Item_ {
|
||||||
|
|
||||||
pub fn lower_trait_item(i: &TraitItem) -> P<hir::TraitItem> {
|
pub fn lower_trait_item(i: &TraitItem) -> P<hir::TraitItem> {
|
||||||
P(hir::TraitItem {
|
P(hir::TraitItem {
|
||||||
id: i.id,
|
id: i.id,
|
||||||
name: i.ident.name,
|
name: i.ident.name,
|
||||||
attrs: i.attrs.clone(),
|
attrs: i.attrs.clone(),
|
||||||
node: match i.node {
|
node: match i.node {
|
||||||
ConstTraitItem(ref ty, ref default) => {
|
ConstTraitItem(ref ty, ref default) => {
|
||||||
hir::ConstTraitItem(lower_ty(ty),
|
hir::ConstTraitItem(lower_ty(ty),
|
||||||
default.as_ref().map(|x| lower_expr(x)))
|
default.as_ref().map(|x| lower_expr(x)))
|
||||||
|
@ -488,33 +528,35 @@ pub fn lower_trait_item(i: &TraitItem) -> P<hir::TraitItem> {
|
||||||
default.as_ref().map(|x| lower_ty(x)))
|
default.as_ref().map(|x| lower_ty(x)))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
span: i.span,
|
span: i.span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_impl_item(i: &ImplItem) -> P<hir::ImplItem> {
|
pub fn lower_impl_item(i: &ImplItem) -> P<hir::ImplItem> {
|
||||||
P(hir::ImplItem {
|
P(hir::ImplItem {
|
||||||
id: i.id,
|
id: i.id,
|
||||||
name: i.ident.name,
|
name: i.ident.name,
|
||||||
attrs: i.attrs.clone(),
|
attrs: i.attrs.clone(),
|
||||||
vis: lower_visibility(i.vis),
|
vis: lower_visibility(i.vis),
|
||||||
node: match i.node {
|
node: match i.node {
|
||||||
ConstImplItem(ref ty, ref expr) => {
|
ConstImplItem(ref ty, ref expr) => {
|
||||||
hir::ConstImplItem(lower_ty(ty), lower_expr(expr))
|
hir::ConstImplItem(lower_ty(ty), lower_expr(expr))
|
||||||
}
|
}
|
||||||
MethodImplItem(ref sig, ref body) => {
|
MethodImplItem(ref sig, ref body) => {
|
||||||
hir::MethodImplItem(lower_method_sig(sig),
|
hir::MethodImplItem(lower_method_sig(sig), lower_block(body))
|
||||||
lower_block(body))
|
|
||||||
}
|
}
|
||||||
TypeImplItem(ref ty) => hir::TypeImplItem(lower_ty(ty)),
|
TypeImplItem(ref ty) => hir::TypeImplItem(lower_ty(ty)),
|
||||||
MacImplItem(..) => panic!("Shouldn't exist any more"),
|
MacImplItem(..) => panic!("Shouldn't exist any more"),
|
||||||
},
|
},
|
||||||
span: i.span,
|
span: i.span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_mod(m: &Mod) -> hir::Mod {
|
pub fn lower_mod(m: &Mod) -> hir::Mod {
|
||||||
hir::Mod { inner: m.inner, items: m.items.iter().map(|x| lower_item(x)).collect() }
|
hir::Mod {
|
||||||
|
inner: m.inner,
|
||||||
|
items: m.items.iter().map(|x| lower_item(x)).collect(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_crate(c: &Crate) -> hir::Crate {
|
pub fn lower_crate(c: &Crate) -> hir::Crate {
|
||||||
|
@ -562,10 +604,10 @@ pub fn lower_item_simple(i: &Item) -> hir::Item {
|
||||||
|
|
||||||
pub fn lower_foreign_item(i: &ForeignItem) -> P<hir::ForeignItem> {
|
pub fn lower_foreign_item(i: &ForeignItem) -> P<hir::ForeignItem> {
|
||||||
P(hir::ForeignItem {
|
P(hir::ForeignItem {
|
||||||
id: i.id,
|
id: i.id,
|
||||||
name: i.ident.name,
|
name: i.ident.name,
|
||||||
attrs: i.attrs.clone(),
|
attrs: i.attrs.clone(),
|
||||||
node: match i.node {
|
node: match i.node {
|
||||||
ForeignItemFn(ref fdec, ref generics) => {
|
ForeignItemFn(ref fdec, ref generics) => {
|
||||||
hir::ForeignItemFn(lower_fn_decl(fdec), lower_generics(generics))
|
hir::ForeignItemFn(lower_fn_decl(fdec), lower_generics(generics))
|
||||||
}
|
}
|
||||||
|
@ -573,9 +615,9 @@ pub fn lower_foreign_item(i: &ForeignItem) -> P<hir::ForeignItem> {
|
||||||
hir::ForeignItemStatic(lower_ty(t), m)
|
hir::ForeignItemStatic(lower_ty(t), m)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
vis: lower_visibility(i.vis),
|
vis: lower_visibility(i.vis),
|
||||||
span: i.span,
|
span: i.span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_method_sig(sig: &MethodSig) -> hir::MethodSig {
|
pub fn lower_method_sig(sig: &MethodSig) -> hir::MethodSig {
|
||||||
|
@ -639,18 +681,18 @@ pub fn lower_binop(b: BinOp) -> hir::BinOp {
|
||||||
|
|
||||||
pub fn lower_pat(p: &Pat) -> P<hir::Pat> {
|
pub fn lower_pat(p: &Pat) -> P<hir::Pat> {
|
||||||
P(hir::Pat {
|
P(hir::Pat {
|
||||||
id: p.id,
|
id: p.id,
|
||||||
node: match p.node {
|
node: match p.node {
|
||||||
PatWild(k) => hir::PatWild(lower_pat_wild_kind(k)),
|
PatWild(k) => hir::PatWild(lower_pat_wild_kind(k)),
|
||||||
PatIdent(ref binding_mode, pth1, ref sub) => {
|
PatIdent(ref binding_mode, pth1, ref sub) => {
|
||||||
hir::PatIdent(lower_binding_mode(binding_mode),
|
hir::PatIdent(lower_binding_mode(binding_mode),
|
||||||
pth1,
|
pth1,
|
||||||
sub.as_ref().map(|x| lower_pat(x)))
|
sub.as_ref().map(|x| lower_pat(x)))
|
||||||
}
|
}
|
||||||
PatLit(ref e) => hir::PatLit(lower_expr(e)),
|
PatLit(ref e) => hir::PatLit(lower_expr(e)),
|
||||||
PatEnum(ref pth, ref pats) => {
|
PatEnum(ref pth, ref pats) => {
|
||||||
hir::PatEnum(lower_path(pth),
|
hir::PatEnum(lower_path(pth),
|
||||||
pats.as_ref().map(|pats| pats.iter().map(|x| lower_pat(x)).collect()))
|
pats.as_ref().map(|pats| pats.iter().map(|x| lower_pat(x)).collect()))
|
||||||
}
|
}
|
||||||
PatQPath(ref qself, ref pth) => {
|
PatQPath(ref qself, ref pth) => {
|
||||||
let qself = hir::QSelf {
|
let qself = hir::QSelf {
|
||||||
|
@ -661,130 +703,126 @@ pub fn lower_pat(p: &Pat) -> P<hir::Pat> {
|
||||||
}
|
}
|
||||||
PatStruct(ref pth, ref fields, etc) => {
|
PatStruct(ref pth, ref fields, etc) => {
|
||||||
let pth = lower_path(pth);
|
let pth = lower_path(pth);
|
||||||
let fs = fields.iter().map(|f| {
|
let fs = fields.iter()
|
||||||
Spanned { span: f.span,
|
.map(|f| {
|
||||||
node: hir::FieldPat {
|
Spanned {
|
||||||
name: f.node.ident.name,
|
span: f.span,
|
||||||
pat: lower_pat(&f.node.pat),
|
node: hir::FieldPat {
|
||||||
is_shorthand: f.node.is_shorthand,
|
name: f.node.ident.name,
|
||||||
}}
|
pat: lower_pat(&f.node.pat),
|
||||||
}).collect();
|
is_shorthand: f.node.is_shorthand,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
hir::PatStruct(pth, fs, etc)
|
hir::PatStruct(pth, fs, etc)
|
||||||
}
|
}
|
||||||
PatTup(ref elts) => hir::PatTup(elts.iter().map(|x| lower_pat(x)).collect()),
|
PatTup(ref elts) => hir::PatTup(elts.iter().map(|x| lower_pat(x)).collect()),
|
||||||
PatBox(ref inner) => hir::PatBox(lower_pat(inner)),
|
PatBox(ref inner) => hir::PatBox(lower_pat(inner)),
|
||||||
PatRegion(ref inner, mutbl) => hir::PatRegion(lower_pat(inner),
|
PatRegion(ref inner, mutbl) =>
|
||||||
lower_mutability(mutbl)),
|
hir::PatRegion(lower_pat(inner), lower_mutability(mutbl)),
|
||||||
PatRange(ref e1, ref e2) => {
|
PatRange(ref e1, ref e2) => {
|
||||||
hir::PatRange(lower_expr(e1), lower_expr(e2))
|
hir::PatRange(lower_expr(e1), lower_expr(e2))
|
||||||
},
|
}
|
||||||
PatVec(ref before, ref slice, ref after) => {
|
PatVec(ref before, ref slice, ref after) => {
|
||||||
hir::PatVec(before.iter().map(|x| lower_pat(x)).collect(),
|
hir::PatVec(before.iter().map(|x| lower_pat(x)).collect(),
|
||||||
slice.as_ref().map(|x| lower_pat(x)),
|
slice.as_ref().map(|x| lower_pat(x)),
|
||||||
after.iter().map(|x| lower_pat(x)).collect())
|
after.iter().map(|x| lower_pat(x)).collect())
|
||||||
}
|
}
|
||||||
PatMac(_) => panic!("Shouldn't exist here"),
|
PatMac(_) => panic!("Shouldn't exist here"),
|
||||||
},
|
},
|
||||||
span: p.span,
|
span: p.span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
|
pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
|
||||||
P(hir::Expr {
|
P(hir::Expr {
|
||||||
id: e.id,
|
id: e.id,
|
||||||
node: match e.node {
|
node: match e.node {
|
||||||
ExprBox(ref e) => {
|
ExprBox(ref e) => {
|
||||||
hir::ExprBox(lower_expr(e))
|
hir::ExprBox(lower_expr(e))
|
||||||
}
|
}
|
||||||
ExprVec(ref exprs) => {
|
ExprVec(ref exprs) => {
|
||||||
hir::ExprVec(exprs.iter().map(|x| lower_expr(x)).collect())
|
hir::ExprVec(exprs.iter().map(|x| lower_expr(x)).collect())
|
||||||
}
|
}
|
||||||
ExprRepeat(ref expr, ref count) => {
|
ExprRepeat(ref expr, ref count) => {
|
||||||
hir::ExprRepeat(lower_expr(expr), lower_expr(count))
|
hir::ExprRepeat(lower_expr(expr), lower_expr(count))
|
||||||
}
|
}
|
||||||
ExprTup(ref elts) => hir::ExprTup(elts.iter().map(|x| lower_expr(x)).collect()),
|
ExprTup(ref elts) => hir::ExprTup(elts.iter().map(|x| lower_expr(x)).collect()),
|
||||||
ExprCall(ref f, ref args) => {
|
ExprCall(ref f, ref args) => {
|
||||||
hir::ExprCall(lower_expr(f),
|
hir::ExprCall(lower_expr(f),
|
||||||
args.iter().map(|x| lower_expr(x)).collect())
|
args.iter().map(|x| lower_expr(x)).collect())
|
||||||
}
|
}
|
||||||
ExprMethodCall(i, ref tps, ref args) => {
|
ExprMethodCall(i, ref tps, ref args) => {
|
||||||
hir::ExprMethodCall(
|
hir::ExprMethodCall(respan(i.span, i.node.name),
|
||||||
respan(i.span, i.node.name),
|
tps.iter().map(|x| lower_ty(x)).collect(),
|
||||||
tps.iter().map(|x| lower_ty(x)).collect(),
|
args.iter().map(|x| lower_expr(x)).collect())
|
||||||
args.iter().map(|x| lower_expr(x)).collect())
|
}
|
||||||
}
|
ExprBinary(binop, ref lhs, ref rhs) => {
|
||||||
ExprBinary(binop, ref lhs, ref rhs) => {
|
hir::ExprBinary(lower_binop(binop), lower_expr(lhs), lower_expr(rhs))
|
||||||
hir::ExprBinary(lower_binop(binop),
|
}
|
||||||
lower_expr(lhs),
|
ExprUnary(op, ref ohs) => {
|
||||||
lower_expr(rhs))
|
hir::ExprUnary(lower_unop(op), lower_expr(ohs))
|
||||||
}
|
}
|
||||||
ExprUnary(op, ref ohs) => {
|
ExprLit(ref l) => hir::ExprLit(P((**l).clone())),
|
||||||
hir::ExprUnary(lower_unop(op), lower_expr(ohs))
|
ExprCast(ref expr, ref ty) => {
|
||||||
}
|
hir::ExprCast(lower_expr(expr), lower_ty(ty))
|
||||||
ExprLit(ref l) => hir::ExprLit(P((**l).clone())),
|
}
|
||||||
ExprCast(ref expr, ref ty) => {
|
ExprAddrOf(m, ref ohs) => hir::ExprAddrOf(lower_mutability(m), lower_expr(ohs)),
|
||||||
hir::ExprCast(lower_expr(expr), lower_ty(ty))
|
ExprIf(ref cond, ref tr, ref fl) => {
|
||||||
}
|
hir::ExprIf(lower_expr(cond),
|
||||||
ExprAddrOf(m, ref ohs) => hir::ExprAddrOf(lower_mutability(m), lower_expr(ohs)),
|
lower_block(tr),
|
||||||
ExprIf(ref cond, ref tr, ref fl) => {
|
fl.as_ref().map(|x| lower_expr(x)))
|
||||||
hir::ExprIf(lower_expr(cond),
|
}
|
||||||
lower_block(tr),
|
ExprWhile(ref cond, ref body, opt_ident) => {
|
||||||
fl.as_ref().map(|x| lower_expr(x)))
|
hir::ExprWhile(lower_expr(cond), lower_block(body), opt_ident)
|
||||||
}
|
}
|
||||||
ExprWhile(ref cond, ref body, opt_ident) => {
|
ExprLoop(ref body, opt_ident) => {
|
||||||
hir::ExprWhile(lower_expr(cond),
|
hir::ExprLoop(lower_block(body), opt_ident)
|
||||||
lower_block(body),
|
}
|
||||||
opt_ident)
|
ExprMatch(ref expr, ref arms, ref source) => {
|
||||||
}
|
hir::ExprMatch(lower_expr(expr),
|
||||||
ExprLoop(ref body, opt_ident) => {
|
arms.iter().map(|x| lower_arm(x)).collect(),
|
||||||
hir::ExprLoop(lower_block(body),
|
lower_match_source(source))
|
||||||
opt_ident)
|
}
|
||||||
}
|
ExprClosure(capture_clause, ref decl, ref body) => {
|
||||||
ExprMatch(ref expr, ref arms, ref source) => {
|
hir::ExprClosure(lower_capture_clause(capture_clause),
|
||||||
hir::ExprMatch(lower_expr(expr),
|
lower_fn_decl(decl),
|
||||||
arms.iter().map(|x| lower_arm(x)).collect(),
|
lower_block(body))
|
||||||
lower_match_source(source))
|
}
|
||||||
}
|
ExprBlock(ref blk) => hir::ExprBlock(lower_block(blk)),
|
||||||
ExprClosure(capture_clause, ref decl, ref body) => {
|
ExprAssign(ref el, ref er) => {
|
||||||
hir::ExprClosure(lower_capture_clause(capture_clause),
|
hir::ExprAssign(lower_expr(el), lower_expr(er))
|
||||||
lower_fn_decl(decl),
|
}
|
||||||
lower_block(body))
|
ExprAssignOp(op, ref el, ref er) => {
|
||||||
}
|
hir::ExprAssignOp(lower_binop(op), lower_expr(el), lower_expr(er))
|
||||||
ExprBlock(ref blk) => hir::ExprBlock(lower_block(blk)),
|
}
|
||||||
ExprAssign(ref el, ref er) => {
|
ExprField(ref el, ident) => {
|
||||||
hir::ExprAssign(lower_expr(el), lower_expr(er))
|
hir::ExprField(lower_expr(el), respan(ident.span, ident.node.name))
|
||||||
}
|
}
|
||||||
ExprAssignOp(op, ref el, ref er) => {
|
ExprTupField(ref el, ident) => {
|
||||||
hir::ExprAssignOp(lower_binop(op),
|
hir::ExprTupField(lower_expr(el), ident)
|
||||||
lower_expr(el),
|
}
|
||||||
lower_expr(er))
|
ExprIndex(ref el, ref er) => {
|
||||||
}
|
hir::ExprIndex(lower_expr(el), lower_expr(er))
|
||||||
ExprField(ref el, ident) => {
|
}
|
||||||
hir::ExprField(lower_expr(el), respan(ident.span, ident.node.name))
|
ExprRange(ref e1, ref e2) => {
|
||||||
}
|
hir::ExprRange(e1.as_ref().map(|x| lower_expr(x)),
|
||||||
ExprTupField(ref el, ident) => {
|
e2.as_ref().map(|x| lower_expr(x)))
|
||||||
hir::ExprTupField(lower_expr(el), ident)
|
}
|
||||||
}
|
ExprPath(ref qself, ref path) => {
|
||||||
ExprIndex(ref el, ref er) => {
|
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
|
||||||
hir::ExprIndex(lower_expr(el), lower_expr(er))
|
hir::QSelf {
|
||||||
}
|
ty: lower_ty(ty),
|
||||||
ExprRange(ref e1, ref e2) => {
|
position: position,
|
||||||
hir::ExprRange(e1.as_ref().map(|x| lower_expr(x)),
|
}
|
||||||
e2.as_ref().map(|x| lower_expr(x)))
|
});
|
||||||
}
|
hir::ExprPath(qself, lower_path(path))
|
||||||
ExprPath(ref qself, ref path) => {
|
}
|
||||||
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
|
ExprBreak(opt_ident) => hir::ExprBreak(opt_ident),
|
||||||
hir::QSelf {
|
ExprAgain(opt_ident) => hir::ExprAgain(opt_ident),
|
||||||
ty: lower_ty(ty),
|
ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(x))),
|
||||||
position: position
|
ExprInlineAsm(InlineAsm {
|
||||||
}
|
|
||||||
});
|
|
||||||
hir::ExprPath(qself, lower_path(path))
|
|
||||||
}
|
|
||||||
ExprBreak(opt_ident) => hir::ExprBreak(opt_ident),
|
|
||||||
ExprAgain(opt_ident) => hir::ExprAgain(opt_ident),
|
|
||||||
ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(x))),
|
|
||||||
ExprInlineAsm(InlineAsm {
|
|
||||||
ref inputs,
|
ref inputs,
|
||||||
ref outputs,
|
ref outputs,
|
||||||
ref asm,
|
ref asm,
|
||||||
|
@ -795,36 +833,38 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
|
||||||
dialect,
|
dialect,
|
||||||
expn_id,
|
expn_id,
|
||||||
}) => hir::ExprInlineAsm(hir::InlineAsm {
|
}) => hir::ExprInlineAsm(hir::InlineAsm {
|
||||||
inputs: inputs.iter().map(|&(ref c, ref input)| {
|
inputs: inputs.iter()
|
||||||
(c.clone(), lower_expr(input))
|
.map(|&(ref c, ref input)| (c.clone(), lower_expr(input)))
|
||||||
}).collect(),
|
.collect(),
|
||||||
outputs: outputs.iter().map(|&(ref c, ref out, ref is_rw)| {
|
outputs: outputs.iter()
|
||||||
(c.clone(), lower_expr(out), *is_rw)
|
.map(|&(ref c, ref out, ref is_rw)| {
|
||||||
}).collect(),
|
(c.clone(), lower_expr(out), *is_rw)
|
||||||
asm: asm.clone(),
|
})
|
||||||
asm_str_style: asm_str_style,
|
.collect(),
|
||||||
clobbers: clobbers.clone(),
|
asm: asm.clone(),
|
||||||
volatile: volatile,
|
asm_str_style: asm_str_style,
|
||||||
alignstack: alignstack,
|
clobbers: clobbers.clone(),
|
||||||
dialect: dialect,
|
volatile: volatile,
|
||||||
expn_id: expn_id,
|
alignstack: alignstack,
|
||||||
}),
|
dialect: dialect,
|
||||||
ExprStruct(ref path, ref fields, ref maybe_expr) => {
|
expn_id: expn_id,
|
||||||
hir::ExprStruct(lower_path(path),
|
}),
|
||||||
fields.iter().map(|x| lower_field(x)).collect(),
|
ExprStruct(ref path, ref fields, ref maybe_expr) => {
|
||||||
maybe_expr.as_ref().map(|x| lower_expr(x)))
|
hir::ExprStruct(lower_path(path),
|
||||||
},
|
fields.iter().map(|x| lower_field(x)).collect(),
|
||||||
ExprParen(ref ex) => {
|
maybe_expr.as_ref().map(|x| lower_expr(x)))
|
||||||
return lower_expr(ex);
|
}
|
||||||
}
|
ExprParen(ref ex) => {
|
||||||
ExprInPlace(..) |
|
return lower_expr(ex);
|
||||||
ExprIfLet(..) |
|
}
|
||||||
ExprWhileLet(..) |
|
ExprInPlace(..) |
|
||||||
ExprForLoop(..) |
|
ExprIfLet(..) |
|
||||||
ExprMac(_) => panic!("Shouldn't exist here"),
|
ExprWhileLet(..) |
|
||||||
},
|
ExprForLoop(..) |
|
||||||
span: e.span,
|
ExprMac(_) => panic!("Shouldn't exist here"),
|
||||||
})
|
},
|
||||||
|
span: e.span,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_stmt(s: &Stmt) -> P<hir::Stmt> {
|
pub fn lower_stmt(s: &Stmt) -> P<hir::Stmt> {
|
||||||
|
@ -832,22 +872,22 @@ pub fn lower_stmt(s: &Stmt) -> P<hir::Stmt> {
|
||||||
StmtDecl(ref d, id) => {
|
StmtDecl(ref d, id) => {
|
||||||
P(Spanned {
|
P(Spanned {
|
||||||
node: hir::StmtDecl(lower_decl(d), id),
|
node: hir::StmtDecl(lower_decl(d), id),
|
||||||
span: s.span
|
span: s.span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
StmtExpr(ref e, id) => {
|
StmtExpr(ref e, id) => {
|
||||||
P(Spanned {
|
P(Spanned {
|
||||||
node: hir::StmtExpr(lower_expr(e), id),
|
node: hir::StmtExpr(lower_expr(e), id),
|
||||||
span: s.span
|
span: s.span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
StmtSemi(ref e, id) => {
|
StmtSemi(ref e, id) => {
|
||||||
P(Spanned {
|
P(Spanned {
|
||||||
node: hir::StmtSemi(lower_expr(e), id),
|
node: hir::StmtSemi(lower_expr(e), id),
|
||||||
span: s.span
|
span: s.span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
StmtMac(..) => panic!("Shouldn't exist here")
|
StmtMac(..) => panic!("Shouldn't exist here"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -17,9 +17,13 @@ use syntax::codemap::Span;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::owned_slice::OwnedSlice;
|
use syntax::owned_slice::OwnedSlice;
|
||||||
|
|
||||||
pub fn walk_pat<F>(pat: &Pat, mut it: F) -> bool where F: FnMut(&Pat) -> bool {
|
pub fn walk_pat<F>(pat: &Pat, mut it: F) -> bool
|
||||||
|
where F: FnMut(&Pat) -> bool
|
||||||
|
{
|
||||||
// FIXME(#19596) this is a workaround, but there should be a better way
|
// FIXME(#19596) this is a workaround, but there should be a better way
|
||||||
fn walk_pat_<G>(pat: &Pat, it: &mut G) -> bool where G: FnMut(&Pat) -> bool {
|
fn walk_pat_<G>(pat: &Pat, it: &mut G) -> bool
|
||||||
|
where G: FnMut(&Pat) -> bool
|
||||||
|
{
|
||||||
if !(*it)(pat) {
|
if !(*it)(pat) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -40,8 +44,12 @@ pub fn walk_pat<F>(pat: &Pat, mut it: F) -> bool where F: FnMut(&Pat) -> bool {
|
||||||
slice.iter().all(|p| walk_pat_(&**p, it)) &&
|
slice.iter().all(|p| walk_pat_(&**p, it)) &&
|
||||||
after.iter().all(|p| walk_pat_(&**p, it))
|
after.iter().all(|p| walk_pat_(&**p, it))
|
||||||
}
|
}
|
||||||
PatWild(_) | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) |
|
PatWild(_) |
|
||||||
PatEnum(_, _) | PatQPath(_, _) => {
|
PatLit(_) |
|
||||||
|
PatRange(_, _) |
|
||||||
|
PatIdent(_, _, _) |
|
||||||
|
PatEnum(_, _) |
|
||||||
|
PatQPath(_, _) => {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +77,7 @@ pub fn binop_to_string(op: BinOp_) -> &'static str {
|
||||||
BiLe => "<=",
|
BiLe => "<=",
|
||||||
BiNe => "!=",
|
BiNe => "!=",
|
||||||
BiGe => ">=",
|
BiGe => ">=",
|
||||||
BiGt => ">"
|
BiGt => ">",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,35 +89,43 @@ pub fn struct_def_is_tuple_like(struct_def: &hir::StructDef) -> bool {
|
||||||
|
|
||||||
pub fn stmt_id(s: &Stmt) -> NodeId {
|
pub fn stmt_id(s: &Stmt) -> NodeId {
|
||||||
match s.node {
|
match s.node {
|
||||||
StmtDecl(_, id) => id,
|
StmtDecl(_, id) => id,
|
||||||
StmtExpr(_, id) => id,
|
StmtExpr(_, id) => id,
|
||||||
StmtSemi(_, id) => id,
|
StmtSemi(_, id) => id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lazy_binop(b: BinOp_) -> bool {
|
pub fn lazy_binop(b: BinOp_) -> bool {
|
||||||
match b {
|
match b {
|
||||||
BiAnd => true,
|
BiAnd => true,
|
||||||
BiOr => true,
|
BiOr => true,
|
||||||
_ => false
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_shift_binop(b: BinOp_) -> bool {
|
pub fn is_shift_binop(b: BinOp_) -> bool {
|
||||||
match b {
|
match b {
|
||||||
BiShl => true,
|
BiShl => true,
|
||||||
BiShr => true,
|
BiShr => true,
|
||||||
_ => false
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_comparison_binop(b: BinOp_) -> bool {
|
pub fn is_comparison_binop(b: BinOp_) -> bool {
|
||||||
match b {
|
match b {
|
||||||
BiEq | BiLt | BiLe | BiNe | BiGt | BiGe =>
|
BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true,
|
||||||
true,
|
BiAnd |
|
||||||
BiAnd | BiOr | BiAdd | BiSub | BiMul | BiDiv | BiRem |
|
BiOr |
|
||||||
BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr =>
|
BiAdd |
|
||||||
false,
|
BiSub |
|
||||||
|
BiMul |
|
||||||
|
BiDiv |
|
||||||
|
BiRem |
|
||||||
|
BiBitXor |
|
||||||
|
BiBitAnd |
|
||||||
|
BiBitOr |
|
||||||
|
BiShl |
|
||||||
|
BiShr => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +150,7 @@ pub fn unop_to_string(op: UnOp) -> &'static str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct IdVisitor<'a, O:'a> {
|
pub struct IdVisitor<'a, O: 'a> {
|
||||||
pub operation: &'a mut O,
|
pub operation: &'a mut O,
|
||||||
pub pass_through_items: bool,
|
pub pass_through_items: bool,
|
||||||
pub visited_outermost: bool,
|
pub visited_outermost: bool,
|
||||||
|
@ -152,10 +168,7 @@ impl<'a, O: ast_util::IdVisitingOperation> IdVisitor<'a, O> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'v, O: ast_util::IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
|
impl<'a, 'v, O: ast_util::IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
|
||||||
fn visit_mod(&mut self,
|
fn visit_mod(&mut self, module: &Mod, _: Span, node_id: NodeId) {
|
||||||
module: &Mod,
|
|
||||||
_: Span,
|
|
||||||
node_id: NodeId) {
|
|
||||||
self.operation.visit_id(node_id);
|
self.operation.visit_id(node_id);
|
||||||
visit::walk_mod(self, module)
|
visit::walk_mod(self, module)
|
||||||
}
|
}
|
||||||
|
@ -265,11 +278,7 @@ impl<'a, 'v, O: ast_util::IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O>
|
||||||
self.operation.visit_id(argument.id)
|
self.operation.visit_id(argument.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
visit::walk_fn(self,
|
visit::walk_fn(self, function_kind, function_declaration, block, span);
|
||||||
function_kind,
|
|
||||||
function_declaration,
|
|
||||||
block,
|
|
||||||
span);
|
|
||||||
|
|
||||||
if !self.pass_through_items {
|
if !self.pass_through_items {
|
||||||
if let FnKind::Method(..) = function_kind {
|
if let FnKind::Method(..) = function_kind {
|
||||||
|
@ -323,11 +332,8 @@ pub fn compute_id_range_for_fn_body(fk: FnKind,
|
||||||
body: &Block,
|
body: &Block,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
id: NodeId)
|
id: NodeId)
|
||||||
-> ast_util::IdRange
|
-> ast_util::IdRange {
|
||||||
{
|
let mut visitor = ast_util::IdRangeComputingVisitor { result: ast_util::IdRange::max() };
|
||||||
let mut visitor = ast_util::IdRangeComputingVisitor {
|
|
||||||
result: ast_util::IdRange::max()
|
|
||||||
};
|
|
||||||
let mut id_visitor = IdVisitor {
|
let mut id_visitor = IdVisitor {
|
||||||
operation: &mut visitor,
|
operation: &mut visitor,
|
||||||
pass_through_items: false,
|
pass_through_items: false,
|
||||||
|
@ -338,7 +344,10 @@ pub fn compute_id_range_for_fn_body(fk: FnKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_path(e: P<Expr>) -> bool {
|
pub fn is_path(e: P<Expr>) -> bool {
|
||||||
match e.node { ExprPath(..) => true, _ => false }
|
match e.node {
|
||||||
|
ExprPath(..) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn empty_generics() -> Generics {
|
pub fn empty_generics() -> Generics {
|
||||||
|
@ -348,7 +357,7 @@ pub fn empty_generics() -> Generics {
|
||||||
where_clause: WhereClause {
|
where_clause: WhereClause {
|
||||||
id: DUMMY_NODE_ID,
|
id: DUMMY_NODE_ID,
|
||||||
predicates: Vec::new(),
|
predicates: Vec::new(),
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,15 +367,13 @@ pub fn ident_to_path(s: Span, ident: Ident) -> Path {
|
||||||
hir::Path {
|
hir::Path {
|
||||||
span: s,
|
span: s,
|
||||||
global: false,
|
global: false,
|
||||||
segments: vec!(
|
segments: vec!(hir::PathSegment {
|
||||||
hir::PathSegment {
|
identifier: ident,
|
||||||
identifier: ident,
|
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
|
||||||
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
|
lifetimes: Vec::new(),
|
||||||
lifetimes: Vec::new(),
|
types: OwnedSlice::empty(),
|
||||||
types: OwnedSlice::empty(),
|
bindings: OwnedSlice::empty(),
|
||||||
bindings: OwnedSlice::empty(),
|
}),
|
||||||
})
|
}),
|
||||||
}
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,25 +56,56 @@ pub trait Visitor<'v> : Sized {
|
||||||
fn visit_ident(&mut self, span: Span, ident: Ident) {
|
fn visit_ident(&mut self, span: Span, ident: Ident) {
|
||||||
walk_ident(self, span, ident);
|
walk_ident(self, span, ident);
|
||||||
}
|
}
|
||||||
fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) { walk_mod(self, m) }
|
fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) {
|
||||||
fn visit_foreign_item(&mut self, i: &'v ForeignItem) { walk_foreign_item(self, i) }
|
walk_mod(self, m)
|
||||||
fn visit_item(&mut self, i: &'v Item) { walk_item(self, i) }
|
}
|
||||||
fn visit_local(&mut self, l: &'v Local) { walk_local(self, l) }
|
fn visit_foreign_item(&mut self, i: &'v ForeignItem) {
|
||||||
fn visit_block(&mut self, b: &'v Block) { walk_block(self, b) }
|
walk_foreign_item(self, i)
|
||||||
fn visit_stmt(&mut self, s: &'v Stmt) { walk_stmt(self, s) }
|
}
|
||||||
fn visit_arm(&mut self, a: &'v Arm) { walk_arm(self, a) }
|
fn visit_item(&mut self, i: &'v Item) {
|
||||||
fn visit_pat(&mut self, p: &'v Pat) { walk_pat(self, p) }
|
walk_item(self, i)
|
||||||
fn visit_decl(&mut self, d: &'v Decl) { walk_decl(self, d) }
|
}
|
||||||
fn visit_expr(&mut self, ex: &'v Expr) { walk_expr(self, ex) }
|
fn visit_local(&mut self, l: &'v Local) {
|
||||||
fn visit_expr_post(&mut self, _ex: &'v Expr) { }
|
walk_local(self, l)
|
||||||
fn visit_ty(&mut self, t: &'v Ty) { walk_ty(self, t) }
|
}
|
||||||
fn visit_generics(&mut self, g: &'v Generics) { walk_generics(self, g) }
|
fn visit_block(&mut self, b: &'v Block) {
|
||||||
|
walk_block(self, b)
|
||||||
|
}
|
||||||
|
fn visit_stmt(&mut self, s: &'v Stmt) {
|
||||||
|
walk_stmt(self, s)
|
||||||
|
}
|
||||||
|
fn visit_arm(&mut self, a: &'v Arm) {
|
||||||
|
walk_arm(self, a)
|
||||||
|
}
|
||||||
|
fn visit_pat(&mut self, p: &'v Pat) {
|
||||||
|
walk_pat(self, p)
|
||||||
|
}
|
||||||
|
fn visit_decl(&mut self, d: &'v Decl) {
|
||||||
|
walk_decl(self, d)
|
||||||
|
}
|
||||||
|
fn visit_expr(&mut self, ex: &'v Expr) {
|
||||||
|
walk_expr(self, ex)
|
||||||
|
}
|
||||||
|
fn visit_expr_post(&mut self, _ex: &'v Expr) {
|
||||||
|
}
|
||||||
|
fn visit_ty(&mut self, t: &'v Ty) {
|
||||||
|
walk_ty(self, t)
|
||||||
|
}
|
||||||
|
fn visit_generics(&mut self, g: &'v Generics) {
|
||||||
|
walk_generics(self, g)
|
||||||
|
}
|
||||||
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block, s: Span, _: NodeId) {
|
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block, s: Span, _: NodeId) {
|
||||||
walk_fn(self, fk, fd, b, s)
|
walk_fn(self, fk, fd, b, s)
|
||||||
}
|
}
|
||||||
fn visit_trait_item(&mut self, ti: &'v TraitItem) { walk_trait_item(self, ti) }
|
fn visit_trait_item(&mut self, ti: &'v TraitItem) {
|
||||||
fn visit_impl_item(&mut self, ii: &'v ImplItem) { walk_impl_item(self, ii) }
|
walk_trait_item(self, ti)
|
||||||
fn visit_trait_ref(&mut self, t: &'v TraitRef) { walk_trait_ref(self, t) }
|
}
|
||||||
|
fn visit_impl_item(&mut self, ii: &'v ImplItem) {
|
||||||
|
walk_impl_item(self, ii)
|
||||||
|
}
|
||||||
|
fn visit_trait_ref(&mut self, t: &'v TraitRef) {
|
||||||
|
walk_trait_ref(self, t)
|
||||||
|
}
|
||||||
fn visit_ty_param_bound(&mut self, bounds: &'v TyParamBound) {
|
fn visit_ty_param_bound(&mut self, bounds: &'v TyParamBound) {
|
||||||
walk_ty_param_bound(self, bounds)
|
walk_ty_param_bound(self, bounds)
|
||||||
}
|
}
|
||||||
|
@ -84,13 +115,16 @@ pub trait Visitor<'v> : Sized {
|
||||||
fn visit_struct_def(&mut self, s: &'v StructDef, _: Name, _: &'v Generics, _: NodeId) {
|
fn visit_struct_def(&mut self, s: &'v StructDef, _: Name, _: &'v Generics, _: NodeId) {
|
||||||
walk_struct_def(self, s)
|
walk_struct_def(self, s)
|
||||||
}
|
}
|
||||||
fn visit_struct_field(&mut self, s: &'v StructField) { walk_struct_field(self, s) }
|
fn visit_struct_field(&mut self, s: &'v StructField) {
|
||||||
fn visit_enum_def(&mut self, enum_definition: &'v EnumDef,
|
walk_struct_field(self, s)
|
||||||
generics: &'v Generics) {
|
}
|
||||||
|
fn visit_enum_def(&mut self, enum_definition: &'v EnumDef, generics: &'v Generics) {
|
||||||
walk_enum_def(self, enum_definition, generics)
|
walk_enum_def(self, enum_definition, generics)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics) { walk_variant(self, v, g) }
|
fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics) {
|
||||||
|
walk_variant(self, v, g)
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
|
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
|
||||||
walk_lifetime(self, lifetime)
|
walk_lifetime(self, lifetime)
|
||||||
|
@ -116,7 +150,8 @@ pub trait Visitor<'v> : Sized {
|
||||||
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding) {
|
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding) {
|
||||||
walk_assoc_type_binding(self, type_binding)
|
walk_assoc_type_binding(self, type_binding)
|
||||||
}
|
}
|
||||||
fn visit_attribute(&mut self, _attr: &'v Attribute) {}
|
fn visit_attribute(&mut self, _attr: &'v Attribute) {
|
||||||
|
}
|
||||||
fn visit_macro_def(&mut self, macro_def: &'v MacroDef) {
|
fn visit_macro_def(&mut self, macro_def: &'v MacroDef) {
|
||||||
walk_macro_def(self, macro_def)
|
walk_macro_def(self, macro_def)
|
||||||
}
|
}
|
||||||
|
@ -164,16 +199,14 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime
|
||||||
visitor.visit_name(lifetime.span, lifetime.name);
|
visitor.visit_name(lifetime.span, lifetime.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V,
|
pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V, lifetime_def: &'v LifetimeDef) {
|
||||||
lifetime_def: &'v LifetimeDef) {
|
|
||||||
visitor.visit_lifetime(&lifetime_def.lifetime);
|
visitor.visit_lifetime(&lifetime_def.lifetime);
|
||||||
walk_list!(visitor, visit_lifetime, &lifetime_def.bounds);
|
walk_list!(visitor, visit_lifetime, &lifetime_def.bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V,
|
pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V, explicit_self: &'v ExplicitSelf) {
|
||||||
explicit_self: &'v ExplicitSelf) {
|
|
||||||
match explicit_self.node {
|
match explicit_self.node {
|
||||||
SelfStatic => {},
|
SelfStatic => {}
|
||||||
SelfValue(name) => {
|
SelfValue(name) => {
|
||||||
visitor.visit_name(explicit_self.span, name)
|
visitor.visit_name(explicit_self.span, name)
|
||||||
}
|
}
|
||||||
|
@ -193,12 +226,13 @@ pub fn walk_poly_trait_ref<'v, V>(visitor: &mut V,
|
||||||
_modifier: &'v TraitBoundModifier)
|
_modifier: &'v TraitBoundModifier)
|
||||||
where V: Visitor<'v>
|
where V: Visitor<'v>
|
||||||
{
|
{
|
||||||
walk_list!(visitor, visit_lifetime_def, &trait_ref.bound_lifetimes);
|
walk_list!(visitor,
|
||||||
|
visit_lifetime_def,
|
||||||
|
&trait_ref.bound_lifetimes);
|
||||||
visitor.visit_trait_ref(&trait_ref.trait_ref);
|
visitor.visit_trait_ref(&trait_ref.trait_ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_trait_ref<'v,V>(visitor: &mut V,
|
pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)
|
||||||
trait_ref: &'v TraitRef)
|
|
||||||
where V: Visitor<'v>
|
where V: Visitor<'v>
|
||||||
{
|
{
|
||||||
visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
|
visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
|
||||||
|
@ -236,8 +270,12 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
|
||||||
visitor.visit_expr(expr);
|
visitor.visit_expr(expr);
|
||||||
}
|
}
|
||||||
ItemFn(ref declaration, unsafety, constness, abi, ref generics, ref body) => {
|
ItemFn(ref declaration, unsafety, constness, abi, ref generics, ref body) => {
|
||||||
visitor.visit_fn(FnKind::ItemFn(item.name, generics, unsafety,
|
visitor.visit_fn(FnKind::ItemFn(item.name,
|
||||||
constness, abi, item.vis),
|
generics,
|
||||||
|
unsafety,
|
||||||
|
constness,
|
||||||
|
abi,
|
||||||
|
item.vis),
|
||||||
declaration,
|
declaration,
|
||||||
body,
|
body,
|
||||||
item.span,
|
item.span,
|
||||||
|
@ -272,10 +310,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
|
||||||
}
|
}
|
||||||
ItemStruct(ref struct_definition, ref generics) => {
|
ItemStruct(ref struct_definition, ref generics) => {
|
||||||
visitor.visit_generics(generics);
|
visitor.visit_generics(generics);
|
||||||
visitor.visit_struct_def(struct_definition,
|
visitor.visit_struct_def(struct_definition, item.name, generics, item.id)
|
||||||
item.name,
|
|
||||||
generics,
|
|
||||||
item.id)
|
|
||||||
}
|
}
|
||||||
ItemTrait(_, ref generics, ref bounds, ref methods) => {
|
ItemTrait(_, ref generics, ref bounds, ref methods) => {
|
||||||
visitor.visit_generics(generics);
|
visitor.visit_generics(generics);
|
||||||
|
@ -333,7 +368,9 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
||||||
}
|
}
|
||||||
TyBareFn(ref function_declaration) => {
|
TyBareFn(ref function_declaration) => {
|
||||||
walk_fn_decl(visitor, &function_declaration.decl);
|
walk_fn_decl(visitor, &function_declaration.decl);
|
||||||
walk_list!(visitor, visit_lifetime_def, &function_declaration.lifetimes);
|
walk_list!(visitor,
|
||||||
|
visit_lifetime_def,
|
||||||
|
&function_declaration.lifetimes);
|
||||||
}
|
}
|
||||||
TyPath(ref maybe_qself, ref path) => {
|
TyPath(ref maybe_qself, ref path) => {
|
||||||
if let Some(ref qself) = *maybe_qself {
|
if let Some(ref qself) = *maybe_qself {
|
||||||
|
@ -365,7 +402,8 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V, prefix: &'v Path,
|
pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||||
|
prefix: &'v Path,
|
||||||
item: &'v PathListItem) {
|
item: &'v PathListItem) {
|
||||||
for segment in &prefix.segments {
|
for segment in &prefix.segments {
|
||||||
visitor.visit_path_segment(prefix.span, segment);
|
visitor.visit_path_segment(prefix.span, segment);
|
||||||
|
@ -448,8 +486,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V,
|
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem) {
|
||||||
foreign_item: &'v ForeignItem) {
|
|
||||||
visitor.visit_name(foreign_item.span, foreign_item.name);
|
visitor.visit_name(foreign_item.span, foreign_item.name);
|
||||||
|
|
||||||
match foreign_item.node {
|
match foreign_item.node {
|
||||||
|
@ -463,8 +500,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||||
walk_list!(visitor, visit_attribute, &foreign_item.attrs);
|
walk_list!(visitor, visit_attribute, &foreign_item.attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V,
|
pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v TyParamBound) {
|
||||||
bound: &'v TyParamBound) {
|
|
||||||
match *bound {
|
match *bound {
|
||||||
TraitTyParamBound(ref typ, ref modifier) => {
|
TraitTyParamBound(ref typ, ref modifier) => {
|
||||||
visitor.visit_poly_trait_ref(typ, modifier);
|
visitor.visit_poly_trait_ref(typ, modifier);
|
||||||
|
@ -530,8 +566,7 @@ pub fn walk_fn_decl_nopat<'v, V: Visitor<'v>>(visitor: &mut V, function_declarat
|
||||||
walk_fn_ret_ty(visitor, &function_declaration.output)
|
walk_fn_ret_ty(visitor, &function_declaration.output)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V,
|
pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'v>) {
|
||||||
function_kind: FnKind<'v>) {
|
|
||||||
match function_kind {
|
match function_kind {
|
||||||
FnKind::ItemFn(_, generics, _, _, _, _) => {
|
FnKind::ItemFn(_, generics, _, _, _, _) => {
|
||||||
visitor.visit_generics(generics);
|
visitor.visit_generics(generics);
|
||||||
|
@ -568,8 +603,11 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
|
||||||
walk_fn_decl(visitor, &sig.decl);
|
walk_fn_decl(visitor, &sig.decl);
|
||||||
}
|
}
|
||||||
MethodTraitItem(ref sig, Some(ref body)) => {
|
MethodTraitItem(ref sig, Some(ref body)) => {
|
||||||
visitor.visit_fn(FnKind::Method(trait_item.name, sig, None), &sig.decl,
|
visitor.visit_fn(FnKind::Method(trait_item.name, sig, None),
|
||||||
body, trait_item.span, trait_item.id);
|
&sig.decl,
|
||||||
|
body,
|
||||||
|
trait_item.span,
|
||||||
|
trait_item.id);
|
||||||
}
|
}
|
||||||
TypeTraitItem(ref bounds, ref default) => {
|
TypeTraitItem(ref bounds, ref default) => {
|
||||||
walk_list!(visitor, visit_ty_param_bound, bounds);
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
||||||
|
@ -587,8 +625,11 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
|
||||||
visitor.visit_expr(expr);
|
visitor.visit_expr(expr);
|
||||||
}
|
}
|
||||||
MethodImplItem(ref sig, ref body) => {
|
MethodImplItem(ref sig, ref body) => {
|
||||||
visitor.visit_fn(FnKind::Method(impl_item.name, sig, Some(impl_item.vis)), &sig.decl,
|
visitor.visit_fn(FnKind::Method(impl_item.name, sig, Some(impl_item.vis)),
|
||||||
body, impl_item.span, impl_item.id);
|
&sig.decl,
|
||||||
|
body,
|
||||||
|
impl_item.span,
|
||||||
|
impl_item.id);
|
||||||
}
|
}
|
||||||
TypeImplItem(ref ty) => {
|
TypeImplItem(ref ty) => {
|
||||||
visitor.visit_ty(ty);
|
visitor.visit_ty(ty);
|
||||||
|
@ -596,13 +637,11 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V,
|
pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v StructDef) {
|
||||||
struct_definition: &'v StructDef) {
|
|
||||||
walk_list!(visitor, visit_struct_field, &struct_definition.fields);
|
walk_list!(visitor, visit_struct_field, &struct_definition.fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V,
|
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField) {
|
||||||
struct_field: &'v StructField) {
|
|
||||||
walk_opt_name(visitor, struct_field.span, struct_field.node.name());
|
walk_opt_name(visitor, struct_field.span, struct_field.node.name());
|
||||||
visitor.visit_ty(&struct_field.node.ty);
|
visitor.visit_ty(&struct_field.node.ty);
|
||||||
walk_list!(visitor, visit_attribute, &struct_field.node.attrs);
|
walk_list!(visitor, visit_attribute, &struct_field.node.attrs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue