rustfmt librustc_front

This commit is contained in:
Nick Cameron 2015-09-28 08:23:31 +13:00
parent c2be91ede0
commit 869e9719fd
7 changed files with 1261 additions and 1117 deletions

File diff suppressed because it is too large Load Diff

View File

@ -56,12 +56,15 @@ use serialize::{Encodable, Encoder, Decoder};
pub struct Lifetime {
pub id: NodeId,
pub span: Span,
pub name: Name
pub name: Name,
}
impl fmt::Debug for Lifetime {
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)]
pub struct LifetimeDef {
pub lifetime: Lifetime,
pub bounds: Vec<Lifetime>
pub bounds: Vec<Lifetime>,
}
/// A "Path" is essentially Rust's notion of a name; for instance:
@ -161,7 +164,8 @@ impl PathParameters {
data.types.iter().collect()
}
ParenthesizedParameters(ref data) => {
data.inputs.iter()
data.inputs
.iter()
.chain(data.output.iter())
.collect()
}
@ -229,7 +233,7 @@ pub struct ParenthesizedParameterData {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum TyParamBound {
TraitTyParamBound(PolyTraitRef, TraitBoundModifier),
RegionTyParamBound(Lifetime)
RegionTyParamBound(Lifetime),
}
/// 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 bounds: TyParamBounds,
pub default: Option<P<Ty>>,
pub span: Span
pub span: Span,
}
/// Represents lifetimes and type parameters attached to a declaration
@ -287,7 +291,7 @@ pub enum WherePredicate {
/// A lifetime predicate, e.g. `'a: 'b+'c`
RegionPredicate(WhereRegionPredicate),
/// An equality predicate (unsupported)
EqPredicate(WhereEqPredicate)
EqPredicate(WhereEqPredicate),
}
/// A type bound, eg `for<'c> Foo: Send+Clone+'c`
@ -496,7 +500,7 @@ pub enum UnOp {
/// The `!` operator for logical inversion
UnNot,
/// The `-` operator for negation
UnNeg
UnNeg,
}
/// A statement
@ -506,7 +510,8 @@ impl fmt::Debug for Stmt_ {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Sadness.
let spanned = codemap::dummy_spanned(self.clone());
write!(f, "stmt({}: {})",
write!(f,
"stmt({}: {})",
util::stmt_id(&spanned),
pprust::stmt_to_string(&spanned))
}
@ -709,13 +714,15 @@ pub enum Expr_ {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct QSelf {
pub ty: P<Ty>,
pub position: usize
pub position: usize,
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum MatchSource {
Normal,
IfLetDesugar { contains_else_clause: bool },
IfLetDesugar {
contains_else_clause: bool,
},
WhileLetDesugar,
ForLoopDesugar,
}
@ -815,7 +822,7 @@ pub enum PrimTy {
TyFloat(FloatTy),
TyStr,
TyBool,
TyChar
TyChar,
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
@ -823,7 +830,7 @@ pub struct BareFnTy {
pub unsafety: Unsafety,
pub abi: Abi,
pub lifetimes: Vec<LifetimeDef>,
pub decl: P<FnDecl>
pub decl: P<FnDecl>,
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
@ -839,7 +846,7 @@ pub enum Ty_ {
/// A bare function (e.g. `fn(usize) -> bool`)
TyBareFn(P<BareFnTy>),
/// A tuple (`(A, B, C, D,...)`)
TyTup(Vec<P<Ty>> ),
TyTup(Vec<P<Ty>>),
/// A path (`module::module::...::Type`), optionally
/// "qualified", e.g. `<Vec<T> as SomeTrait>::SomeType`.
///
@ -881,7 +888,10 @@ pub struct Arg {
impl 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 {
// HACK(eddyb) fake type for the self argument.
ty: P(Ty {
@ -892,9 +902,9 @@ impl Arg {
pat: P(Pat {
id: DUMMY_NODE_ID,
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 inputs: Vec<Arg>,
pub output: FunctionRetTy,
pub variadic: bool
pub variadic: bool,
}
#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
@ -922,9 +932,10 @@ pub enum Constness {
impl fmt::Display for Unsafety {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(match *self {
Unsafety::Normal => "normal",
Unsafety::Unsafe => "unsafe",
}, f)
Unsafety::Normal => "normal",
Unsafety::Unsafe => "unsafe",
},
f)
}
}
@ -966,7 +977,7 @@ impl FunctionRetTy {
match *self {
NoReturn(span) => span,
DefaultReturn(span) => span,
Return(ref ty) => ty.span
Return(ref ty) => ty.span,
}
}
}
@ -1038,19 +1049,19 @@ pub enum PathListItem_ {
name: Name,
/// renamed in list, eg `use foo::{bar as baz};`
rename: Option<Name>,
id: NodeId
id: NodeId,
},
PathListMod {
/// renamed in list, eg `use foo::{self as baz};`
rename: Option<Name>,
id: NodeId
}
id: NodeId,
},
}
impl PathListItem_ {
pub fn id(&self) -> NodeId {
match *self {
PathListIdent { id, .. } | PathListMod { id, .. } => id
PathListIdent { id, .. } | PathListMod { id, .. } => id,
}
}
@ -1063,7 +1074,7 @@ impl PathListItem_ {
pub fn rename(&self) -> Option<Name> {
match *self {
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename,
}
}
}
@ -1086,7 +1097,7 @@ pub enum ViewPath_ {
ViewPathGlob(Path),
/// `foo::bar::{a,b,c}`
ViewPathList(Path, Vec<PathListItem>)
ViewPathList(Path, Vec<PathListItem>),
}
/// TraitRef's appear in impls.
@ -1122,7 +1133,7 @@ impl Visibility {
pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
match self {
&Inherited => parent_visibility,
&Public => *self
&Public => *self,
}
}
}
@ -1139,7 +1150,7 @@ impl StructField_ {
pub fn name(&self) -> Option<Name> {
match self.kind {
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}`
ItemStruct(P<StructDef>, Generics),
/// Represents a Trait Declaration
ItemTrait(Unsafety,
Generics,
TyParamBounds,
Vec<P<TraitItem>>),
ItemTrait(Unsafety, Generics, TyParamBounds, Vec<P<TraitItem>>),
// Default trait implementations
///
@ -1247,7 +1255,7 @@ impl Item_ {
ItemStruct(..) => "struct",
ItemTrait(..) => "trait",
ItemImpl(..) |
ItemDefaultImpl(..) => "item"
ItemDefaultImpl(..) => "item",
}
}
}
@ -1276,7 +1284,7 @@ impl ForeignItem_ {
pub fn descriptive_variant(&self) -> &str {
match *self {
ForeignItemFn(..) => "foreign function",
ForeignItemStatic(..) => "foreign static item"
ForeignItemStatic(..) => "foreign static item",
}
}
}

View File

@ -38,9 +38,13 @@
#![feature(filling_drop)]
extern crate serialize;
#[macro_use] extern crate log;
#[macro_use] extern crate syntax;
#[macro_use] #[no_link] extern crate rustc_bitflags;
#[macro_use]
extern crate log;
#[macro_use]
extern crate syntax;
#[macro_use]
#[no_link]
extern crate rustc_bitflags;
extern crate serialize as rustc_serialize; // used by deriving

View File

@ -29,24 +29,26 @@ pub fn lower_view_path(view_path: &ViewPath) -> P<hir::ViewPath> {
}
ViewPathList(ref path, ref path_list_idents) => {
hir::ViewPathList(lower_path(path),
path_list_idents.iter().map(|path_list_ident| {
Spanned {
node: match path_list_ident.node {
PathListIdent { id, name, rename } =>
hir::PathListIdent {
id: id,
name: name.name,
rename: rename.map(|x| x.name),
},
PathListMod { id, rename } =>
hir::PathListMod {
id: id,
rename: rename.map(|x| x.name)
}
},
span: path_list_ident.span
}
}).collect())
path_list_idents.iter()
.map(|path_list_ident| {
Spanned {
node: match path_list_ident.node {
PathListIdent { id, name, rename } =>
hir::PathListIdent {
id: id,
name: name.name,
rename: rename.map(|x| x.name),
},
PathListMod { id, rename } =>
hir::PathListMod {
id: id,
rename: rename.map(|x| x.name),
},
},
span: path_list_ident.span,
}
})
.collect())
}
},
span: view_path.span,
@ -66,17 +68,22 @@ pub fn lower_decl(d: &Decl) -> P<hir::Decl> {
match d.node {
DeclLocal(ref l) => P(Spanned {
node: hir::DeclLocal(lower_local(l)),
span: d.span
span: d.span,
}),
DeclItem(ref it) => P(Spanned {
node: hir::DeclItem(lower_item(it)),
span: d.span
span: d.span,
}),
}
}
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> {
@ -94,7 +101,7 @@ pub fn lower_ty(t: &Ty) -> P<hir::Ty> {
lifetimes: lower_lifetime_defs(&f.lifetimes),
unsafety: lower_unsafety(f.unsafety),
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()),
@ -103,14 +110,13 @@ pub fn lower_ty(t: &Ty) -> P<hir::Ty> {
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
hir::QSelf {
ty: lower_ty(ty),
position: position
position: position,
}
});
hir::TyPath(qself, lower_path(path))
}
TyObjectSum(ref ty, ref bounds) => {
hir::TyObjectSum(lower_ty(ty),
lower_bounds(bounds))
hir::TyObjectSum(lower_ty(ty), lower_bounds(bounds))
}
TyFixedLengthVec(ref ty, ref 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(),
kind: match v.node.kind {
TupleVariantKind(ref variant_args) => {
hir::TupleVariantKind(variant_args.iter().map(|ref x|
lower_variant_arg(x)).collect())
hir::TupleVariantKind(variant_args.iter()
.map(|ref x| lower_variant_arg(x))
.collect())
}
StructVariantKind(ref 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 {
hir::Path {
global: p.global,
segments: p.segments.iter().map(|&PathSegment {identifier, ref parameters}|
hir::PathSegment {
identifier: identifier,
parameters: lower_path_parameters(parameters),
}).collect(),
segments: p.segments
.iter()
.map(|&PathSegment { identifier, ref parameters }| {
hir::PathSegment {
identifier: identifier,
parameters: lower_path_parameters(parameters),
}
})
.collect(),
span: p.span,
}
}
@ -198,12 +209,12 @@ pub fn lower_parenthesized_parameter_data(data: &ParenthesizedParameterData)
pub fn lower_local(l: &Local) -> P<hir::Local> {
P(hir::Local {
id: l.id,
ty: l.ty.as_ref().map(|t| lower_ty(t)),
pat: lower_pat(&l.pat),
init: l.init.as_ref().map(|e| lower_expr(e)),
span: l.span,
})
id: l.id,
ty: l.ty.as_ref().map(|t| lower_ty(t)),
pat: lower_pat(&l.pat),
init: l.init.as_ref().map(|e| lower_expr(e)),
span: l.span,
})
}
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,
SelfValue(v) => hir::SelfValue(v.name),
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) => {
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 {
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 {
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> {
@ -240,7 +260,7 @@ pub fn lower_fn_decl(decl: &FnDecl) -> P<hir::FnDecl> {
output: match decl.output {
Return(ref ty) => hir::Return(lower_ty(ty)),
DefaultReturn(span) => hir::DefaultReturn(span),
NoReturn(span) => hir::NoReturn(span)
NoReturn(span) => hir::NoReturn(span),
},
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 {
match *tpb {
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)),
}
@ -270,11 +291,18 @@ pub fn lower_ty_params(tps: &OwnedSlice<TyParam>) -> OwnedSlice<hir::TyParam> {
}
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 {
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> {
@ -300,8 +328,10 @@ pub fn lower_generics(g: &Generics) -> hir::Generics {
pub fn lower_where_clause(wc: &WhereClause) -> hir::WhereClause {
hir::WhereClause {
id: wc.id,
predicates: wc.predicates.iter().map(|predicate|
lower_where_predicate(predicate)).collect(),
predicates: wc.predicates
.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),
bounded_ty: lower_ty(bounded_ty),
bounds: bounds.iter().map(|x| lower_ty_param_bound(x)).collect(),
span: span
span: span,
})
}
WherePredicate::RegionPredicate(WhereRegionPredicate{ ref lifetime,
@ -324,18 +354,18 @@ pub fn lower_where_predicate(pred: &WherePredicate) -> hir::WherePredicate {
hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
span: span,
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,
ref path,
ref ty,
span}) => {
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate{
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
id: id,
path: lower_path(path),
ty:lower_ty(ty),
span: span
ty: lower_ty(ty),
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 {
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 {
@ -375,12 +408,16 @@ pub fn lower_struct_field(f: &StructField) -> hir::StructField {
pub fn lower_field(f: &Field) -> hir::Field {
hir::Field {
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 {
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>>)
@ -393,7 +430,10 @@ fn lower_bounds(bounds: &TyParamBounds) -> hir::TyParamBounds {
}
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> {
@ -419,14 +459,12 @@ pub fn lower_item_underscore(i: &Item_) -> hir::Item_ {
hir::ItemConst(lower_ty(t), lower_expr(e))
}
ItemFn(ref decl, unsafety, constness, abi, ref generics, ref body) => {
hir::ItemFn(
lower_fn_decl(decl),
lower_unsafety(unsafety),
lower_constness(constness),
abi,
lower_generics(generics),
lower_block(body)
)
hir::ItemFn(lower_fn_decl(decl),
lower_unsafety(unsafety),
lower_constness(constness),
abi,
lower_generics(generics),
lower_block(body))
}
ItemMod(ref m) => hir::ItemMod(lower_mod(m)),
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))
}
ItemEnum(ref enum_definition, ref generics) => {
hir::ItemEnum(
hir::EnumDef {
variants: enum_definition.variants.iter().map(|x| lower_variant(x)).collect(),
},
lower_generics(generics))
hir::ItemEnum(hir::EnumDef {
variants: enum_definition.variants
.iter()
.map(|x| lower_variant(x))
.collect(),
},
lower_generics(generics))
}
ItemStruct(ref struct_def, ref generics) => {
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> {
P(hir::TraitItem {
id: i.id,
name: i.ident.name,
attrs: i.attrs.clone(),
node: match i.node {
id: i.id,
name: i.ident.name,
attrs: i.attrs.clone(),
node: match i.node {
ConstTraitItem(ref ty, ref default) => {
hir::ConstTraitItem(lower_ty(ty),
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)))
}
},
span: i.span,
})
span: i.span,
})
}
pub fn lower_impl_item(i: &ImplItem) -> P<hir::ImplItem> {
P(hir::ImplItem {
id: i.id,
name: i.ident.name,
attrs: i.attrs.clone(),
vis: lower_visibility(i.vis),
node: match i.node {
id: i.id,
name: i.ident.name,
attrs: i.attrs.clone(),
vis: lower_visibility(i.vis),
node: match i.node {
ConstImplItem(ref ty, ref expr) => {
hir::ConstImplItem(lower_ty(ty), lower_expr(expr))
}
MethodImplItem(ref sig, ref body) => {
hir::MethodImplItem(lower_method_sig(sig),
lower_block(body))
hir::MethodImplItem(lower_method_sig(sig), lower_block(body))
}
TypeImplItem(ref ty) => hir::TypeImplItem(lower_ty(ty)),
MacImplItem(..) => panic!("Shouldn't exist any more"),
},
span: i.span,
})
span: i.span,
})
}
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 {
@ -562,10 +604,10 @@ pub fn lower_item_simple(i: &Item) -> hir::Item {
pub fn lower_foreign_item(i: &ForeignItem) -> P<hir::ForeignItem> {
P(hir::ForeignItem {
id: i.id,
name: i.ident.name,
attrs: i.attrs.clone(),
node: match i.node {
id: i.id,
name: i.ident.name,
attrs: i.attrs.clone(),
node: match i.node {
ForeignItemFn(ref fdec, ref 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)
}
},
vis: lower_visibility(i.vis),
span: i.span,
})
vis: lower_visibility(i.vis),
span: i.span,
})
}
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> {
P(hir::Pat {
id: p.id,
node: match p.node {
id: p.id,
node: match p.node {
PatWild(k) => hir::PatWild(lower_pat_wild_kind(k)),
PatIdent(ref binding_mode, pth1, ref sub) => {
hir::PatIdent(lower_binding_mode(binding_mode),
pth1,
sub.as_ref().map(|x| lower_pat(x)))
pth1,
sub.as_ref().map(|x| lower_pat(x)))
}
PatLit(ref e) => hir::PatLit(lower_expr(e)),
PatEnum(ref pth, ref pats) => {
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) => {
let qself = hir::QSelf {
@ -661,130 +703,126 @@ pub fn lower_pat(p: &Pat) -> P<hir::Pat> {
}
PatStruct(ref pth, ref fields, etc) => {
let pth = lower_path(pth);
let fs = fields.iter().map(|f| {
Spanned { span: f.span,
node: hir::FieldPat {
name: f.node.ident.name,
pat: lower_pat(&f.node.pat),
is_shorthand: f.node.is_shorthand,
}}
}).collect();
let fs = fields.iter()
.map(|f| {
Spanned {
span: f.span,
node: hir::FieldPat {
name: f.node.ident.name,
pat: lower_pat(&f.node.pat),
is_shorthand: f.node.is_shorthand,
},
}
})
.collect();
hir::PatStruct(pth, fs, etc)
}
PatTup(ref elts) => hir::PatTup(elts.iter().map(|x| lower_pat(x)).collect()),
PatBox(ref inner) => hir::PatBox(lower_pat(inner)),
PatRegion(ref inner, mutbl) => hir::PatRegion(lower_pat(inner),
lower_mutability(mutbl)),
PatRegion(ref inner, mutbl) =>
hir::PatRegion(lower_pat(inner), lower_mutability(mutbl)),
PatRange(ref e1, ref e2) => {
hir::PatRange(lower_expr(e1), lower_expr(e2))
},
}
PatVec(ref before, ref slice, ref after) => {
hir::PatVec(before.iter().map(|x| lower_pat(x)).collect(),
slice.as_ref().map(|x| lower_pat(x)),
after.iter().map(|x| lower_pat(x)).collect())
slice.as_ref().map(|x| lower_pat(x)),
after.iter().map(|x| lower_pat(x)).collect())
}
PatMac(_) => panic!("Shouldn't exist here"),
},
span: p.span,
})
span: p.span,
})
}
pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
P(hir::Expr {
id: e.id,
node: match e.node {
ExprBox(ref e) => {
hir::ExprBox(lower_expr(e))
}
ExprVec(ref exprs) => {
hir::ExprVec(exprs.iter().map(|x| lower_expr(x)).collect())
}
ExprRepeat(ref expr, ref count) => {
hir::ExprRepeat(lower_expr(expr), lower_expr(count))
}
ExprTup(ref elts) => hir::ExprTup(elts.iter().map(|x| lower_expr(x)).collect()),
ExprCall(ref f, ref args) => {
hir::ExprCall(lower_expr(f),
args.iter().map(|x| lower_expr(x)).collect())
}
ExprMethodCall(i, ref tps, ref args) => {
hir::ExprMethodCall(
respan(i.span, i.node.name),
tps.iter().map(|x| lower_ty(x)).collect(),
args.iter().map(|x| lower_expr(x)).collect())
}
ExprBinary(binop, ref lhs, ref rhs) => {
hir::ExprBinary(lower_binop(binop),
lower_expr(lhs),
lower_expr(rhs))
}
ExprUnary(op, ref ohs) => {
hir::ExprUnary(lower_unop(op), lower_expr(ohs))
}
ExprLit(ref l) => hir::ExprLit(P((**l).clone())),
ExprCast(ref expr, ref ty) => {
hir::ExprCast(lower_expr(expr), lower_ty(ty))
}
ExprAddrOf(m, ref ohs) => hir::ExprAddrOf(lower_mutability(m), lower_expr(ohs)),
ExprIf(ref cond, ref tr, ref fl) => {
hir::ExprIf(lower_expr(cond),
lower_block(tr),
fl.as_ref().map(|x| lower_expr(x)))
}
ExprWhile(ref cond, ref body, opt_ident) => {
hir::ExprWhile(lower_expr(cond),
lower_block(body),
opt_ident)
}
ExprLoop(ref body, opt_ident) => {
hir::ExprLoop(lower_block(body),
opt_ident)
}
ExprMatch(ref expr, ref arms, ref source) => {
hir::ExprMatch(lower_expr(expr),
arms.iter().map(|x| lower_arm(x)).collect(),
lower_match_source(source))
}
ExprClosure(capture_clause, ref decl, ref body) => {
hir::ExprClosure(lower_capture_clause(capture_clause),
lower_fn_decl(decl),
lower_block(body))
}
ExprBlock(ref blk) => hir::ExprBlock(lower_block(blk)),
ExprAssign(ref el, ref er) => {
hir::ExprAssign(lower_expr(el), lower_expr(er))
}
ExprAssignOp(op, ref el, ref er) => {
hir::ExprAssignOp(lower_binop(op),
lower_expr(el),
lower_expr(er))
}
ExprField(ref el, ident) => {
hir::ExprField(lower_expr(el), respan(ident.span, ident.node.name))
}
ExprTupField(ref el, ident) => {
hir::ExprTupField(lower_expr(el), ident)
}
ExprIndex(ref el, ref er) => {
hir::ExprIndex(lower_expr(el), lower_expr(er))
}
ExprRange(ref e1, ref e2) => {
hir::ExprRange(e1.as_ref().map(|x| lower_expr(x)),
e2.as_ref().map(|x| lower_expr(x)))
}
ExprPath(ref qself, ref path) => {
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
hir::QSelf {
ty: lower_ty(ty),
position: position
}
});
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 {
id: e.id,
node: match e.node {
ExprBox(ref e) => {
hir::ExprBox(lower_expr(e))
}
ExprVec(ref exprs) => {
hir::ExprVec(exprs.iter().map(|x| lower_expr(x)).collect())
}
ExprRepeat(ref expr, ref count) => {
hir::ExprRepeat(lower_expr(expr), lower_expr(count))
}
ExprTup(ref elts) => hir::ExprTup(elts.iter().map(|x| lower_expr(x)).collect()),
ExprCall(ref f, ref args) => {
hir::ExprCall(lower_expr(f),
args.iter().map(|x| lower_expr(x)).collect())
}
ExprMethodCall(i, ref tps, ref args) => {
hir::ExprMethodCall(respan(i.span, i.node.name),
tps.iter().map(|x| lower_ty(x)).collect(),
args.iter().map(|x| lower_expr(x)).collect())
}
ExprBinary(binop, ref lhs, ref rhs) => {
hir::ExprBinary(lower_binop(binop), lower_expr(lhs), lower_expr(rhs))
}
ExprUnary(op, ref ohs) => {
hir::ExprUnary(lower_unop(op), lower_expr(ohs))
}
ExprLit(ref l) => hir::ExprLit(P((**l).clone())),
ExprCast(ref expr, ref ty) => {
hir::ExprCast(lower_expr(expr), lower_ty(ty))
}
ExprAddrOf(m, ref ohs) => hir::ExprAddrOf(lower_mutability(m), lower_expr(ohs)),
ExprIf(ref cond, ref tr, ref fl) => {
hir::ExprIf(lower_expr(cond),
lower_block(tr),
fl.as_ref().map(|x| lower_expr(x)))
}
ExprWhile(ref cond, ref body, opt_ident) => {
hir::ExprWhile(lower_expr(cond), lower_block(body), opt_ident)
}
ExprLoop(ref body, opt_ident) => {
hir::ExprLoop(lower_block(body), opt_ident)
}
ExprMatch(ref expr, ref arms, ref source) => {
hir::ExprMatch(lower_expr(expr),
arms.iter().map(|x| lower_arm(x)).collect(),
lower_match_source(source))
}
ExprClosure(capture_clause, ref decl, ref body) => {
hir::ExprClosure(lower_capture_clause(capture_clause),
lower_fn_decl(decl),
lower_block(body))
}
ExprBlock(ref blk) => hir::ExprBlock(lower_block(blk)),
ExprAssign(ref el, ref er) => {
hir::ExprAssign(lower_expr(el), lower_expr(er))
}
ExprAssignOp(op, ref el, ref er) => {
hir::ExprAssignOp(lower_binop(op), lower_expr(el), lower_expr(er))
}
ExprField(ref el, ident) => {
hir::ExprField(lower_expr(el), respan(ident.span, ident.node.name))
}
ExprTupField(ref el, ident) => {
hir::ExprTupField(lower_expr(el), ident)
}
ExprIndex(ref el, ref er) => {
hir::ExprIndex(lower_expr(el), lower_expr(er))
}
ExprRange(ref e1, ref e2) => {
hir::ExprRange(e1.as_ref().map(|x| lower_expr(x)),
e2.as_ref().map(|x| lower_expr(x)))
}
ExprPath(ref qself, ref path) => {
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
hir::QSelf {
ty: lower_ty(ty),
position: position,
}
});
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 outputs,
ref asm,
@ -795,36 +833,38 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
dialect,
expn_id,
}) => hir::ExprInlineAsm(hir::InlineAsm {
inputs: inputs.iter().map(|&(ref c, ref input)| {
(c.clone(), lower_expr(input))
}).collect(),
outputs: outputs.iter().map(|&(ref c, ref out, ref is_rw)| {
(c.clone(), lower_expr(out), *is_rw)
}).collect(),
asm: asm.clone(),
asm_str_style: asm_str_style,
clobbers: clobbers.clone(),
volatile: volatile,
alignstack: alignstack,
dialect: dialect,
expn_id: expn_id,
}),
ExprStruct(ref path, ref fields, ref maybe_expr) => {
hir::ExprStruct(lower_path(path),
fields.iter().map(|x| lower_field(x)).collect(),
maybe_expr.as_ref().map(|x| lower_expr(x)))
},
ExprParen(ref ex) => {
return lower_expr(ex);
}
ExprInPlace(..) |
ExprIfLet(..) |
ExprWhileLet(..) |
ExprForLoop(..) |
ExprMac(_) => panic!("Shouldn't exist here"),
},
span: e.span,
})
inputs: inputs.iter()
.map(|&(ref c, ref input)| (c.clone(), lower_expr(input)))
.collect(),
outputs: outputs.iter()
.map(|&(ref c, ref out, ref is_rw)| {
(c.clone(), lower_expr(out), *is_rw)
})
.collect(),
asm: asm.clone(),
asm_str_style: asm_str_style,
clobbers: clobbers.clone(),
volatile: volatile,
alignstack: alignstack,
dialect: dialect,
expn_id: expn_id,
}),
ExprStruct(ref path, ref fields, ref maybe_expr) => {
hir::ExprStruct(lower_path(path),
fields.iter().map(|x| lower_field(x)).collect(),
maybe_expr.as_ref().map(|x| lower_expr(x)))
}
ExprParen(ref ex) => {
return lower_expr(ex);
}
ExprInPlace(..) |
ExprIfLet(..) |
ExprWhileLet(..) |
ExprForLoop(..) |
ExprMac(_) => panic!("Shouldn't exist here"),
},
span: e.span,
})
}
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) => {
P(Spanned {
node: hir::StmtDecl(lower_decl(d), id),
span: s.span
span: s.span,
})
}
StmtExpr(ref e, id) => {
P(Spanned {
node: hir::StmtExpr(lower_expr(e), id),
span: s.span
span: s.span,
})
}
StmtSemi(ref e, id) => {
P(Spanned {
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

View File

@ -17,9 +17,13 @@ use syntax::codemap::Span;
use syntax::ptr::P;
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
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) {
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)) &&
after.iter().all(|p| walk_pat_(&**p, it))
}
PatWild(_) | PatLit(_) | PatRange(_, _) | PatIdent(_, _, _) |
PatEnum(_, _) | PatQPath(_, _) => {
PatWild(_) |
PatLit(_) |
PatRange(_, _) |
PatIdent(_, _, _) |
PatEnum(_, _) |
PatQPath(_, _) => {
true
}
}
@ -69,7 +77,7 @@ pub fn binop_to_string(op: BinOp_) -> &'static str {
BiLe => "<=",
BiNe => "!=",
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 {
match s.node {
StmtDecl(_, id) => id,
StmtExpr(_, id) => id,
StmtSemi(_, id) => id,
StmtDecl(_, id) => id,
StmtExpr(_, id) => id,
StmtSemi(_, id) => id,
}
}
pub fn lazy_binop(b: BinOp_) -> bool {
match b {
BiAnd => true,
BiOr => true,
_ => false
BiAnd => true,
BiOr => true,
_ => false,
}
}
pub fn is_shift_binop(b: BinOp_) -> bool {
match b {
BiShl => true,
BiShr => true,
_ => false
BiShl => true,
BiShr => true,
_ => false,
}
}
pub fn is_comparison_binop(b: BinOp_) -> bool {
match b {
BiEq | BiLt | BiLe | BiNe | BiGt | BiGe =>
true,
BiAnd | BiOr | BiAdd | BiSub | BiMul | BiDiv | BiRem |
BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr =>
false,
BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true,
BiAnd |
BiOr |
BiAdd |
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 pass_through_items: 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> {
fn visit_mod(&mut self,
module: &Mod,
_: Span,
node_id: NodeId) {
fn visit_mod(&mut self, module: &Mod, _: Span, node_id: NodeId) {
self.operation.visit_id(node_id);
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)
}
visit::walk_fn(self,
function_kind,
function_declaration,
block,
span);
visit::walk_fn(self, function_kind, function_declaration, block, span);
if !self.pass_through_items {
if let FnKind::Method(..) = function_kind {
@ -323,11 +332,8 @@ pub fn compute_id_range_for_fn_body(fk: FnKind,
body: &Block,
sp: Span,
id: NodeId)
-> ast_util::IdRange
{
let mut visitor = ast_util::IdRangeComputingVisitor {
result: ast_util::IdRange::max()
};
-> ast_util::IdRange {
let mut visitor = ast_util::IdRangeComputingVisitor { result: ast_util::IdRange::max() };
let mut id_visitor = IdVisitor {
operation: &mut visitor,
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 {
match e.node { ExprPath(..) => true, _ => false }
match e.node {
ExprPath(..) => true,
_ => false,
}
}
pub fn empty_generics() -> Generics {
@ -348,7 +357,7 @@ pub fn empty_generics() -> Generics {
where_clause: WhereClause {
id: DUMMY_NODE_ID,
predicates: Vec::new(),
}
},
}
}
@ -358,15 +367,13 @@ pub fn ident_to_path(s: Span, ident: Ident) -> Path {
hir::Path {
span: s,
global: false,
segments: vec!(
hir::PathSegment {
identifier: ident,
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
lifetimes: Vec::new(),
types: OwnedSlice::empty(),
bindings: OwnedSlice::empty(),
})
}
),
segments: vec!(hir::PathSegment {
identifier: ident,
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
lifetimes: Vec::new(),
types: OwnedSlice::empty(),
bindings: OwnedSlice::empty(),
}),
}),
}
}

View File

@ -56,25 +56,56 @@ pub trait Visitor<'v> : Sized {
fn visit_ident(&mut self, span: Span, ident: Ident) {
walk_ident(self, span, ident);
}
fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) { walk_mod(self, m) }
fn visit_foreign_item(&mut self, i: &'v ForeignItem) { walk_foreign_item(self, i) }
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_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_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) {
walk_mod(self, m)
}
fn visit_foreign_item(&mut self, i: &'v ForeignItem) {
walk_foreign_item(self, i)
}
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_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) {
walk_fn(self, fk, fd, b, s)
}
fn visit_trait_item(&mut self, ti: &'v TraitItem) { walk_trait_item(self, ti) }
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_trait_item(&mut self, ti: &'v TraitItem) {
walk_trait_item(self, ti)
}
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) {
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) {
walk_struct_def(self, s)
}
fn visit_struct_field(&mut self, s: &'v StructField) { walk_struct_field(self, s) }
fn visit_enum_def(&mut self, enum_definition: &'v EnumDef,
generics: &'v Generics) {
fn visit_struct_field(&mut self, s: &'v StructField) {
walk_struct_field(self, s)
}
fn visit_enum_def(&mut self, enum_definition: &'v EnumDef, generics: &'v 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) {
walk_lifetime(self, lifetime)
@ -116,7 +150,8 @@ pub trait Visitor<'v> : Sized {
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding) {
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) {
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);
}
pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V,
lifetime_def: &'v LifetimeDef) {
pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V, lifetime_def: &'v LifetimeDef) {
visitor.visit_lifetime(&lifetime_def.lifetime);
walk_list!(visitor, visit_lifetime, &lifetime_def.bounds);
}
pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V,
explicit_self: &'v ExplicitSelf) {
pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V, explicit_self: &'v ExplicitSelf) {
match explicit_self.node {
SelfStatic => {},
SelfStatic => {}
SelfValue(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)
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);
}
pub fn walk_trait_ref<'v,V>(visitor: &mut V,
trait_ref: &'v TraitRef)
pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)
where V: Visitor<'v>
{
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);
}
ItemFn(ref declaration, unsafety, constness, abi, ref generics, ref body) => {
visitor.visit_fn(FnKind::ItemFn(item.name, generics, unsafety,
constness, abi, item.vis),
visitor.visit_fn(FnKind::ItemFn(item.name,
generics,
unsafety,
constness,
abi,
item.vis),
declaration,
body,
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) => {
visitor.visit_generics(generics);
visitor.visit_struct_def(struct_definition,
item.name,
generics,
item.id)
visitor.visit_struct_def(struct_definition, item.name, generics, item.id)
}
ItemTrait(_, ref generics, ref bounds, ref methods) => {
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) => {
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) => {
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) {
for segment in &prefix.segments {
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,
foreign_item: &'v ForeignItem) {
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem) {
visitor.visit_name(foreign_item.span, foreign_item.name);
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);
}
pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V,
bound: &'v TyParamBound) {
pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v TyParamBound) {
match *bound {
TraitTyParamBound(ref typ, ref 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)
}
pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V,
function_kind: FnKind<'v>) {
pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'v>) {
match function_kind {
FnKind::ItemFn(_, 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);
}
MethodTraitItem(ref sig, Some(ref body)) => {
visitor.visit_fn(FnKind::Method(trait_item.name, sig, None), &sig.decl,
body, trait_item.span, trait_item.id);
visitor.visit_fn(FnKind::Method(trait_item.name, sig, None),
&sig.decl,
body,
trait_item.span,
trait_item.id);
}
TypeTraitItem(ref bounds, ref default) => {
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);
}
MethodImplItem(ref sig, ref body) => {
visitor.visit_fn(FnKind::Method(impl_item.name, sig, Some(impl_item.vis)), &sig.decl,
body, impl_item.span, impl_item.id);
visitor.visit_fn(FnKind::Method(impl_item.name, sig, Some(impl_item.vis)),
&sig.decl,
body,
impl_item.span,
impl_item.id);
}
TypeImplItem(ref 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,
struct_definition: &'v StructDef) {
pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v StructDef) {
walk_list!(visitor, visit_struct_field, &struct_definition.fields);
}
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V,
struct_field: &'v StructField) {
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField) {
walk_opt_name(visitor, struct_field.span, struct_field.node.name());
visitor.visit_ty(&struct_field.node.ty);
walk_list!(visitor, visit_attribute, &struct_field.node.attrs);