rustfmt librustc_front
This commit is contained in:
parent
c2be91ede0
commit
869e9719fd
7 changed files with 1261 additions and 1117 deletions
|
@ -29,7 +29,9 @@ pub trait MoveMap<T> {
|
|||
}
|
||||
|
||||
impl<T> MoveMap<T> for Vec<T> {
|
||||
fn move_map<F>(mut self, mut f: F) -> Vec<T> where F: FnMut(T) -> T {
|
||||
fn move_map<F>(mut self, mut f: F) -> Vec<T>
|
||||
where F: FnMut(T) -> T
|
||||
{
|
||||
for p in &mut self {
|
||||
unsafe {
|
||||
// FIXME(#5016) this shouldn't need to zero to be safe.
|
||||
|
@ -41,7 +43,9 @@ impl<T> MoveMap<T> for Vec<T> {
|
|||
}
|
||||
|
||||
impl<T> MoveMap<T> for OwnedSlice<T> {
|
||||
fn move_map<F>(self, f: F) -> OwnedSlice<T> where F: FnMut(T) -> T {
|
||||
fn move_map<F>(self, f: F) -> OwnedSlice<T>
|
||||
where F: FnMut(T) -> T
|
||||
{
|
||||
OwnedSlice::from_vec(self.into_vec().move_map(f))
|
||||
}
|
||||
}
|
||||
|
@ -167,15 +171,15 @@ pub trait Folder : Sized {
|
|||
noop_fold_path_parameters(p, self)
|
||||
}
|
||||
|
||||
fn fold_angle_bracketed_parameter_data(&mut self, p: AngleBracketedParameterData)
|
||||
-> AngleBracketedParameterData
|
||||
{
|
||||
fn fold_angle_bracketed_parameter_data(&mut self,
|
||||
p: AngleBracketedParameterData)
|
||||
-> AngleBracketedParameterData {
|
||||
noop_fold_angle_bracketed_parameter_data(p, self)
|
||||
}
|
||||
|
||||
fn fold_parenthesized_parameter_data(&mut self, p: ParenthesizedParameterData)
|
||||
-> ParenthesizedParameterData
|
||||
{
|
||||
fn fold_parenthesized_parameter_data(&mut self,
|
||||
p: ParenthesizedParameterData)
|
||||
-> ParenthesizedParameterData {
|
||||
noop_fold_parenthesized_parameter_data(p, self)
|
||||
}
|
||||
|
||||
|
@ -247,13 +251,13 @@ pub trait Folder : Sized {
|
|||
noop_fold_variant_arg(va, self)
|
||||
}
|
||||
|
||||
fn fold_opt_bounds(&mut self, b: Option<OwnedSlice<TyParamBound>>)
|
||||
fn fold_opt_bounds(&mut self,
|
||||
b: Option<OwnedSlice<TyParamBound>>)
|
||||
-> Option<OwnedSlice<TyParamBound>> {
|
||||
noop_fold_opt_bounds(b, self)
|
||||
}
|
||||
|
||||
fn fold_bounds(&mut self, b: OwnedSlice<TyParamBound>)
|
||||
-> OwnedSlice<TyParamBound> {
|
||||
fn fold_bounds(&mut self, b: OwnedSlice<TyParamBound>) -> OwnedSlice<TyParamBound> {
|
||||
noop_fold_bounds(b, self)
|
||||
}
|
||||
|
||||
|
@ -269,13 +273,11 @@ pub trait Folder : Sized {
|
|||
noop_fold_field(field, self)
|
||||
}
|
||||
|
||||
fn fold_where_clause(&mut self, where_clause: WhereClause)
|
||||
-> WhereClause {
|
||||
fn fold_where_clause(&mut self, where_clause: WhereClause) -> WhereClause {
|
||||
noop_fold_where_clause(where_clause, self)
|
||||
}
|
||||
|
||||
fn fold_where_predicate(&mut self, where_predicate: WherePredicate)
|
||||
-> WherePredicate {
|
||||
fn fold_where_predicate(&mut self, where_predicate: WherePredicate) -> WherePredicate {
|
||||
noop_fold_where_predicate(where_predicate, self)
|
||||
}
|
||||
|
||||
|
@ -288,13 +290,15 @@ pub trait Folder : Sized {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<P<MetaItem>>, fld: &mut T)
|
||||
pub fn noop_fold_meta_items<T: Folder>(meta_items: Vec<P<MetaItem>>,
|
||||
fld: &mut T)
|
||||
-> Vec<P<MetaItem>> {
|
||||
meta_items.move_map(|x| fld.fold_meta_item(x))
|
||||
}
|
||||
|
||||
pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<ViewPath> {
|
||||
view_path.map(|Spanned {node, span}| Spanned {
|
||||
view_path.map(|Spanned { node, span }| {
|
||||
Spanned {
|
||||
node: match node {
|
||||
ViewPathSimple(name, path) => {
|
||||
ViewPathSimple(name, fld.fold_path(path))
|
||||
|
@ -307,24 +311,23 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P<
|
|||
path_list_idents.move_map(|path_list_ident| {
|
||||
Spanned {
|
||||
node: match path_list_ident.node {
|
||||
PathListIdent { id, name, rename } =>
|
||||
PathListIdent {
|
||||
PathListIdent { id, name, rename } => PathListIdent {
|
||||
id: fld.new_id(id),
|
||||
name: name,
|
||||
rename: rename,
|
||||
},
|
||||
PathListMod { id, rename } =>
|
||||
PathListMod {
|
||||
PathListMod { id, rename } => PathListMod {
|
||||
id: fld.new_id(id),
|
||||
rename: rename,
|
||||
}
|
||||
},
|
||||
span: fld.new_span(path_list_ident.span)
|
||||
},
|
||||
span: fld.new_span(path_list_ident.span),
|
||||
}
|
||||
}))
|
||||
}
|
||||
},
|
||||
span: fld.new_span(span)
|
||||
span: fld.new_span(span),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -332,7 +335,7 @@ pub fn fold_attrs<T: Folder>(attrs: Vec<Attribute>, fld: &mut T) -> Vec<Attribut
|
|||
attrs.into_iter().flat_map(|x| fld.fold_attribute(x)).collect()
|
||||
}
|
||||
|
||||
pub fn noop_fold_arm<T: Folder>(Arm {attrs, pats, guard, body}: Arm, fld: &mut T) -> Arm {
|
||||
pub fn noop_fold_arm<T: Folder>(Arm { attrs, pats, guard, body }: Arm, fld: &mut T) -> Arm {
|
||||
Arm {
|
||||
attrs: fold_attrs(attrs, fld),
|
||||
pats: pats.move_map(|x| fld.fold_pat(x)),
|
||||
|
@ -342,29 +345,39 @@ pub fn noop_fold_arm<T: Folder>(Arm {attrs, pats, guard, body}: Arm, fld: &mut T
|
|||
}
|
||||
|
||||
pub fn noop_fold_decl<T: Folder>(d: P<Decl>, fld: &mut T) -> SmallVector<P<Decl>> {
|
||||
d.and_then(|Spanned {node, span}| match node {
|
||||
d.and_then(|Spanned { node, span }| {
|
||||
match node {
|
||||
DeclLocal(l) => SmallVector::one(P(Spanned {
|
||||
node: DeclLocal(fld.fold_local(l)),
|
||||
span: fld.new_span(span)
|
||||
span: fld.new_span(span),
|
||||
})),
|
||||
DeclItem(it) => fld.fold_item(it).into_iter().map(|i| P(Spanned {
|
||||
DeclItem(it) => fld.fold_item(it)
|
||||
.into_iter()
|
||||
.map(|i| {
|
||||
P(Spanned {
|
||||
node: DeclItem(i),
|
||||
span: fld.new_span(span)
|
||||
})).collect()
|
||||
span: fld.new_span(span),
|
||||
})
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn noop_fold_ty_binding<T: Folder>(b: P<TypeBinding>, fld: &mut T) -> P<TypeBinding> {
|
||||
b.map(|TypeBinding { id, name, ty, span }| TypeBinding {
|
||||
b.map(|TypeBinding { id, name, ty, span }| {
|
||||
TypeBinding {
|
||||
id: fld.new_id(id),
|
||||
name: name,
|
||||
ty: fld.fold_ty(ty),
|
||||
span: fld.new_span(span),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
|
||||
t.map(|Ty {id, node, span}| Ty {
|
||||
t.map(|Ty { id, node, span }| {
|
||||
Ty {
|
||||
id: fld.new_id(id),
|
||||
node: match node {
|
||||
TyInfer => node,
|
||||
|
@ -374,11 +387,13 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
|
|||
TyRptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt))
|
||||
}
|
||||
TyBareFn(f) => {
|
||||
TyBareFn(f.map(|BareFnTy {lifetimes, unsafety, abi, decl}| BareFnTy {
|
||||
TyBareFn(f.map(|BareFnTy { lifetimes, unsafety, abi, decl }| {
|
||||
BareFnTy {
|
||||
lifetimes: fld.fold_lifetime_defs(lifetimes),
|
||||
unsafety: unsafety,
|
||||
abi: abi,
|
||||
decl: fld.fold_fn_decl(decl)
|
||||
decl: fld.fold_fn_decl(decl),
|
||||
}
|
||||
}))
|
||||
}
|
||||
TyTup(tys) => TyTup(tys.move_map(|ty| fld.fold_ty(ty))),
|
||||
|
@ -387,14 +402,13 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
|
|||
let qself = qself.map(|QSelf { ty, position }| {
|
||||
QSelf {
|
||||
ty: fld.fold_ty(ty),
|
||||
position: position
|
||||
position: position,
|
||||
}
|
||||
});
|
||||
TyPath(qself, fld.fold_path(path))
|
||||
}
|
||||
TyObjectSum(ty, bounds) => {
|
||||
TyObjectSum(fld.fold_ty(ty),
|
||||
fld.fold_bounds(bounds))
|
||||
TyObjectSum(fld.fold_ty(ty), fld.fold_bounds(bounds))
|
||||
}
|
||||
TyFixedLengthVec(ty, e) => {
|
||||
TyFixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e))
|
||||
|
@ -406,12 +420,14 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
|
|||
TyPolyTraitRef(bounds.move_map(|b| fld.fold_ty_param_bound(b)))
|
||||
}
|
||||
},
|
||||
span: fld.new_span(span)
|
||||
span: fld.new_span(span),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn noop_fold_foreign_mod<T: Folder>(ForeignMod {abi, items}: ForeignMod,
|
||||
fld: &mut T) -> ForeignMod {
|
||||
pub fn noop_fold_foreign_mod<T: Folder>(ForeignMod { abi, items }: ForeignMod,
|
||||
fld: &mut T)
|
||||
-> ForeignMod {
|
||||
ForeignMod {
|
||||
abi: abi,
|
||||
items: items.move_map(|x| fld.fold_foreign_item(x)),
|
||||
|
@ -419,15 +435,15 @@ pub fn noop_fold_foreign_mod<T: Folder>(ForeignMod {abi, items}: ForeignMod,
|
|||
}
|
||||
|
||||
pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T) -> P<Variant> {
|
||||
v.map(|Spanned {node: Variant_ {id, name, attrs, kind, disr_expr}, span}| Spanned {
|
||||
v.map(|Spanned { node: Variant_ { id, name, attrs, kind, disr_expr }, span }| {
|
||||
Spanned {
|
||||
node: Variant_ {
|
||||
id: fld.new_id(id),
|
||||
name: name,
|
||||
attrs: fold_attrs(attrs, fld),
|
||||
kind: match kind {
|
||||
TupleVariantKind(variant_args) => {
|
||||
TupleVariantKind(variant_args.move_map(|x|
|
||||
fld.fold_variant_arg(x)))
|
||||
TupleVariantKind(variant_args.move_map(|x| fld.fold_variant_arg(x)))
|
||||
}
|
||||
StructVariantKind(struct_def) => {
|
||||
StructVariantKind(fld.fold_struct_def(struct_def))
|
||||
|
@ -436,6 +452,7 @@ pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T) -> P<Variant> {
|
|||
disr_expr: disr_expr.map(|e| fld.fold_expr(e)),
|
||||
},
|
||||
span: fld.new_span(span),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -451,20 +468,22 @@ pub fn noop_fold_usize<T: Folder>(i: usize, _: &mut T) -> usize {
|
|||
i
|
||||
}
|
||||
|
||||
pub fn noop_fold_path<T: Folder>(Path {global, segments, span}: Path, fld: &mut T) -> Path {
|
||||
pub fn noop_fold_path<T: Folder>(Path { global, segments, span }: Path, fld: &mut T) -> Path {
|
||||
Path {
|
||||
global: global,
|
||||
segments: segments.move_map(|PathSegment {identifier, parameters}| PathSegment {
|
||||
segments: segments.move_map(|PathSegment { identifier, parameters }| {
|
||||
PathSegment {
|
||||
identifier: fld.fold_ident(identifier),
|
||||
parameters: fld.fold_path_parameters(parameters),
|
||||
}
|
||||
}),
|
||||
span: fld.new_span(span)
|
||||
span: fld.new_span(span),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_path_parameters<T: Folder>(path_parameters: PathParameters, fld: &mut T)
|
||||
-> PathParameters
|
||||
{
|
||||
pub fn noop_fold_path_parameters<T: Folder>(path_parameters: PathParameters,
|
||||
fld: &mut T)
|
||||
-> PathParameters {
|
||||
match path_parameters {
|
||||
AngleBracketedParameters(data) =>
|
||||
AngleBracketedParameters(fld.fold_angle_bracketed_parameter_data(data)),
|
||||
|
@ -475,31 +494,35 @@ pub fn noop_fold_path_parameters<T: Folder>(path_parameters: PathParameters, fld
|
|||
|
||||
pub fn noop_fold_angle_bracketed_parameter_data<T: Folder>(data: AngleBracketedParameterData,
|
||||
fld: &mut T)
|
||||
-> AngleBracketedParameterData
|
||||
{
|
||||
-> AngleBracketedParameterData {
|
||||
let AngleBracketedParameterData { lifetimes, types, bindings } = data;
|
||||
AngleBracketedParameterData { lifetimes: fld.fold_lifetimes(lifetimes),
|
||||
AngleBracketedParameterData {
|
||||
lifetimes: fld.fold_lifetimes(lifetimes),
|
||||
types: types.move_map(|ty| fld.fold_ty(ty)),
|
||||
bindings: bindings.move_map(|b| fld.fold_ty_binding(b)) }
|
||||
bindings: bindings.move_map(|b| fld.fold_ty_binding(b)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_parenthesized_parameter_data<T: Folder>(data: ParenthesizedParameterData,
|
||||
fld: &mut T)
|
||||
-> ParenthesizedParameterData
|
||||
{
|
||||
-> ParenthesizedParameterData {
|
||||
let ParenthesizedParameterData { inputs, output, span } = data;
|
||||
ParenthesizedParameterData { inputs: inputs.move_map(|ty| fld.fold_ty(ty)),
|
||||
ParenthesizedParameterData {
|
||||
inputs: inputs.move_map(|ty| fld.fold_ty(ty)),
|
||||
output: output.map(|ty| fld.fold_ty(ty)),
|
||||
span: fld.new_span(span) }
|
||||
span: fld.new_span(span),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
|
||||
l.map(|Local {id, pat, ty, init, span}| Local {
|
||||
l.map(|Local { id, pat, ty, init, span }| {
|
||||
Local {
|
||||
id: fld.new_id(id),
|
||||
ty: ty.map(|t| fld.fold_ty(t)),
|
||||
pat: fld.fold_pat(pat),
|
||||
init: init.map(|e| fld.fold_expr(e)),
|
||||
span: fld.new_span(span)
|
||||
span: fld.new_span(span),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -510,13 +533,14 @@ pub fn noop_fold_attribute<T: Folder>(at: Attribute, fld: &mut T) -> Option<Attr
|
|||
id: id,
|
||||
style: style,
|
||||
value: fld.fold_meta_item(value),
|
||||
is_sugared_doc: is_sugared_doc
|
||||
is_sugared_doc: is_sugared_doc,
|
||||
},
|
||||
span: fld.new_span(span)
|
||||
span: fld.new_span(span),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_, fld: &mut T)
|
||||
pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_,
|
||||
fld: &mut T)
|
||||
-> ExplicitSelf_ {
|
||||
match es {
|
||||
SelfStatic | SelfValue(_) => es,
|
||||
|
@ -529,50 +553,55 @@ pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_, fld: &mu
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_explicit_self<T: Folder>(Spanned {span, node}: ExplicitSelf, fld: &mut T)
|
||||
pub fn noop_fold_explicit_self<T: Folder>(Spanned { span, node }: ExplicitSelf,
|
||||
fld: &mut T)
|
||||
-> ExplicitSelf {
|
||||
Spanned {
|
||||
node: fld.fold_explicit_self_underscore(node),
|
||||
span: fld.new_span(span)
|
||||
span: fld.new_span(span),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_meta_item<T: Folder>(mi: P<MetaItem>, fld: &mut T) -> P<MetaItem> {
|
||||
mi.map(|Spanned {node, span}| Spanned {
|
||||
mi.map(|Spanned { node, span }| {
|
||||
Spanned {
|
||||
node: match node {
|
||||
MetaWord(id) => MetaWord(id),
|
||||
MetaList(id, mis) => {
|
||||
MetaList(id, mis.move_map(|e| fld.fold_meta_item(e)))
|
||||
}
|
||||
MetaNameValue(id, s) => MetaNameValue(id, s)
|
||||
MetaNameValue(id, s) => MetaNameValue(id, s),
|
||||
},
|
||||
span: fld.new_span(span)
|
||||
span: fld.new_span(span),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn noop_fold_arg<T: Folder>(Arg {id, pat, ty}: Arg, fld: &mut T) -> Arg {
|
||||
pub fn noop_fold_arg<T: Folder>(Arg { id, pat, ty }: Arg, fld: &mut T) -> Arg {
|
||||
Arg {
|
||||
id: fld.new_id(id),
|
||||
pat: fld.fold_pat(pat),
|
||||
ty: fld.fold_ty(ty)
|
||||
ty: fld.fold_ty(ty),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> {
|
||||
decl.map(|FnDecl {inputs, output, variadic}| FnDecl {
|
||||
decl.map(|FnDecl { inputs, output, variadic }| {
|
||||
FnDecl {
|
||||
inputs: inputs.move_map(|x| fld.fold_arg(x)),
|
||||
output: match output {
|
||||
Return(ty) => Return(fld.fold_ty(ty)),
|
||||
DefaultReturn(span) => DefaultReturn(span),
|
||||
NoReturn(span) => NoReturn(span)
|
||||
NoReturn(span) => NoReturn(span),
|
||||
},
|
||||
variadic: variadic
|
||||
variadic: variadic,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn noop_fold_ty_param_bound<T>(tpb: TyParamBound, fld: &mut T)
|
||||
-> TyParamBound
|
||||
where T: Folder {
|
||||
pub fn noop_fold_ty_param_bound<T>(tpb: TyParamBound, fld: &mut T) -> TyParamBound
|
||||
where T: Folder
|
||||
{
|
||||
match tpb {
|
||||
TraitTyParamBound(ty, modifier) => TraitTyParamBound(fld.fold_poly_trait_ref(ty), modifier),
|
||||
RegionTyParamBound(lifetime) => RegionTyParamBound(fld.fold_lifetime(lifetime)),
|
||||
|
@ -586,11 +615,12 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam {
|
|||
name: name,
|
||||
bounds: fld.fold_bounds(bounds),
|
||||
default: default.map(|x| fld.fold_ty(x)),
|
||||
span: span
|
||||
span: span,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_ty_params<T: Folder>(tps: OwnedSlice<TyParam>, fld: &mut T)
|
||||
pub fn noop_fold_ty_params<T: Folder>(tps: OwnedSlice<TyParam>,
|
||||
fld: &mut T)
|
||||
-> OwnedSlice<TyParam> {
|
||||
tps.move_map(|tp| fld.fold_ty_param(tp))
|
||||
}
|
||||
|
@ -599,12 +629,11 @@ pub fn noop_fold_lifetime<T: Folder>(l: Lifetime, fld: &mut T) -> Lifetime {
|
|||
Lifetime {
|
||||
id: fld.new_id(l.id),
|
||||
name: l.name,
|
||||
span: fld.new_span(l.span)
|
||||
span: fld.new_span(l.span),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_lifetime_def<T: Folder>(l: LifetimeDef, fld: &mut T)
|
||||
-> LifetimeDef {
|
||||
pub fn noop_fold_lifetime_def<T: Folder>(l: LifetimeDef, fld: &mut T) -> LifetimeDef {
|
||||
LifetimeDef {
|
||||
lifetime: fld.fold_lifetime(l.lifetime),
|
||||
bounds: fld.fold_lifetimes(l.bounds),
|
||||
|
@ -615,18 +644,17 @@ pub fn noop_fold_lifetimes<T: Folder>(lts: Vec<Lifetime>, fld: &mut T) -> Vec<Li
|
|||
lts.move_map(|l| fld.fold_lifetime(l))
|
||||
}
|
||||
|
||||
pub fn noop_fold_lifetime_defs<T: Folder>(lts: Vec<LifetimeDef>, fld: &mut T)
|
||||
-> Vec<LifetimeDef> {
|
||||
pub fn noop_fold_lifetime_defs<T: Folder>(lts: Vec<LifetimeDef>, fld: &mut T) -> Vec<LifetimeDef> {
|
||||
lts.move_map(|l| fld.fold_lifetime_def(l))
|
||||
}
|
||||
|
||||
pub fn noop_fold_opt_lifetime<T: Folder>(o_lt: Option<Lifetime>, fld: &mut T)
|
||||
-> Option<Lifetime> {
|
||||
pub fn noop_fold_opt_lifetime<T: Folder>(o_lt: Option<Lifetime>, fld: &mut T) -> Option<Lifetime> {
|
||||
o_lt.map(|lt| fld.fold_lifetime(lt))
|
||||
}
|
||||
|
||||
pub fn noop_fold_generics<T: Folder>(Generics {ty_params, lifetimes, where_clause}: Generics,
|
||||
fld: &mut T) -> Generics {
|
||||
pub fn noop_fold_generics<T: Folder>(Generics { ty_params, lifetimes, where_clause }: Generics,
|
||||
fld: &mut T)
|
||||
-> Generics {
|
||||
Generics {
|
||||
ty_params: fld.fold_ty_params(ty_params),
|
||||
lifetimes: fld.fold_lifetime_defs(lifetimes),
|
||||
|
@ -634,22 +662,16 @@ pub fn noop_fold_generics<T: Folder>(Generics {ty_params, lifetimes, where_claus
|
|||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_where_clause<T: Folder>(
|
||||
WhereClause {id, predicates}: WhereClause,
|
||||
pub fn noop_fold_where_clause<T: Folder>(WhereClause { id, predicates }: WhereClause,
|
||||
fld: &mut T)
|
||||
-> WhereClause {
|
||||
WhereClause {
|
||||
id: fld.new_id(id),
|
||||
predicates: predicates.move_map(|predicate| {
|
||||
fld.fold_where_predicate(predicate)
|
||||
})
|
||||
predicates: predicates.move_map(|predicate| fld.fold_where_predicate(predicate)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_where_predicate<T: Folder>(
|
||||
pred: WherePredicate,
|
||||
fld: &mut T)
|
||||
-> WherePredicate {
|
||||
pub fn noop_fold_where_predicate<T: Folder>(pred: WherePredicate, fld: &mut T) -> WherePredicate {
|
||||
match pred {
|
||||
hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate{bound_lifetimes,
|
||||
bounded_ty,
|
||||
|
@ -659,7 +681,7 @@ pub fn noop_fold_where_predicate<T: Folder>(
|
|||
bound_lifetimes: fld.fold_lifetime_defs(bound_lifetimes),
|
||||
bounded_ty: fld.fold_ty(bounded_ty),
|
||||
bounds: bounds.move_map(|x| fld.fold_ty_param_bound(x)),
|
||||
span: fld.new_span(span)
|
||||
span: fld.new_span(span),
|
||||
})
|
||||
}
|
||||
hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate{lifetime,
|
||||
|
@ -668,27 +690,29 @@ pub fn noop_fold_where_predicate<T: Folder>(
|
|||
hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
||||
span: fld.new_span(span),
|
||||
lifetime: fld.fold_lifetime(lifetime),
|
||||
bounds: bounds.move_map(|bound| fld.fold_lifetime(bound))
|
||||
bounds: bounds.move_map(|bound| fld.fold_lifetime(bound)),
|
||||
})
|
||||
}
|
||||
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate{id,
|
||||
path,
|
||||
ty,
|
||||
span}) => {
|
||||
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate{
|
||||
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
|
||||
id: fld.new_id(id),
|
||||
path: fld.fold_path(path),
|
||||
ty:fld.fold_ty(ty),
|
||||
span: fld.new_span(span)
|
||||
ty: fld.fold_ty(ty),
|
||||
span: fld.new_span(span),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_struct_def<T: Folder>(struct_def: P<StructDef>, fld: &mut T) -> P<StructDef> {
|
||||
struct_def.map(|StructDef { fields, ctor_id }| StructDef {
|
||||
struct_def.map(|StructDef { fields, ctor_id }| {
|
||||
StructDef {
|
||||
fields: fields.move_map(|f| fld.fold_struct_field(f)),
|
||||
ctor_id: ctor_id.map(|cid| fld.new_id(cid)),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -721,50 +745,54 @@ pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T) -> StructF
|
|||
ty: fld.fold_ty(ty),
|
||||
attrs: fold_attrs(attrs, fld),
|
||||
},
|
||||
span: fld.new_span(span)
|
||||
span: fld.new_span(span),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_field<T: Folder>(Field {name, expr, span}: Field, folder: &mut T) -> Field {
|
||||
pub fn noop_fold_field<T: Folder>(Field { name, expr, span }: Field, folder: &mut T) -> Field {
|
||||
Field {
|
||||
name: respan(folder.new_span(name.span), folder.fold_name(name.node)),
|
||||
name: respan(folder.new_span(name.span),
|
||||
folder.fold_name(name.node)),
|
||||
expr: folder.fold_expr(expr),
|
||||
span: folder.new_span(span)
|
||||
span: folder.new_span(span),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_mt<T: Folder>(MutTy {ty, mutbl}: MutTy, folder: &mut T) -> MutTy {
|
||||
pub fn noop_fold_mt<T: Folder>(MutTy { ty, mutbl }: MutTy, folder: &mut T) -> MutTy {
|
||||
MutTy {
|
||||
ty: folder.fold_ty(ty),
|
||||
mutbl: mutbl,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_opt_bounds<T: Folder>(b: Option<OwnedSlice<TyParamBound>>, folder: &mut T)
|
||||
pub fn noop_fold_opt_bounds<T: Folder>(b: Option<OwnedSlice<TyParamBound>>,
|
||||
folder: &mut T)
|
||||
-> Option<OwnedSlice<TyParamBound>> {
|
||||
b.map(|bounds| folder.fold_bounds(bounds))
|
||||
}
|
||||
|
||||
fn noop_fold_bounds<T: Folder>(bounds: TyParamBounds, folder: &mut T)
|
||||
-> TyParamBounds {
|
||||
fn noop_fold_bounds<T: Folder>(bounds: TyParamBounds, folder: &mut T) -> TyParamBounds {
|
||||
bounds.move_map(|bound| folder.fold_ty_param_bound(bound))
|
||||
}
|
||||
|
||||
fn noop_fold_variant_arg<T: Folder>(VariantArg {id, ty}: VariantArg, folder: &mut T)
|
||||
fn noop_fold_variant_arg<T: Folder>(VariantArg { id, ty }: VariantArg,
|
||||
folder: &mut T)
|
||||
-> VariantArg {
|
||||
VariantArg {
|
||||
id: folder.new_id(id),
|
||||
ty: folder.fold_ty(ty)
|
||||
ty: folder.fold_ty(ty),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_block<T: Folder>(b: P<Block>, folder: &mut T) -> P<Block> {
|
||||
b.map(|Block {id, stmts, expr, rules, span}| Block {
|
||||
b.map(|Block { id, stmts, expr, rules, span }| {
|
||||
Block {
|
||||
id: folder.new_id(id),
|
||||
stmts: stmts.into_iter().flat_map(|s| folder.fold_stmt(s).into_iter()).collect(),
|
||||
expr: expr.map(|x| folder.fold_expr(x)),
|
||||
rules: rules,
|
||||
span: folder.new_span(span),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -781,14 +809,12 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
|
|||
ItemConst(folder.fold_ty(t), folder.fold_expr(e))
|
||||
}
|
||||
ItemFn(decl, unsafety, constness, abi, generics, body) => {
|
||||
ItemFn(
|
||||
folder.fold_fn_decl(decl),
|
||||
ItemFn(folder.fold_fn_decl(decl),
|
||||
unsafety,
|
||||
constness,
|
||||
abi,
|
||||
folder.fold_generics(generics),
|
||||
folder.fold_block(body)
|
||||
)
|
||||
folder.fold_block(body))
|
||||
}
|
||||
ItemMod(m) => ItemMod(folder.fold_mod(m)),
|
||||
ItemForeignMod(nm) => ItemForeignMod(folder.fold_foreign_mod(nm)),
|
||||
|
@ -796,8 +822,7 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
|
|||
ItemTy(folder.fold_ty(t), folder.fold_generics(generics))
|
||||
}
|
||||
ItemEnum(enum_definition, generics) => {
|
||||
ItemEnum(
|
||||
hir::EnumDef {
|
||||
ItemEnum(hir::EnumDef {
|
||||
variants: enum_definition.variants.move_map(|x| folder.fold_variant(x)),
|
||||
},
|
||||
folder.fold_generics(generics))
|
||||
|
@ -807,12 +832,15 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
|
|||
ItemStruct(struct_def, folder.fold_generics(generics))
|
||||
}
|
||||
ItemDefaultImpl(unsafety, ref trait_ref) => {
|
||||
ItemDefaultImpl(unsafety, folder.fold_trait_ref((*trait_ref).clone()))
|
||||
ItemDefaultImpl(unsafety,
|
||||
folder.fold_trait_ref((*trait_ref).clone()))
|
||||
}
|
||||
ItemImpl(unsafety, polarity, generics, ifce, ty, impl_items) => {
|
||||
let new_impl_items = impl_items.into_iter().flat_map(|item| {
|
||||
let new_impl_items = impl_items.into_iter()
|
||||
.flat_map(|item| {
|
||||
folder.fold_impl_item(item).into_iter()
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
let ifce = match ifce {
|
||||
None => None,
|
||||
Some(ref trait_ref) => {
|
||||
|
@ -828,20 +856,19 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
|
|||
}
|
||||
ItemTrait(unsafety, generics, bounds, items) => {
|
||||
let bounds = folder.fold_bounds(bounds);
|
||||
let items = items.into_iter().flat_map(|item| {
|
||||
folder.fold_trait_item(item).into_iter()
|
||||
}).collect();
|
||||
ItemTrait(unsafety,
|
||||
folder.fold_generics(generics),
|
||||
bounds,
|
||||
items)
|
||||
let items = items.into_iter()
|
||||
.flat_map(|item| folder.fold_trait_item(item).into_iter())
|
||||
.collect();
|
||||
ItemTrait(unsafety, folder.fold_generics(generics), bounds, items)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_trait_item<T: Folder>(i: P<TraitItem>, folder: &mut T)
|
||||
pub fn noop_fold_trait_item<T: Folder>(i: P<TraitItem>,
|
||||
folder: &mut T)
|
||||
-> SmallVector<P<TraitItem>> {
|
||||
SmallVector::one(i.map(|TraitItem {id, name, attrs, node, span}| TraitItem {
|
||||
SmallVector::one(i.map(|TraitItem { id, name, attrs, node, span }| {
|
||||
TraitItem {
|
||||
id: folder.new_id(id),
|
||||
name: folder.fold_name(name),
|
||||
attrs: fold_attrs(attrs, folder),
|
||||
|
@ -859,13 +886,14 @@ pub fn noop_fold_trait_item<T: Folder>(i: P<TraitItem>, folder: &mut T)
|
|||
default.map(|x| folder.fold_ty(x)))
|
||||
}
|
||||
},
|
||||
span: folder.new_span(span)
|
||||
span: folder.new_span(span),
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn noop_fold_impl_item<T: Folder>(i: P<ImplItem>, folder: &mut T)
|
||||
-> SmallVector<P<ImplItem>> {
|
||||
SmallVector::one(i.map(|ImplItem {id, name, attrs, node, vis, span}| ImplItem {
|
||||
pub fn noop_fold_impl_item<T: Folder>(i: P<ImplItem>, folder: &mut T) -> SmallVector<P<ImplItem>> {
|
||||
SmallVector::one(i.map(|ImplItem { id, name, attrs, node, vis, span }| {
|
||||
ImplItem {
|
||||
id: folder.new_id(id),
|
||||
name: folder.fold_name(name),
|
||||
attrs: fold_attrs(attrs, folder),
|
||||
|
@ -880,19 +908,21 @@ pub fn noop_fold_impl_item<T: Folder>(i: P<ImplItem>, folder: &mut T)
|
|||
}
|
||||
TypeImplItem(ty) => TypeImplItem(folder.fold_ty(ty)),
|
||||
},
|
||||
span: folder.new_span(span)
|
||||
span: folder.new_span(span),
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn noop_fold_mod<T: Folder>(Mod {inner, items}: Mod, folder: &mut T) -> Mod {
|
||||
pub fn noop_fold_mod<T: Folder>(Mod { inner, items }: Mod, folder: &mut T) -> Mod {
|
||||
Mod {
|
||||
inner: folder.new_span(inner),
|
||||
items: items.into_iter().flat_map(|x| folder.fold_item(x).into_iter()).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, config, span, exported_macros}: Crate,
|
||||
folder: &mut T) -> Crate {
|
||||
pub fn noop_fold_crate<T: Folder>(Crate { module, attrs, config, span, exported_macros }: Crate,
|
||||
folder: &mut T)
|
||||
-> Crate {
|
||||
let config = folder.fold_meta_items(config);
|
||||
|
||||
let mut items = folder.fold_item(P(hir::Item {
|
||||
|
@ -902,7 +932,8 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, config, span, exported_m
|
|||
vis: hir::Public,
|
||||
span: span,
|
||||
node: hir::ItemMod(module),
|
||||
})).into_iter();
|
||||
}))
|
||||
.into_iter();
|
||||
|
||||
let (module, attrs, span) = match items.next() {
|
||||
Some(item) => {
|
||||
|
@ -918,7 +949,9 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, config, span, exported_m
|
|||
None => (hir::Mod {
|
||||
inner: span,
|
||||
items: vec![],
|
||||
}, vec![], span)
|
||||
},
|
||||
vec![],
|
||||
span),
|
||||
};
|
||||
|
||||
Crate {
|
||||
|
@ -936,8 +969,9 @@ pub fn noop_fold_item<T: Folder>(i: P<Item>, folder: &mut T) -> SmallVector<P<It
|
|||
}
|
||||
|
||||
// fold one item into exactly one item
|
||||
pub fn noop_fold_item_simple<T: Folder>(Item {id, name, attrs, node, vis, span}: Item,
|
||||
folder: &mut T) -> Item {
|
||||
pub fn noop_fold_item_simple<T: Folder>(Item { id, name, attrs, node, vis, span }: Item,
|
||||
folder: &mut T)
|
||||
-> Item {
|
||||
let id = folder.new_id(id);
|
||||
let node = folder.fold_item_underscore(node);
|
||||
// FIXME: we should update the impl_pretty_name, but it uses pretty printing.
|
||||
|
@ -955,25 +989,28 @@ pub fn noop_fold_item_simple<T: Folder>(Item {id, name, attrs, node, vis, span}:
|
|||
attrs: fold_attrs(attrs, folder),
|
||||
node: node,
|
||||
vis: vis,
|
||||
span: folder.new_span(span)
|
||||
span: folder.new_span(span),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) -> P<ForeignItem> {
|
||||
ni.map(|ForeignItem {id, name, attrs, node, span, vis}| ForeignItem {
|
||||
ni.map(|ForeignItem { id, name, attrs, node, span, vis }| {
|
||||
ForeignItem {
|
||||
id: folder.new_id(id),
|
||||
name: folder.fold_name(name),
|
||||
attrs: fold_attrs(attrs, folder),
|
||||
node: match node {
|
||||
ForeignItemFn(fdec, generics) => {
|
||||
ForeignItemFn(folder.fold_fn_decl(fdec), folder.fold_generics(generics))
|
||||
ForeignItemFn(folder.fold_fn_decl(fdec),
|
||||
folder.fold_generics(generics))
|
||||
}
|
||||
ForeignItemStatic(t, m) => {
|
||||
ForeignItemStatic(folder.fold_ty(t), m)
|
||||
}
|
||||
},
|
||||
vis: vis,
|
||||
span: folder.new_span(span)
|
||||
span: folder.new_span(span),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -984,19 +1021,22 @@ pub fn noop_fold_method_sig<T: Folder>(sig: MethodSig, folder: &mut T) -> Method
|
|||
explicit_self: folder.fold_explicit_self(sig.explicit_self),
|
||||
unsafety: sig.unsafety,
|
||||
constness: sig.constness,
|
||||
decl: folder.fold_fn_decl(sig.decl)
|
||||
decl: folder.fold_fn_decl(sig.decl),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
|
||||
p.map(|Pat {id, node, span}| Pat {
|
||||
p.map(|Pat { id, node, span }| {
|
||||
Pat {
|
||||
id: folder.new_id(id),
|
||||
node: match node {
|
||||
PatWild(k) => PatWild(k),
|
||||
PatIdent(binding_mode, pth1, sub) => {
|
||||
PatIdent(binding_mode,
|
||||
Spanned{span: folder.new_span(pth1.span),
|
||||
node: folder.fold_ident(pth1.node)},
|
||||
Spanned {
|
||||
span: folder.new_span(pth1.span),
|
||||
node: folder.fold_ident(pth1.node),
|
||||
},
|
||||
sub.map(|x| folder.fold_pat(x)))
|
||||
}
|
||||
PatLit(e) => PatLit(folder.fold_expr(e)),
|
||||
|
@ -1005,18 +1045,20 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
|
|||
pats.map(|pats| pats.move_map(|x| folder.fold_pat(x))))
|
||||
}
|
||||
PatQPath(qself, pth) => {
|
||||
let qself = QSelf {ty: folder.fold_ty(qself.ty), .. qself};
|
||||
let qself = QSelf { ty: folder.fold_ty(qself.ty), ..qself };
|
||||
PatQPath(qself, folder.fold_path(pth))
|
||||
}
|
||||
PatStruct(pth, fields, etc) => {
|
||||
let pth = folder.fold_path(pth);
|
||||
let fs = fields.move_map(|f| {
|
||||
Spanned { span: folder.new_span(f.span),
|
||||
Spanned {
|
||||
span: folder.new_span(f.span),
|
||||
node: hir::FieldPat {
|
||||
name: f.node.name,
|
||||
pat: folder.fold_pat(f.node.pat),
|
||||
is_shorthand: f.node.is_shorthand,
|
||||
}}
|
||||
},
|
||||
}
|
||||
});
|
||||
PatStruct(pth, fs, etc)
|
||||
}
|
||||
|
@ -1025,18 +1067,19 @@ pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
|
|||
PatRegion(inner, mutbl) => PatRegion(folder.fold_pat(inner), mutbl),
|
||||
PatRange(e1, e2) => {
|
||||
PatRange(folder.fold_expr(e1), folder.fold_expr(e2))
|
||||
},
|
||||
}
|
||||
PatVec(before, slice, after) => {
|
||||
PatVec(before.move_map(|x| folder.fold_pat(x)),
|
||||
slice.map(|x| folder.fold_pat(x)),
|
||||
after.move_map(|x| folder.fold_pat(x)))
|
||||
}
|
||||
},
|
||||
span: folder.new_span(span)
|
||||
span: folder.new_span(span),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) -> Expr {
|
||||
pub fn noop_fold_expr<T: Folder>(Expr { id, node, span }: Expr, folder: &mut T) -> Expr {
|
||||
Expr {
|
||||
id: folder.new_id(id),
|
||||
node: match node {
|
||||
|
@ -1055,15 +1098,13 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
|
|||
args.move_map(|x| folder.fold_expr(x)))
|
||||
}
|
||||
ExprMethodCall(name, tps, args) => {
|
||||
ExprMethodCall(
|
||||
respan(folder.new_span(name.span), folder.fold_name(name.node)),
|
||||
ExprMethodCall(respan(folder.new_span(name.span),
|
||||
folder.fold_name(name.node)),
|
||||
tps.move_map(|x| folder.fold_ty(x)),
|
||||
args.move_map(|x| folder.fold_expr(x)))
|
||||
}
|
||||
ExprBinary(binop, lhs, rhs) => {
|
||||
ExprBinary(binop,
|
||||
folder.fold_expr(lhs),
|
||||
folder.fold_expr(rhs))
|
||||
ExprBinary(binop, folder.fold_expr(lhs), folder.fold_expr(rhs))
|
||||
}
|
||||
ExprUnary(binop, ohs) => {
|
||||
ExprUnary(binop, folder.fold_expr(ohs))
|
||||
|
@ -1102,9 +1143,7 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
|
|||
ExprAssign(folder.fold_expr(el), folder.fold_expr(er))
|
||||
}
|
||||
ExprAssignOp(op, el, er) => {
|
||||
ExprAssignOp(op,
|
||||
folder.fold_expr(el),
|
||||
folder.fold_expr(er))
|
||||
ExprAssignOp(op, folder.fold_expr(el), folder.fold_expr(er))
|
||||
}
|
||||
ExprField(el, name) => {
|
||||
ExprField(folder.fold_expr(el),
|
||||
|
@ -1127,19 +1166,19 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
|
|||
let qself = qself.map(|QSelf { ty, position }| {
|
||||
QSelf {
|
||||
ty: folder.fold_ty(ty),
|
||||
position: position
|
||||
position: position,
|
||||
}
|
||||
});
|
||||
ExprPath(qself, folder.fold_path(path))
|
||||
}
|
||||
ExprBreak(opt_ident) => ExprBreak(opt_ident.map(|label|
|
||||
ExprBreak(opt_ident) => ExprBreak(opt_ident.map(|label| {
|
||||
respan(folder.new_span(label.span),
|
||||
folder.fold_ident(label.node)))
|
||||
),
|
||||
ExprAgain(opt_ident) => ExprAgain(opt_ident.map(|label|
|
||||
folder.fold_ident(label.node))
|
||||
})),
|
||||
ExprAgain(opt_ident) => ExprAgain(opt_ident.map(|label| {
|
||||
respan(folder.new_span(label.span),
|
||||
folder.fold_ident(label.node)))
|
||||
),
|
||||
folder.fold_ident(label.node))
|
||||
})),
|
||||
ExprRet(e) => ExprRet(e.map(|x| folder.fold_expr(x))),
|
||||
ExprInlineAsm(InlineAsm {
|
||||
inputs,
|
||||
|
@ -1152,12 +1191,8 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
|
|||
dialect,
|
||||
expn_id,
|
||||
}) => ExprInlineAsm(InlineAsm {
|
||||
inputs: inputs.move_map(|(c, input)| {
|
||||
(c, folder.fold_expr(input))
|
||||
}),
|
||||
outputs: outputs.move_map(|(c, out, is_rw)| {
|
||||
(c, folder.fold_expr(out), is_rw)
|
||||
}),
|
||||
inputs: inputs.move_map(|(c, input)| (c, folder.fold_expr(input))),
|
||||
outputs: outputs.move_map(|(c, out, is_rw)| (c, folder.fold_expr(out), is_rw)),
|
||||
asm: asm,
|
||||
asm_str_style: asm_str_style,
|
||||
clobbers: clobbers,
|
||||
|
@ -1170,35 +1205,41 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
|
|||
ExprStruct(folder.fold_path(path),
|
||||
fields.move_map(|x| folder.fold_field(x)),
|
||||
maybe_expr.map(|x| folder.fold_expr(x)))
|
||||
}
|
||||
},
|
||||
},
|
||||
span: folder.new_span(span)
|
||||
span: folder.new_span(span),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_stmt<T: Folder>(Spanned {node, span}: Stmt, folder: &mut T)
|
||||
pub fn noop_fold_stmt<T: Folder>(Spanned { node, span }: Stmt,
|
||||
folder: &mut T)
|
||||
-> SmallVector<P<Stmt>> {
|
||||
let span = folder.new_span(span);
|
||||
match node {
|
||||
StmtDecl(d, id) => {
|
||||
let id = folder.new_id(id);
|
||||
folder.fold_decl(d).into_iter().map(|d| P(Spanned {
|
||||
folder.fold_decl(d)
|
||||
.into_iter()
|
||||
.map(|d| {
|
||||
P(Spanned {
|
||||
node: StmtDecl(d, id),
|
||||
span: span
|
||||
})).collect()
|
||||
span: span,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
StmtExpr(e, id) => {
|
||||
let id = folder.new_id(id);
|
||||
SmallVector::one(P(Spanned {
|
||||
node: StmtExpr(folder.fold_expr(e), id),
|
||||
span: span
|
||||
span: span,
|
||||
}))
|
||||
}
|
||||
StmtSemi(e, id) => {
|
||||
let id = folder.new_id(id);
|
||||
SmallVector::one(P(Spanned {
|
||||
node: StmtSemi(folder.fold_expr(e), id),
|
||||
span: span
|
||||
span: span,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)]
|
||||
|
@ -924,7 +934,8 @@ impl fmt::Display for Unsafety {
|
|||
fmt::Display::fmt(match *self {
|
||||
Unsafety::Normal => "normal",
|
||||
Unsafety::Unsafe => "unsafe",
|
||||
}, f)
|
||||
},
|
||||
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",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@ 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| {
|
||||
path_list_idents.iter()
|
||||
.map(|path_list_ident| {
|
||||
Spanned {
|
||||
node: match path_list_ident.node {
|
||||
PathListIdent { id, name, rename } =>
|
||||
|
@ -41,12 +42,13 @@ pub fn lower_view_path(view_path: &ViewPath) -> P<hir::ViewPath> {
|
|||
PathListMod { id, rename } =>
|
||||
hir::PathListMod {
|
||||
id: id,
|
||||
rename: rename.map(|x| x.name)
|
||||
}
|
||||
rename: rename.map(|x| x.name),
|
||||
},
|
||||
span: path_list_ident.span
|
||||
},
|
||||
span: path_list_ident.span,
|
||||
}
|
||||
}).collect())
|
||||
})
|
||||
.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}|
|
||||
segments: p.segments
|
||||
.iter()
|
||||
.map(|&PathSegment { identifier, ref parameters }| {
|
||||
hir::PathSegment {
|
||||
identifier: identifier,
|
||||
parameters: lower_path_parameters(parameters),
|
||||
}).collect(),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
span: p.span,
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
hir::ItemFn(lower_fn_decl(decl),
|
||||
lower_unsafety(unsafety),
|
||||
lower_constness(constness),
|
||||
abi,
|
||||
lower_generics(generics),
|
||||
lower_block(body)
|
||||
)
|
||||
lower_block(body))
|
||||
}
|
||||
ItemMod(ref m) => hir::ItemMod(lower_mod(m)),
|
||||
ItemForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(nm)),
|
||||
|
@ -434,9 +472,11 @@ 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(),
|
||||
hir::ItemEnum(hir::EnumDef {
|
||||
variants: enum_definition.variants
|
||||
.iter()
|
||||
.map(|x| lower_variant(x))
|
||||
.collect(),
|
||||
},
|
||||
lower_generics(generics))
|
||||
}
|
||||
|
@ -503,8 +543,7 @@ pub fn lower_impl_item(i: &ImplItem) -> P<hir::ImplItem> {
|
|||
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"),
|
||||
|
@ -514,7 +553,10 @@ pub fn lower_impl_item(i: &ImplItem) -> P<hir::ImplItem> {
|
|||
}
|
||||
|
||||
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 {
|
||||
|
@ -661,23 +703,27 @@ 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,
|
||||
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();
|
||||
},
|
||||
}
|
||||
})
|
||||
.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)),
|
||||
|
@ -708,15 +754,12 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
|
|||
args.iter().map(|x| lower_expr(x)).collect())
|
||||
}
|
||||
ExprMethodCall(i, ref tps, ref args) => {
|
||||
hir::ExprMethodCall(
|
||||
respan(i.span, i.node.name),
|
||||
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))
|
||||
hir::ExprBinary(lower_binop(binop), lower_expr(lhs), lower_expr(rhs))
|
||||
}
|
||||
ExprUnary(op, ref ohs) => {
|
||||
hir::ExprUnary(lower_unop(op), lower_expr(ohs))
|
||||
|
@ -732,13 +775,10 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
|
|||
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)
|
||||
hir::ExprWhile(lower_expr(cond), lower_block(body), opt_ident)
|
||||
}
|
||||
ExprLoop(ref body, opt_ident) => {
|
||||
hir::ExprLoop(lower_block(body),
|
||||
opt_ident)
|
||||
hir::ExprLoop(lower_block(body), opt_ident)
|
||||
}
|
||||
ExprMatch(ref expr, ref arms, ref source) => {
|
||||
hir::ExprMatch(lower_expr(expr),
|
||||
|
@ -755,9 +795,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
|
|||
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))
|
||||
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))
|
||||
|
@ -776,7 +814,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
|
|||
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
|
||||
hir::QSelf {
|
||||
ty: lower_ty(ty),
|
||||
position: position
|
||||
position: position,
|
||||
}
|
||||
});
|
||||
hir::ExprPath(qself, lower_path(path))
|
||||
|
@ -795,12 +833,14 @@ 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)| {
|
||||
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(),
|
||||
})
|
||||
.collect(),
|
||||
asm: asm.clone(),
|
||||
asm_str_style: asm_str_style,
|
||||
clobbers: clobbers.clone(),
|
||||
|
@ -813,7 +853,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::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);
|
||||
}
|
||||
|
@ -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
|
@ -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 => ">",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +99,7 @@ pub fn lazy_binop(b: BinOp_) -> bool {
|
|||
match b {
|
||||
BiAnd => true,
|
||||
BiOr => true,
|
||||
_ => false
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,17 +107,25 @@ pub fn is_shift_binop(b: BinOp_) -> bool {
|
|||
match b {
|
||||
BiShl => true,
|
||||
BiShr => true,
|
||||
_ => false
|
||||
_ => 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 {
|
||||
segments: vec!(hir::PathSegment {
|
||||
identifier: ident,
|
||||
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
|
||||
lifetimes: Vec::new(),
|
||||
types: OwnedSlice::empty(),
|
||||
bindings: OwnedSlice::empty(),
|
||||
})
|
||||
}
|
||||
),
|
||||
}),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue