mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-01 22:18:23 +03:00
Auto merge of #28697 - nrc:fmt7, r=brson
This commit is contained in:
+433
-392
@@ -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 @@ fn move_map<F>(mut self, mut f: F) -> Vec<T> where F: FnMut(T) -> 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 @@ fn fold_path_parameters(&mut self, p: PathParameters) -> PathParameters {
|
||||
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 @@ fn fold_variant_arg(&mut self, va: VariantArg) -> VariantArg {
|
||||
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 @@ fn fold_field(&mut self, field: Field) -> Field {
|
||||
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,43 +290,44 @@ fn new_span(&mut self, sp: Span) -> Span {
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
node: match node {
|
||||
ViewPathSimple(name, path) => {
|
||||
ViewPathSimple(name, fld.fold_path(path))
|
||||
}
|
||||
ViewPathGlob(path) => {
|
||||
ViewPathGlob(fld.fold_path(path))
|
||||
}
|
||||
ViewPathList(path, path_list_idents) => {
|
||||
ViewPathList(fld.fold_path(path),
|
||||
path_list_idents.move_map(|path_list_ident| {
|
||||
Spanned {
|
||||
node: match path_list_ident.node {
|
||||
PathListIdent { id, name, rename } =>
|
||||
PathListIdent {
|
||||
id: fld.new_id(id),
|
||||
name: name,
|
||||
rename: rename,
|
||||
},
|
||||
PathListMod { id, rename } =>
|
||||
PathListMod {
|
||||
id: fld.new_id(id),
|
||||
rename: rename,
|
||||
}
|
||||
},
|
||||
span: fld.new_span(path_list_ident.span)
|
||||
}
|
||||
}))
|
||||
}
|
||||
},
|
||||
span: fld.new_span(span)
|
||||
view_path.map(|Spanned { node, span }| {
|
||||
Spanned {
|
||||
node: match node {
|
||||
ViewPathSimple(name, path) => {
|
||||
ViewPathSimple(name, fld.fold_path(path))
|
||||
}
|
||||
ViewPathGlob(path) => {
|
||||
ViewPathGlob(fld.fold_path(path))
|
||||
}
|
||||
ViewPathList(path, path_list_idents) => {
|
||||
ViewPathList(fld.fold_path(path),
|
||||
path_list_idents.move_map(|path_list_ident| {
|
||||
Spanned {
|
||||
node: match path_list_ident.node {
|
||||
PathListIdent { id, name, rename } => PathListIdent {
|
||||
id: fld.new_id(id),
|
||||
name: name,
|
||||
rename: rename,
|
||||
},
|
||||
PathListMod { id, rename } => PathListMod {
|
||||
id: fld.new_id(id),
|
||||
rename: rename,
|
||||
},
|
||||
},
|
||||
span: fld.new_span(path_list_ident.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,76 +345,89 @@ 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 {
|
||||
DeclLocal(l) => SmallVector::one(P(Spanned {
|
||||
node: DeclLocal(fld.fold_local(l)),
|
||||
span: fld.new_span(span)
|
||||
})),
|
||||
DeclItem(it) => fld.fold_item(it).into_iter().map(|i| P(Spanned {
|
||||
node: DeclItem(i),
|
||||
span: fld.new_span(span)
|
||||
})).collect()
|
||||
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),
|
||||
})),
|
||||
DeclItem(it) => fld.fold_item(it)
|
||||
.into_iter()
|
||||
.map(|i| {
|
||||
P(Spanned {
|
||||
node: DeclItem(i),
|
||||
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 {
|
||||
id: fld.new_id(id),
|
||||
name: name,
|
||||
ty: fld.fold_ty(ty),
|
||||
span: fld.new_span(span),
|
||||
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 {
|
||||
id: fld.new_id(id),
|
||||
node: match node {
|
||||
TyInfer => node,
|
||||
TyVec(ty) => TyVec(fld.fold_ty(ty)),
|
||||
TyPtr(mt) => TyPtr(fld.fold_mt(mt)),
|
||||
TyRptr(region, mt) => {
|
||||
TyRptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt))
|
||||
}
|
||||
TyBareFn(f) => {
|
||||
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)
|
||||
}))
|
||||
}
|
||||
TyTup(tys) => TyTup(tys.move_map(|ty| fld.fold_ty(ty))),
|
||||
TyParen(ty) => TyParen(fld.fold_ty(ty)),
|
||||
TyPath(qself, path) => {
|
||||
let qself = qself.map(|QSelf { ty, position }| {
|
||||
QSelf {
|
||||
ty: fld.fold_ty(ty),
|
||||
position: position
|
||||
}
|
||||
});
|
||||
TyPath(qself, fld.fold_path(path))
|
||||
}
|
||||
TyObjectSum(ty, bounds) => {
|
||||
TyObjectSum(fld.fold_ty(ty),
|
||||
fld.fold_bounds(bounds))
|
||||
}
|
||||
TyFixedLengthVec(ty, e) => {
|
||||
TyFixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e))
|
||||
}
|
||||
TyTypeof(expr) => {
|
||||
TyTypeof(fld.fold_expr(expr))
|
||||
}
|
||||
TyPolyTraitRef(bounds) => {
|
||||
TyPolyTraitRef(bounds.move_map(|b| fld.fold_ty_param_bound(b)))
|
||||
}
|
||||
},
|
||||
span: fld.new_span(span)
|
||||
t.map(|Ty { id, node, span }| {
|
||||
Ty {
|
||||
id: fld.new_id(id),
|
||||
node: match node {
|
||||
TyInfer => node,
|
||||
TyVec(ty) => TyVec(fld.fold_ty(ty)),
|
||||
TyPtr(mt) => TyPtr(fld.fold_mt(mt)),
|
||||
TyRptr(region, mt) => {
|
||||
TyRptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt))
|
||||
}
|
||||
TyBareFn(f) => {
|
||||
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),
|
||||
}
|
||||
}))
|
||||
}
|
||||
TyTup(tys) => TyTup(tys.move_map(|ty| fld.fold_ty(ty))),
|
||||
TyParen(ty) => TyParen(fld.fold_ty(ty)),
|
||||
TyPath(qself, path) => {
|
||||
let qself = qself.map(|QSelf { ty, position }| {
|
||||
QSelf {
|
||||
ty: fld.fold_ty(ty),
|
||||
position: position,
|
||||
}
|
||||
});
|
||||
TyPath(qself, fld.fold_path(path))
|
||||
}
|
||||
TyObjectSum(ty, bounds) => {
|
||||
TyObjectSum(fld.fold_ty(ty), fld.fold_bounds(bounds))
|
||||
}
|
||||
TyFixedLengthVec(ty, e) => {
|
||||
TyFixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e))
|
||||
}
|
||||
TyTypeof(expr) => {
|
||||
TyTypeof(fld.fold_expr(expr))
|
||||
}
|
||||
TyPolyTraitRef(bounds) => {
|
||||
TyPolyTraitRef(bounds.move_map(|b| fld.fold_ty_param_bound(b)))
|
||||
}
|
||||
},
|
||||
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,23 +435,24 @@ 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 {
|
||||
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)))
|
||||
}
|
||||
StructVariantKind(struct_def) => {
|
||||
StructVariantKind(fld.fold_struct_def(struct_def))
|
||||
}
|
||||
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)))
|
||||
}
|
||||
StructVariantKind(struct_def) => {
|
||||
StructVariantKind(fld.fold_struct_def(struct_def))
|
||||
}
|
||||
},
|
||||
disr_expr: disr_expr.map(|e| fld.fold_expr(e)),
|
||||
},
|
||||
disr_expr: disr_expr.map(|e| fld.fold_expr(e)),
|
||||
},
|
||||
span: fld.new_span(span),
|
||||
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 {
|
||||
identifier: fld.fold_ident(identifier),
|
||||
parameters: fld.fold_path_parameters(parameters),
|
||||
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),
|
||||
types: types.move_map(|ty| fld.fold_ty(ty)),
|
||||
bindings: bindings.move_map(|b| fld.fold_ty_binding(b)) }
|
||||
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)),
|
||||
}
|
||||
}
|
||||
|
||||
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)),
|
||||
output: output.map(|ty| fld.fold_ty(ty)),
|
||||
span: fld.new_span(span) }
|
||||
ParenthesizedParameterData {
|
||||
inputs: inputs.move_map(|ty| fld.fold_ty(ty)),
|
||||
output: output.map(|ty| fld.fold_ty(ty)),
|
||||
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 {
|
||||
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)
|
||||
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),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
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)
|
||||
},
|
||||
span: fld.new_span(span)
|
||||
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),
|
||||
},
|
||||
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 {
|
||||
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)
|
||||
},
|
||||
variadic: variadic
|
||||
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),
|
||||
},
|
||||
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,
|
||||
fld: &mut T)
|
||||
-> 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 {
|
||||
fields: fields.move_map(|f| fld.fold_struct_field(f)),
|
||||
ctor_id: ctor_id.map(|cid| fld.new_id(cid)),
|
||||
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 {
|
||||
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),
|
||||
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),
|
||||
unsafety,
|
||||
constness,
|
||||
abi,
|
||||
folder.fold_generics(generics),
|
||||
folder.fold_block(body)
|
||||
)
|
||||
ItemFn(folder.fold_fn_decl(decl),
|
||||
unsafety,
|
||||
constness,
|
||||
abi,
|
||||
folder.fold_generics(generics),
|
||||
folder.fold_block(body))
|
||||
}
|
||||
ItemMod(m) => ItemMod(folder.fold_mod(m)),
|
||||
ItemForeignMod(nm) => ItemForeignMod(folder.fold_foreign_mod(nm)),
|
||||
@@ -796,23 +822,25 @@ 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 {
|
||||
variants: enum_definition.variants.move_map(|x| folder.fold_variant(x)),
|
||||
},
|
||||
folder.fold_generics(generics))
|
||||
ItemEnum(hir::EnumDef {
|
||||
variants: enum_definition.variants.move_map(|x| folder.fold_variant(x)),
|
||||
},
|
||||
folder.fold_generics(generics))
|
||||
}
|
||||
ItemStruct(struct_def, generics) => {
|
||||
let struct_def = folder.fold_struct_def(struct_def);
|
||||
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| {
|
||||
folder.fold_impl_item(item).into_iter()
|
||||
}).collect();
|
||||
let new_impl_items = impl_items.into_iter()
|
||||
.flat_map(|item| {
|
||||
folder.fold_impl_item(item).into_iter()
|
||||
})
|
||||
.collect();
|
||||
let ifce = match ifce {
|
||||
None => None,
|
||||
Some(ref trait_ref) => {
|
||||
@@ -828,81 +856,84 @@ 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 {
|
||||
id: folder.new_id(id),
|
||||
name: folder.fold_name(name),
|
||||
attrs: fold_attrs(attrs, folder),
|
||||
node: match node {
|
||||
ConstTraitItem(ty, default) => {
|
||||
ConstTraitItem(folder.fold_ty(ty),
|
||||
default.map(|x| folder.fold_expr(x)))
|
||||
}
|
||||
MethodTraitItem(sig, body) => {
|
||||
MethodTraitItem(noop_fold_method_sig(sig, folder),
|
||||
body.map(|x| folder.fold_block(x)))
|
||||
}
|
||||
TypeTraitItem(bounds, default) => {
|
||||
TypeTraitItem(folder.fold_bounds(bounds),
|
||||
default.map(|x| folder.fold_ty(x)))
|
||||
}
|
||||
},
|
||||
span: folder.new_span(span)
|
||||
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),
|
||||
node: match node {
|
||||
ConstTraitItem(ty, default) => {
|
||||
ConstTraitItem(folder.fold_ty(ty),
|
||||
default.map(|x| folder.fold_expr(x)))
|
||||
}
|
||||
MethodTraitItem(sig, body) => {
|
||||
MethodTraitItem(noop_fold_method_sig(sig, folder),
|
||||
body.map(|x| folder.fold_block(x)))
|
||||
}
|
||||
TypeTraitItem(bounds, default) => {
|
||||
TypeTraitItem(folder.fold_bounds(bounds),
|
||||
default.map(|x| folder.fold_ty(x)))
|
||||
}
|
||||
},
|
||||
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 {
|
||||
id: folder.new_id(id),
|
||||
name: folder.fold_name(name),
|
||||
attrs: fold_attrs(attrs, folder),
|
||||
vis: vis,
|
||||
node: match node {
|
||||
ConstImplItem(ty, expr) => {
|
||||
ConstImplItem(folder.fold_ty(ty), folder.fold_expr(expr))
|
||||
}
|
||||
MethodImplItem(sig, body) => {
|
||||
MethodImplItem(noop_fold_method_sig(sig, folder),
|
||||
folder.fold_block(body))
|
||||
}
|
||||
TypeImplItem(ty) => TypeImplItem(folder.fold_ty(ty)),
|
||||
},
|
||||
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 {
|
||||
id: folder.new_id(id),
|
||||
name: folder.fold_name(name),
|
||||
attrs: fold_attrs(attrs, folder),
|
||||
vis: vis,
|
||||
node: match node {
|
||||
ConstImplItem(ty, expr) => {
|
||||
ConstImplItem(folder.fold_ty(ty), folder.fold_expr(expr))
|
||||
}
|
||||
MethodImplItem(sig, body) => {
|
||||
MethodImplItem(noop_fold_method_sig(sig, folder),
|
||||
folder.fold_block(body))
|
||||
}
|
||||
TypeImplItem(ty) => TypeImplItem(folder.fold_ty(ty)),
|
||||
},
|
||||
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 {
|
||||
name: token::special_idents::invalid.name,
|
||||
attrs: attrs,
|
||||
id: DUMMY_NODE_ID,
|
||||
vis: hir::Public,
|
||||
span: span,
|
||||
node: hir::ItemMod(module),
|
||||
})).into_iter();
|
||||
name: token::special_idents::invalid.name,
|
||||
attrs: attrs,
|
||||
id: DUMMY_NODE_ID,
|
||||
vis: hir::Public,
|
||||
span: span,
|
||||
node: hir::ItemMod(module),
|
||||
}))
|
||||
.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 {
|
||||
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))
|
||||
}
|
||||
ForeignItemStatic(t, m) => {
|
||||
ForeignItemStatic(folder.fold_ty(t), m)
|
||||
}
|
||||
},
|
||||
vis: vis,
|
||||
span: folder.new_span(span)
|
||||
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))
|
||||
}
|
||||
ForeignItemStatic(t, m) => {
|
||||
ForeignItemStatic(folder.fold_ty(t), m)
|
||||
}
|
||||
},
|
||||
vis: vis,
|
||||
span: folder.new_span(span),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -984,59 +1021,65 @@ 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 {
|
||||
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)},
|
||||
sub.map(|x| folder.fold_pat(x)))
|
||||
}
|
||||
PatLit(e) => PatLit(folder.fold_expr(e)),
|
||||
PatEnum(pth, pats) => {
|
||||
PatEnum(folder.fold_path(pth),
|
||||
pats.map(|pats| pats.move_map(|x| folder.fold_pat(x))))
|
||||
}
|
||||
PatQPath(qself, pth) => {
|
||||
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),
|
||||
node: hir::FieldPat {
|
||||
name: f.node.name,
|
||||
pat: folder.fold_pat(f.node.pat),
|
||||
is_shorthand: f.node.is_shorthand,
|
||||
}}
|
||||
});
|
||||
PatStruct(pth, fs, etc)
|
||||
}
|
||||
PatTup(elts) => PatTup(elts.move_map(|x| folder.fold_pat(x))),
|
||||
PatBox(inner) => PatBox(folder.fold_pat(inner)),
|
||||
PatRegion(inner, mutbl) => PatRegion(folder.fold_pat(inner), mutbl),
|
||||
PatRange(e1, e2) => {
|
||||
PatRange(folder.fold_expr(e1), folder.fold_expr(e2))
|
||||
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),
|
||||
},
|
||||
sub.map(|x| folder.fold_pat(x)))
|
||||
}
|
||||
PatLit(e) => PatLit(folder.fold_expr(e)),
|
||||
PatEnum(pth, pats) => {
|
||||
PatEnum(folder.fold_path(pth),
|
||||
pats.map(|pats| pats.move_map(|x| folder.fold_pat(x))))
|
||||
}
|
||||
PatQPath(qself, pth) => {
|
||||
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),
|
||||
node: hir::FieldPat {
|
||||
name: f.node.name,
|
||||
pat: folder.fold_pat(f.node.pat),
|
||||
is_shorthand: f.node.is_shorthand,
|
||||
},
|
||||
}
|
||||
});
|
||||
PatStruct(pth, fs, etc)
|
||||
}
|
||||
PatTup(elts) => PatTup(elts.move_map(|x| folder.fold_pat(x))),
|
||||
PatBox(inner) => PatBox(folder.fold_pat(inner)),
|
||||
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)))
|
||||
}
|
||||
},
|
||||
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)),
|
||||
tps.move_map(|x| folder.fold_ty(x)),
|
||||
args.move_map(|x| folder.fold_expr(x)))
|
||||
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))
|
||||
@@ -1085,12 +1126,12 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
|
||||
}
|
||||
ExprLoop(body, opt_ident) => {
|
||||
ExprLoop(folder.fold_block(body),
|
||||
opt_ident.map(|i| folder.fold_ident(i)))
|
||||
opt_ident.map(|i| folder.fold_ident(i)))
|
||||
}
|
||||
ExprMatch(expr, arms, source) => {
|
||||
ExprMatch(folder.fold_expr(expr),
|
||||
arms.move_map(|x| folder.fold_arm(x)),
|
||||
source)
|
||||
arms.move_map(|x| folder.fold_arm(x)),
|
||||
source)
|
||||
}
|
||||
ExprClosure(capture_clause, decl, body) => {
|
||||
ExprClosure(capture_clause,
|
||||
@@ -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,
|
||||
@@ -1168,37 +1203,43 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span}: Expr, folder: &mut T) ->
|
||||
}),
|
||||
ExprStruct(path, fields, maybe_expr) => {
|
||||
ExprStruct(folder.fold_path(path),
|
||||
fields.move_map(|x| folder.fold_field(x)),
|
||||
maybe_expr.map(|x| folder.fold_expr(x)))
|
||||
},
|
||||
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 {
|
||||
node: StmtDecl(d, id),
|
||||
span: span
|
||||
})).collect()
|
||||
folder.fold_decl(d)
|
||||
.into_iter()
|
||||
.map(|d| {
|
||||
P(Spanned {
|
||||
node: StmtDecl(d, id),
|
||||
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,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
+44
-36
@@ -56,12 +56,15 @@
|
||||
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 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
#[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 @@ pub fn types(&self) -> Vec<&P<Ty>> {
|
||||
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 @@ pub fn new_self(span: Span, mutability: Mutability, self_ident: Ident) -> 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 @@ pub fn new_self(span: Span, mutability: Mutability, self_ident: Ident) -> 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 @@ pub fn span(&self) -> Span {
|
||||
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 @@ pub fn name(&self) -> Option<Name> {
|
||||
|
||||
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 @@ pub fn descriptive_variant(&self) -> &str {
|
||||
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
|
||||
|
||||
|
||||
+280
-240
@@ -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"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+354
-349
@@ -39,8 +39,12 @@ pub enum AnnNode<'a> {
|
||||
}
|
||||
|
||||
pub trait PpAnn {
|
||||
fn pre(&self, _state: &mut State, _node: AnnNode) -> io::Result<()> { Ok(()) }
|
||||
fn post(&self, _state: &mut State, _node: AnnNode) -> io::Result<()> { Ok(()) }
|
||||
fn pre(&self, _state: &mut State, _node: AnnNode) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn post(&self, _state: &mut State, _node: AnnNode) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@@ -56,7 +60,7 @@ pub struct State<'a> {
|
||||
literals: Option<Vec<comments::Literal>>,
|
||||
cur_cmnt_and_lit: ast_pp::CurrentCommentAndLiteral,
|
||||
boxes: Vec<pp::Breaks>,
|
||||
ann: &'a (PpAnn+'a),
|
||||
ann: &'a (PpAnn + 'a),
|
||||
}
|
||||
|
||||
impl<'a> PrintState<'a> for State<'a> {
|
||||
@@ -81,13 +85,12 @@ fn literals(&self) -> &Option<Vec<comments::Literal>> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rust_printer<'a>(writer: Box<Write+'a>) -> State<'a> {
|
||||
pub fn rust_printer<'a>(writer: Box<Write + 'a>) -> State<'a> {
|
||||
static NO_ANN: NoAnn = NoAnn;
|
||||
rust_printer_annotated(writer, &NO_ANN)
|
||||
}
|
||||
|
||||
pub fn rust_printer_annotated<'a>(writer: Box<Write+'a>,
|
||||
ann: &'a PpAnn) -> State<'a> {
|
||||
pub fn rust_printer_annotated<'a>(writer: Box<Write + 'a>, ann: &'a PpAnn) -> State<'a> {
|
||||
State {
|
||||
s: pp::mk_printer(writer, default_columns),
|
||||
cm: None,
|
||||
@@ -95,7 +98,7 @@ pub fn rust_printer_annotated<'a>(writer: Box<Write+'a>,
|
||||
literals: None,
|
||||
cur_cmnt_and_lit: ast_pp::CurrentCommentAndLiteral {
|
||||
cur_cmnt: 0,
|
||||
cur_lit: 0
|
||||
cur_lit: 0,
|
||||
},
|
||||
boxes: Vec::new(),
|
||||
ann: ann,
|
||||
@@ -117,16 +120,11 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
|
||||
krate: &hir::Crate,
|
||||
filename: String,
|
||||
input: &mut Read,
|
||||
out: Box<Write+'a>,
|
||||
out: Box<Write + 'a>,
|
||||
ann: &'a PpAnn,
|
||||
is_expanded: bool) -> io::Result<()> {
|
||||
let mut s = State::new_from_input(cm,
|
||||
span_diagnostic,
|
||||
filename,
|
||||
input,
|
||||
out,
|
||||
ann,
|
||||
is_expanded);
|
||||
is_expanded: bool)
|
||||
-> io::Result<()> {
|
||||
let mut s = State::new_from_input(cm, span_diagnostic, filename, input, out, ann, is_expanded);
|
||||
|
||||
// When printing the AST, we sometimes need to inject `#[no_std]` here.
|
||||
// Since you can't compile the HIR, it's not necessary.
|
||||
@@ -141,30 +139,34 @@ pub fn new_from_input(cm: &'a CodeMap,
|
||||
span_diagnostic: &diagnostic::SpanHandler,
|
||||
filename: String,
|
||||
input: &mut Read,
|
||||
out: Box<Write+'a>,
|
||||
out: Box<Write + 'a>,
|
||||
ann: &'a PpAnn,
|
||||
is_expanded: bool) -> State<'a> {
|
||||
let (cmnts, lits) = comments::gather_comments_and_literals(
|
||||
span_diagnostic,
|
||||
filename,
|
||||
input);
|
||||
is_expanded: bool)
|
||||
-> State<'a> {
|
||||
let (cmnts, lits) = comments::gather_comments_and_literals(span_diagnostic,
|
||||
filename,
|
||||
input);
|
||||
|
||||
State::new(
|
||||
cm,
|
||||
out,
|
||||
ann,
|
||||
Some(cmnts),
|
||||
// If the code is post expansion, don't use the table of
|
||||
// literals, since it doesn't correspond with the literals
|
||||
// in the AST anymore.
|
||||
if is_expanded { None } else { Some(lits) })
|
||||
State::new(cm,
|
||||
out,
|
||||
ann,
|
||||
Some(cmnts),
|
||||
// If the code is post expansion, don't use the table of
|
||||
// literals, since it doesn't correspond with the literals
|
||||
// in the AST anymore.
|
||||
if is_expanded {
|
||||
None
|
||||
} else {
|
||||
Some(lits)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new(cm: &'a CodeMap,
|
||||
out: Box<Write+'a>,
|
||||
out: Box<Write + 'a>,
|
||||
ann: &'a PpAnn,
|
||||
comments: Option<Vec<comments::Comment>>,
|
||||
literals: Option<Vec<comments::Literal>>) -> State<'a> {
|
||||
literals: Option<Vec<comments::Literal>>)
|
||||
-> State<'a> {
|
||||
State {
|
||||
s: pp::mk_printer(out, default_columns),
|
||||
cm: Some(cm),
|
||||
@@ -172,7 +174,7 @@ pub fn new(cm: &'a CodeMap,
|
||||
literals: literals.clone(),
|
||||
cur_cmnt_and_lit: ast_pp::CurrentCommentAndLiteral {
|
||||
cur_cmnt: 0,
|
||||
cur_lit: 0
|
||||
cur_lit: 0,
|
||||
},
|
||||
boxes: Vec::new(),
|
||||
ann: ann,
|
||||
@@ -180,8 +182,8 @@ pub fn new(cm: &'a CodeMap,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_string<F>(f: F) -> String where
|
||||
F: FnOnce(&mut State) -> io::Result<()>,
|
||||
pub fn to_string<F>(f: F) -> String
|
||||
where F: FnOnce(&mut State) -> io::Result<()>
|
||||
{
|
||||
let mut wr = Vec::new();
|
||||
{
|
||||
@@ -194,16 +196,16 @@ pub fn to_string<F>(f: F) -> String where
|
||||
|
||||
pub fn binop_to_string(op: BinOpToken) -> &'static str {
|
||||
match op {
|
||||
token::Plus => "+",
|
||||
token::Minus => "-",
|
||||
token::Star => "*",
|
||||
token::Slash => "/",
|
||||
token::Percent => "%",
|
||||
token::Caret => "^",
|
||||
token::And => "&",
|
||||
token::Or => "|",
|
||||
token::Shl => "<<",
|
||||
token::Shr => ">>",
|
||||
token::Plus => "+",
|
||||
token::Minus => "-",
|
||||
token::Star => "*",
|
||||
token::Slash => "/",
|
||||
token::Percent => "%",
|
||||
token::Caret => "^",
|
||||
token::And => "&",
|
||||
token::Or => "|",
|
||||
token::Shl => "<<",
|
||||
token::Shr => ">>",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,8 +278,14 @@ pub fn fun_to_string(decl: &hir::FnDecl,
|
||||
-> String {
|
||||
to_string(|s| {
|
||||
try!(s.head(""));
|
||||
try!(s.print_fn(decl, unsafety, constness, abi::Rust, Some(name),
|
||||
generics, opt_explicit_self, hir::Inherited));
|
||||
try!(s.print_fn(decl,
|
||||
unsafety,
|
||||
constness,
|
||||
abi::Rust,
|
||||
Some(name),
|
||||
generics,
|
||||
opt_explicit_self,
|
||||
hir::Inherited));
|
||||
try!(s.end()); // Close the head box
|
||||
s.end() // Close the outer box
|
||||
})
|
||||
@@ -308,15 +316,17 @@ pub fn arg_to_string(arg: &hir::Arg) -> String {
|
||||
pub fn visibility_qualified(vis: hir::Visibility, s: &str) -> String {
|
||||
match vis {
|
||||
hir::Public => format!("pub {}", s),
|
||||
hir::Inherited => s.to_string()
|
||||
hir::Inherited => s.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn needs_parentheses(expr: &hir::Expr) -> bool {
|
||||
match expr.node {
|
||||
hir::ExprAssign(..) | hir::ExprBinary(..) |
|
||||
hir::ExprAssign(..) |
|
||||
hir::ExprBinary(..) |
|
||||
hir::ExprClosure(..) |
|
||||
hir::ExprAssignOp(..) | hir::ExprCast(..) => true,
|
||||
hir::ExprAssignOp(..) |
|
||||
hir::ExprCast(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@@ -327,7 +337,9 @@ pub fn cbox(&mut self, u: usize) -> io::Result<()> {
|
||||
pp::cbox(&mut self.s, u)
|
||||
}
|
||||
|
||||
pub fn nbsp(&mut self) -> io::Result<()> { word(&mut self.s, " ") }
|
||||
pub fn nbsp(&mut self) -> io::Result<()> {
|
||||
word(&mut self.s, " ")
|
||||
}
|
||||
|
||||
pub fn word_nbsp(&mut self, w: &str) -> io::Result<()> {
|
||||
try!(word(&mut self.s, w));
|
||||
@@ -351,12 +363,14 @@ pub fn bopen(&mut self) -> io::Result<()> {
|
||||
self.end() // close the head-box
|
||||
}
|
||||
|
||||
pub fn bclose_(&mut self, span: codemap::Span,
|
||||
indented: usize) -> io::Result<()> {
|
||||
pub fn bclose_(&mut self, span: codemap::Span, indented: usize) -> io::Result<()> {
|
||||
self.bclose_maybe_open(span, indented, true)
|
||||
}
|
||||
pub fn bclose_maybe_open (&mut self, span: codemap::Span,
|
||||
indented: usize, close_box: bool) -> io::Result<()> {
|
||||
pub fn bclose_maybe_open(&mut self,
|
||||
span: codemap::Span,
|
||||
indented: usize,
|
||||
close_box: bool)
|
||||
-> io::Result<()> {
|
||||
try!(self.maybe_print_comment(span.hi));
|
||||
try!(self.break_offset_if_not_bol(1, -(indented as isize)));
|
||||
try!(word(&mut self.s, "}"));
|
||||
@@ -372,15 +386,16 @@ pub fn bclose(&mut self, span: codemap::Span) -> io::Result<()> {
|
||||
pub fn in_cbox(&self) -> bool {
|
||||
match self.boxes.last() {
|
||||
Some(&last_box) => last_box == pp::Breaks::Consistent,
|
||||
None => false
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
pub fn space_if_not_bol(&mut self) -> io::Result<()> {
|
||||
if !self.is_bol() { try!(space(&mut self.s)); }
|
||||
if !self.is_bol() {
|
||||
try!(space(&mut self.s));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn break_offset_if_not_bol(&mut self, n: usize,
|
||||
off: isize) -> io::Result<()> {
|
||||
pub fn break_offset_if_not_bol(&mut self, n: usize, off: isize) -> io::Result<()> {
|
||||
if !self.is_bol() {
|
||||
break_offset(&mut self.s, n, off)
|
||||
} else {
|
||||
@@ -409,9 +424,10 @@ pub fn commasep_cmnt<T, F, G>(&mut self,
|
||||
b: Breaks,
|
||||
elts: &[T],
|
||||
mut op: F,
|
||||
mut get_span: G) -> io::Result<()> where
|
||||
F: FnMut(&mut State, &T) -> io::Result<()>,
|
||||
G: FnMut(&T) -> codemap::Span,
|
||||
mut get_span: G)
|
||||
-> io::Result<()>
|
||||
where F: FnMut(&mut State, &T) -> io::Result<()>,
|
||||
G: FnMut(&T) -> codemap::Span
|
||||
{
|
||||
try!(self.rbox(0, b));
|
||||
let len = elts.len();
|
||||
@@ -422,21 +438,18 @@ pub fn commasep_cmnt<T, F, G>(&mut self,
|
||||
i += 1;
|
||||
if i < len {
|
||||
try!(word(&mut self.s, ","));
|
||||
try!(self.maybe_print_trailing_comment(get_span(elt),
|
||||
Some(get_span(&elts[i]).hi)));
|
||||
try!(self.maybe_print_trailing_comment(get_span(elt), Some(get_span(&elts[i]).hi)));
|
||||
try!(self.space_if_not_bol());
|
||||
}
|
||||
}
|
||||
self.end()
|
||||
}
|
||||
|
||||
pub fn commasep_exprs(&mut self, b: Breaks,
|
||||
exprs: &[P<hir::Expr>]) -> io::Result<()> {
|
||||
pub fn commasep_exprs(&mut self, b: Breaks, exprs: &[P<hir::Expr>]) -> io::Result<()> {
|
||||
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&**e), |e| e.span)
|
||||
}
|
||||
|
||||
pub fn print_mod(&mut self, _mod: &hir::Mod,
|
||||
attrs: &[ast::Attribute]) -> io::Result<()> {
|
||||
pub fn print_mod(&mut self, _mod: &hir::Mod, attrs: &[ast::Attribute]) -> io::Result<()> {
|
||||
try!(self.print_inner_attributes(attrs));
|
||||
for item in &_mod.items {
|
||||
try!(self.print_item(&**item));
|
||||
@@ -444,8 +457,10 @@ pub fn print_mod(&mut self, _mod: &hir::Mod,
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_foreign_mod(&mut self, nmod: &hir::ForeignMod,
|
||||
attrs: &[ast::Attribute]) -> io::Result<()> {
|
||||
pub fn print_foreign_mod(&mut self,
|
||||
nmod: &hir::ForeignMod,
|
||||
attrs: &[ast::Attribute])
|
||||
-> io::Result<()> {
|
||||
try!(self.print_inner_attributes(attrs));
|
||||
for item in &nmod.items {
|
||||
try!(self.print_foreign_item(&**item));
|
||||
@@ -453,8 +468,7 @@ pub fn print_foreign_mod(&mut self, nmod: &hir::ForeignMod,
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_opt_lifetime(&mut self,
|
||||
lifetime: &Option<hir::Lifetime>) -> io::Result<()> {
|
||||
pub fn print_opt_lifetime(&mut self, lifetime: &Option<hir::Lifetime>) -> io::Result<()> {
|
||||
if let Some(l) = *lifetime {
|
||||
try!(self.print_lifetime(&l));
|
||||
try!(self.nbsp());
|
||||
@@ -486,8 +500,7 @@ pub fn print_type(&mut self, ty: &hir::Ty) -> io::Result<()> {
|
||||
}
|
||||
hir::TyTup(ref elts) => {
|
||||
try!(self.popen());
|
||||
try!(self.commasep(Inconsistent, &elts[..],
|
||||
|s, ty| s.print_type(&**ty)));
|
||||
try!(self.commasep(Inconsistent, &elts[..], |s, ty| s.print_type(&**ty)));
|
||||
if elts.len() == 1 {
|
||||
try!(word(&mut self.s, ","));
|
||||
}
|
||||
@@ -507,12 +520,7 @@ pub fn print_type(&mut self, ty: &hir::Ty) -> io::Result<()> {
|
||||
predicates: Vec::new(),
|
||||
},
|
||||
};
|
||||
try!(self.print_ty_fn(f.abi,
|
||||
f.unsafety,
|
||||
&*f.decl,
|
||||
None,
|
||||
&generics,
|
||||
None));
|
||||
try!(self.print_ty_fn(f.abi, f.unsafety, &*f.decl, None, &generics, None));
|
||||
}
|
||||
hir::TyPath(None, ref path) => {
|
||||
try!(self.print_path(path, false, 0));
|
||||
@@ -546,25 +554,27 @@ pub fn print_type(&mut self, ty: &hir::Ty) -> io::Result<()> {
|
||||
self.end()
|
||||
}
|
||||
|
||||
pub fn print_foreign_item(&mut self,
|
||||
item: &hir::ForeignItem) -> io::Result<()> {
|
||||
pub fn print_foreign_item(&mut self, item: &hir::ForeignItem) -> io::Result<()> {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
try!(self.maybe_print_comment(item.span.lo));
|
||||
try!(self.print_outer_attributes(&item.attrs));
|
||||
match item.node {
|
||||
hir::ForeignItemFn(ref decl, ref generics) => {
|
||||
try!(self.head(""));
|
||||
try!(self.print_fn(decl, hir::Unsafety::Normal,
|
||||
try!(self.print_fn(decl,
|
||||
hir::Unsafety::Normal,
|
||||
hir::Constness::NotConst,
|
||||
abi::Rust, Some(item.name),
|
||||
generics, None, item.vis));
|
||||
abi::Rust,
|
||||
Some(item.name),
|
||||
generics,
|
||||
None,
|
||||
item.vis));
|
||||
try!(self.end()); // end head-ibox
|
||||
try!(word(&mut self.s, ";"));
|
||||
self.end() // end the outer fn box
|
||||
}
|
||||
hir::ForeignItemStatic(ref t, m) => {
|
||||
try!(self.head(&visibility_qualified(item.vis,
|
||||
"static")));
|
||||
try!(self.head(&visibility_qualified(item.vis, "static")));
|
||||
if m {
|
||||
try!(self.word_space("mut"));
|
||||
}
|
||||
@@ -583,8 +593,7 @@ fn print_associated_const(&mut self,
|
||||
ty: &hir::Ty,
|
||||
default: Option<&hir::Expr>,
|
||||
vis: hir::Visibility)
|
||||
-> io::Result<()>
|
||||
{
|
||||
-> io::Result<()> {
|
||||
try!(word(&mut self.s, &visibility_qualified(vis, "")));
|
||||
try!(self.word_space("const"));
|
||||
try!(self.print_name(name));
|
||||
@@ -624,8 +633,7 @@ pub fn print_item(&mut self, item: &hir::Item) -> io::Result<()> {
|
||||
try!(self.ann.pre(self, NodeItem(item)));
|
||||
match item.node {
|
||||
hir::ItemExternCrate(ref optional_path) => {
|
||||
try!(self.head(&visibility_qualified(item.vis,
|
||||
"extern crate")));
|
||||
try!(self.head(&visibility_qualified(item.vis, "extern crate")));
|
||||
if let Some(p) = *optional_path {
|
||||
let val = p.as_str();
|
||||
if val.contains("-") {
|
||||
@@ -643,16 +651,14 @@ pub fn print_item(&mut self, item: &hir::Item) -> io::Result<()> {
|
||||
try!(self.end()); // end outer head-block
|
||||
}
|
||||
hir::ItemUse(ref vp) => {
|
||||
try!(self.head(&visibility_qualified(item.vis,
|
||||
"use")));
|
||||
try!(self.head(&visibility_qualified(item.vis, "use")));
|
||||
try!(self.print_view_path(&**vp));
|
||||
try!(word(&mut self.s, ";"));
|
||||
try!(self.end()); // end inner head-block
|
||||
try!(self.end()); // end outer head-block
|
||||
}
|
||||
hir::ItemStatic(ref ty, m, ref expr) => {
|
||||
try!(self.head(&visibility_qualified(item.vis,
|
||||
"static")));
|
||||
try!(self.head(&visibility_qualified(item.vis, "static")));
|
||||
if m == hir::MutMutable {
|
||||
try!(self.word_space("mut"));
|
||||
}
|
||||
@@ -668,8 +674,7 @@ pub fn print_item(&mut self, item: &hir::Item) -> io::Result<()> {
|
||||
try!(self.end()); // end the outer cbox
|
||||
}
|
||||
hir::ItemConst(ref ty, ref expr) => {
|
||||
try!(self.head(&visibility_qualified(item.vis,
|
||||
"const")));
|
||||
try!(self.head(&visibility_qualified(item.vis, "const")));
|
||||
try!(self.print_name(item.name));
|
||||
try!(self.word_space(":"));
|
||||
try!(self.print_type(&**ty));
|
||||
@@ -683,22 +688,19 @@ pub fn print_item(&mut self, item: &hir::Item) -> io::Result<()> {
|
||||
}
|
||||
hir::ItemFn(ref decl, unsafety, constness, abi, ref typarams, ref body) => {
|
||||
try!(self.head(""));
|
||||
try!(self.print_fn(
|
||||
decl,
|
||||
unsafety,
|
||||
constness,
|
||||
abi,
|
||||
Some(item.name),
|
||||
typarams,
|
||||
None,
|
||||
item.vis
|
||||
));
|
||||
try!(self.print_fn(decl,
|
||||
unsafety,
|
||||
constness,
|
||||
abi,
|
||||
Some(item.name),
|
||||
typarams,
|
||||
None,
|
||||
item.vis));
|
||||
try!(word(&mut self.s, " "));
|
||||
try!(self.print_block_with_attrs(&**body, &item.attrs));
|
||||
}
|
||||
hir::ItemMod(ref _mod) => {
|
||||
try!(self.head(&visibility_qualified(item.vis,
|
||||
"mod")));
|
||||
try!(self.head(&visibility_qualified(item.vis, "mod")));
|
||||
try!(self.print_name(item.name));
|
||||
try!(self.nbsp());
|
||||
try!(self.bopen());
|
||||
@@ -728,16 +730,10 @@ pub fn print_item(&mut self, item: &hir::Item) -> io::Result<()> {
|
||||
try!(self.end()); // end the outer ibox
|
||||
}
|
||||
hir::ItemEnum(ref enum_definition, ref params) => {
|
||||
try!(self.print_enum_def(
|
||||
enum_definition,
|
||||
params,
|
||||
item.name,
|
||||
item.span,
|
||||
item.vis
|
||||
));
|
||||
try!(self.print_enum_def(enum_definition, params, item.name, item.span, item.vis));
|
||||
}
|
||||
hir::ItemStruct(ref struct_def, ref generics) => {
|
||||
try!(self.head(&visibility_qualified(item.vis,"struct")));
|
||||
try!(self.head(&visibility_qualified(item.vis, "struct")));
|
||||
try!(self.print_struct(&**struct_def, generics, item.name, item.span));
|
||||
}
|
||||
|
||||
@@ -772,7 +768,7 @@ pub fn print_item(&mut self, item: &hir::Item) -> io::Result<()> {
|
||||
match polarity {
|
||||
hir::ImplPolarity::Negative => {
|
||||
try!(word(&mut self.s, "!"));
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -851,10 +847,13 @@ fn print_poly_trait_ref(&mut self, t: &hir::PolyTraitRef) -> io::Result<()> {
|
||||
self.print_trait_ref(&t.trait_ref)
|
||||
}
|
||||
|
||||
pub fn print_enum_def(&mut self, enum_definition: &hir::EnumDef,
|
||||
generics: &hir::Generics, name: ast::Name,
|
||||
pub fn print_enum_def(&mut self,
|
||||
enum_definition: &hir::EnumDef,
|
||||
generics: &hir::Generics,
|
||||
name: ast::Name,
|
||||
span: codemap::Span,
|
||||
visibility: hir::Visibility) -> io::Result<()> {
|
||||
visibility: hir::Visibility)
|
||||
-> io::Result<()> {
|
||||
try!(self.head(&visibility_qualified(visibility, "enum")));
|
||||
try!(self.print_name(name));
|
||||
try!(self.print_generics(generics));
|
||||
@@ -865,7 +864,8 @@ pub fn print_enum_def(&mut self, enum_definition: &hir::EnumDef,
|
||||
|
||||
pub fn print_variants(&mut self,
|
||||
variants: &[P<hir::Variant>],
|
||||
span: codemap::Span) -> io::Result<()> {
|
||||
span: codemap::Span)
|
||||
-> io::Result<()> {
|
||||
try!(self.bopen());
|
||||
for v in variants {
|
||||
try!(self.space_if_not_bol());
|
||||
@@ -883,7 +883,7 @@ pub fn print_variants(&mut self,
|
||||
pub fn print_visibility(&mut self, vis: hir::Visibility) -> io::Result<()> {
|
||||
match vis {
|
||||
hir::Public => self.word_nbsp("pub"),
|
||||
hir::Inherited => Ok(())
|
||||
hir::Inherited => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -891,25 +891,25 @@ pub fn print_struct(&mut self,
|
||||
struct_def: &hir::StructDef,
|
||||
generics: &hir::Generics,
|
||||
name: ast::Name,
|
||||
span: codemap::Span) -> io::Result<()> {
|
||||
span: codemap::Span)
|
||||
-> io::Result<()> {
|
||||
try!(self.print_name(name));
|
||||
try!(self.print_generics(generics));
|
||||
if ::util::struct_def_is_tuple_like(struct_def) {
|
||||
if !struct_def.fields.is_empty() {
|
||||
try!(self.popen());
|
||||
try!(self.commasep(
|
||||
Inconsistent, &struct_def.fields,
|
||||
|s, field| {
|
||||
match field.node.kind {
|
||||
hir::NamedField(..) => panic!("unexpected named field"),
|
||||
hir::UnnamedField(vis) => {
|
||||
try!(s.print_visibility(vis));
|
||||
try!(s.maybe_print_comment(field.span.lo));
|
||||
s.print_type(&*field.node.ty)
|
||||
}
|
||||
}
|
||||
}
|
||||
));
|
||||
try!(self.commasep(Inconsistent,
|
||||
&struct_def.fields,
|
||||
|s, field| {
|
||||
match field.node.kind {
|
||||
hir::NamedField(..) => panic!("unexpected named field"),
|
||||
hir::UnnamedField(vis) => {
|
||||
try!(s.print_visibility(vis));
|
||||
try!(s.maybe_print_comment(field.span.lo));
|
||||
s.print_type(&*field.node.ty)
|
||||
}
|
||||
}
|
||||
}));
|
||||
try!(self.pclose());
|
||||
}
|
||||
try!(self.print_where_clause(&generics.where_clause));
|
||||
@@ -948,9 +948,7 @@ pub fn print_variant(&mut self, v: &hir::Variant) -> io::Result<()> {
|
||||
try!(self.print_name(v.node.name));
|
||||
if !args.is_empty() {
|
||||
try!(self.popen());
|
||||
try!(self.commasep(Consistent,
|
||||
&args[..],
|
||||
|s, arg| s.print_type(&*arg.ty)));
|
||||
try!(self.commasep(Consistent, &args[..], |s, arg| s.print_type(&*arg.ty)));
|
||||
try!(self.pclose());
|
||||
}
|
||||
}
|
||||
@@ -966,7 +964,7 @@ pub fn print_variant(&mut self, v: &hir::Variant) -> io::Result<()> {
|
||||
try!(self.word_space("="));
|
||||
self.print_expr(&**d)
|
||||
}
|
||||
_ => Ok(())
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -985,15 +983,15 @@ pub fn print_method_sig(&mut self,
|
||||
vis)
|
||||
}
|
||||
|
||||
pub fn print_trait_item(&mut self, ti: &hir::TraitItem)
|
||||
-> io::Result<()> {
|
||||
pub fn print_trait_item(&mut self, ti: &hir::TraitItem) -> io::Result<()> {
|
||||
try!(self.ann.pre(self, NodeSubItem(ti.id)));
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
try!(self.maybe_print_comment(ti.span.lo));
|
||||
try!(self.print_outer_attributes(&ti.attrs));
|
||||
match ti.node {
|
||||
hir::ConstTraitItem(ref ty, ref default) => {
|
||||
try!(self.print_associated_const(ti.name, &ty,
|
||||
try!(self.print_associated_const(ti.name,
|
||||
&ty,
|
||||
default.as_ref().map(|expr| &**expr),
|
||||
hir::Inherited));
|
||||
}
|
||||
@@ -1010,7 +1008,8 @@ pub fn print_trait_item(&mut self, ti: &hir::TraitItem)
|
||||
}
|
||||
}
|
||||
hir::TypeTraitItem(ref bounds, ref default) => {
|
||||
try!(self.print_associated_type(ti.name, Some(bounds),
|
||||
try!(self.print_associated_type(ti.name,
|
||||
Some(bounds),
|
||||
default.as_ref().map(|ty| &**ty)));
|
||||
}
|
||||
}
|
||||
@@ -1069,14 +1068,17 @@ pub fn print_block_unclosed(&mut self, blk: &hir::Block) -> io::Result<()> {
|
||||
self.print_block_unclosed_indent(blk, indent_unit)
|
||||
}
|
||||
|
||||
pub fn print_block_unclosed_indent(&mut self, blk: &hir::Block,
|
||||
indented: usize) -> io::Result<()> {
|
||||
pub fn print_block_unclosed_indent(&mut self,
|
||||
blk: &hir::Block,
|
||||
indented: usize)
|
||||
-> io::Result<()> {
|
||||
self.print_block_maybe_unclosed(blk, indented, &[], false)
|
||||
}
|
||||
|
||||
pub fn print_block_with_attrs(&mut self,
|
||||
blk: &hir::Block,
|
||||
attrs: &[ast::Attribute]) -> io::Result<()> {
|
||||
attrs: &[ast::Attribute])
|
||||
-> io::Result<()> {
|
||||
self.print_block_maybe_unclosed(blk, indent_unit, attrs, true)
|
||||
}
|
||||
|
||||
@@ -1084,10 +1086,11 @@ pub fn print_block_maybe_unclosed(&mut self,
|
||||
blk: &hir::Block,
|
||||
indented: usize,
|
||||
attrs: &[ast::Attribute],
|
||||
close_box: bool) -> io::Result<()> {
|
||||
close_box: bool)
|
||||
-> io::Result<()> {
|
||||
match blk.rules {
|
||||
hir::UnsafeBlock(..) | hir::PushUnsafeBlock(..) => try!(self.word_space("unsafe")),
|
||||
hir::DefaultBlock | hir::PopUnsafeBlock(..) => ()
|
||||
hir::DefaultBlock | hir::PopUnsafeBlock(..) => (),
|
||||
}
|
||||
try!(self.maybe_print_comment(blk.span.lo));
|
||||
try!(self.ann.pre(self, NodeBlock(blk)));
|
||||
@@ -1104,7 +1107,7 @@ pub fn print_block_maybe_unclosed(&mut self,
|
||||
try!(self.print_expr(&**expr));
|
||||
try!(self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi)));
|
||||
}
|
||||
_ => ()
|
||||
_ => (),
|
||||
}
|
||||
try!(self.bclose_maybe_open(blk.span, indented, close_box));
|
||||
self.ann.post(self, NodeBlock(blk))
|
||||
@@ -1137,12 +1140,15 @@ fn print_else(&mut self, els: Option<&hir::Expr>) -> io::Result<()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => Ok(())
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_if(&mut self, test: &hir::Expr, blk: &hir::Block,
|
||||
elseopt: Option<&hir::Expr>) -> io::Result<()> {
|
||||
pub fn print_if(&mut self,
|
||||
test: &hir::Expr,
|
||||
blk: &hir::Block,
|
||||
elseopt: Option<&hir::Expr>)
|
||||
-> io::Result<()> {
|
||||
try!(self.head("if"));
|
||||
try!(self.print_expr(test));
|
||||
try!(space(&mut self.s));
|
||||
@@ -1150,8 +1156,12 @@ pub fn print_if(&mut self, test: &hir::Expr, blk: &hir::Block,
|
||||
self.print_else(elseopt)
|
||||
}
|
||||
|
||||
pub fn print_if_let(&mut self, pat: &hir::Pat, expr: &hir::Expr, blk: &hir::Block,
|
||||
elseopt: Option<&hir::Expr>) -> io::Result<()> {
|
||||
pub fn print_if_let(&mut self,
|
||||
pat: &hir::Pat,
|
||||
expr: &hir::Expr,
|
||||
blk: &hir::Block,
|
||||
elseopt: Option<&hir::Expr>)
|
||||
-> io::Result<()> {
|
||||
try!(self.head("if let"));
|
||||
try!(self.print_pat(pat));
|
||||
try!(space(&mut self.s));
|
||||
@@ -1189,9 +1199,7 @@ fn print_expr_vec(&mut self, exprs: &[P<hir::Expr>]) -> io::Result<()> {
|
||||
self.end()
|
||||
}
|
||||
|
||||
fn print_expr_repeat(&mut self,
|
||||
element: &hir::Expr,
|
||||
count: &hir::Expr) -> io::Result<()> {
|
||||
fn print_expr_repeat(&mut self, element: &hir::Expr, count: &hir::Expr) -> io::Result<()> {
|
||||
try!(self.ibox(indent_unit));
|
||||
try!(word(&mut self.s, "["));
|
||||
try!(self.print_expr(element));
|
||||
@@ -1204,20 +1212,20 @@ fn print_expr_repeat(&mut self,
|
||||
fn print_expr_struct(&mut self,
|
||||
path: &hir::Path,
|
||||
fields: &[hir::Field],
|
||||
wth: &Option<P<hir::Expr>>) -> io::Result<()> {
|
||||
wth: &Option<P<hir::Expr>>)
|
||||
-> io::Result<()> {
|
||||
try!(self.print_path(path, true, 0));
|
||||
try!(word(&mut self.s, "{"));
|
||||
try!(self.commasep_cmnt(
|
||||
Consistent,
|
||||
&fields[..],
|
||||
|s, field| {
|
||||
try!(s.ibox(indent_unit));
|
||||
try!(s.print_name(field.name.node));
|
||||
try!(s.word_space(":"));
|
||||
try!(s.print_expr(&*field.expr));
|
||||
s.end()
|
||||
},
|
||||
|f| f.span));
|
||||
try!(self.commasep_cmnt(Consistent,
|
||||
&fields[..],
|
||||
|s, field| {
|
||||
try!(s.ibox(indent_unit));
|
||||
try!(s.print_name(field.name.node));
|
||||
try!(s.word_space(":"));
|
||||
try!(s.print_expr(&*field.expr));
|
||||
s.end()
|
||||
},
|
||||
|f| f.span));
|
||||
match *wth {
|
||||
Some(ref expr) => {
|
||||
try!(self.ibox(indent_unit));
|
||||
@@ -1231,7 +1239,7 @@ fn print_expr_struct(&mut self,
|
||||
}
|
||||
_ => if !fields.is_empty() {
|
||||
try!(word(&mut self.s, ","))
|
||||
}
|
||||
},
|
||||
}
|
||||
try!(word(&mut self.s, "}"));
|
||||
Ok(())
|
||||
@@ -1246,9 +1254,7 @@ fn print_expr_tup(&mut self, exprs: &[P<hir::Expr>]) -> io::Result<()> {
|
||||
self.pclose()
|
||||
}
|
||||
|
||||
fn print_expr_call(&mut self,
|
||||
func: &hir::Expr,
|
||||
args: &[P<hir::Expr>]) -> io::Result<()> {
|
||||
fn print_expr_call(&mut self, func: &hir::Expr, args: &[P<hir::Expr>]) -> io::Result<()> {
|
||||
try!(self.print_expr_maybe_paren(func));
|
||||
self.print_call_post(args)
|
||||
}
|
||||
@@ -1256,15 +1262,15 @@ fn print_expr_call(&mut self,
|
||||
fn print_expr_method_call(&mut self,
|
||||
name: Spanned<ast::Name>,
|
||||
tys: &[P<hir::Ty>],
|
||||
args: &[P<hir::Expr>]) -> io::Result<()> {
|
||||
args: &[P<hir::Expr>])
|
||||
-> io::Result<()> {
|
||||
let base_args = &args[1..];
|
||||
try!(self.print_expr(&*args[0]));
|
||||
try!(word(&mut self.s, "."));
|
||||
try!(self.print_name(name.node));
|
||||
if !tys.is_empty() {
|
||||
try!(word(&mut self.s, "::<"));
|
||||
try!(self.commasep(Inconsistent, tys,
|
||||
|s, ty| s.print_type(&**ty)));
|
||||
try!(self.commasep(Inconsistent, tys, |s, ty| s.print_type(&**ty)));
|
||||
try!(word(&mut self.s, ">"));
|
||||
}
|
||||
self.print_call_post(base_args)
|
||||
@@ -1273,23 +1279,23 @@ fn print_expr_method_call(&mut self,
|
||||
fn print_expr_binary(&mut self,
|
||||
op: hir::BinOp,
|
||||
lhs: &hir::Expr,
|
||||
rhs: &hir::Expr) -> io::Result<()> {
|
||||
rhs: &hir::Expr)
|
||||
-> io::Result<()> {
|
||||
try!(self.print_expr(lhs));
|
||||
try!(space(&mut self.s));
|
||||
try!(self.word_space(::util::binop_to_string(op.node)));
|
||||
self.print_expr(rhs)
|
||||
}
|
||||
|
||||
fn print_expr_unary(&mut self,
|
||||
op: hir::UnOp,
|
||||
expr: &hir::Expr) -> io::Result<()> {
|
||||
fn print_expr_unary(&mut self, op: hir::UnOp, expr: &hir::Expr) -> io::Result<()> {
|
||||
try!(word(&mut self.s, ::util::unop_to_string(op)));
|
||||
self.print_expr_maybe_paren(expr)
|
||||
}
|
||||
|
||||
fn print_expr_addr_of(&mut self,
|
||||
mutability: hir::Mutability,
|
||||
expr: &hir::Expr) -> io::Result<()> {
|
||||
expr: &hir::Expr)
|
||||
-> io::Result<()> {
|
||||
try!(word(&mut self.s, "&"));
|
||||
try!(self.print_mutability(mutability));
|
||||
self.print_expr_maybe_paren(expr)
|
||||
@@ -1382,7 +1388,7 @@ pub fn print_expr(&mut self, expr: &hir::Expr) -> io::Result<()> {
|
||||
|
||||
let default_return = match decl.output {
|
||||
hir::DefaultReturn(..) => true,
|
||||
_ => false
|
||||
_ => false,
|
||||
};
|
||||
|
||||
if !default_return || !body.stmts.is_empty() || body.expr.is_none() {
|
||||
@@ -1479,7 +1485,7 @@ pub fn print_expr(&mut self, expr: &hir::Expr) -> io::Result<()> {
|
||||
try!(word(&mut self.s, " "));
|
||||
try!(self.print_expr(&**expr));
|
||||
}
|
||||
_ => ()
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
hir::ExprInlineAsm(ref a) => {
|
||||
@@ -1488,39 +1494,42 @@ pub fn print_expr(&mut self, expr: &hir::Expr) -> io::Result<()> {
|
||||
try!(self.print_string(&a.asm, a.asm_str_style));
|
||||
try!(self.word_space(":"));
|
||||
|
||||
try!(self.commasep(Inconsistent, &a.outputs,
|
||||
try!(self.commasep(Inconsistent,
|
||||
&a.outputs,
|
||||
|s, &(ref co, ref o, is_rw)| {
|
||||
match co.slice_shift_char() {
|
||||
Some(('=', operand)) if is_rw => {
|
||||
try!(s.print_string(&format!("+{}", operand),
|
||||
ast::CookedStr))
|
||||
}
|
||||
_ => try!(s.print_string(&co, ast::CookedStr))
|
||||
}
|
||||
try!(s.popen());
|
||||
try!(s.print_expr(&**o));
|
||||
try!(s.pclose());
|
||||
Ok(())
|
||||
}));
|
||||
match co.slice_shift_char() {
|
||||
Some(('=', operand)) if is_rw => {
|
||||
try!(s.print_string(&format!("+{}", operand),
|
||||
ast::CookedStr))
|
||||
}
|
||||
_ => try!(s.print_string(&co, ast::CookedStr)),
|
||||
}
|
||||
try!(s.popen());
|
||||
try!(s.print_expr(&**o));
|
||||
try!(s.pclose());
|
||||
Ok(())
|
||||
}));
|
||||
try!(space(&mut self.s));
|
||||
try!(self.word_space(":"));
|
||||
|
||||
try!(self.commasep(Inconsistent, &a.inputs,
|
||||
try!(self.commasep(Inconsistent,
|
||||
&a.inputs,
|
||||
|s, &(ref co, ref o)| {
|
||||
try!(s.print_string(&co, ast::CookedStr));
|
||||
try!(s.popen());
|
||||
try!(s.print_expr(&**o));
|
||||
try!(s.pclose());
|
||||
Ok(())
|
||||
}));
|
||||
try!(s.print_string(&co, ast::CookedStr));
|
||||
try!(s.popen());
|
||||
try!(s.print_expr(&**o));
|
||||
try!(s.pclose());
|
||||
Ok(())
|
||||
}));
|
||||
try!(space(&mut self.s));
|
||||
try!(self.word_space(":"));
|
||||
|
||||
try!(self.commasep(Inconsistent, &a.clobbers,
|
||||
try!(self.commasep(Inconsistent,
|
||||
&a.clobbers,
|
||||
|s, co| {
|
||||
try!(s.print_string(&co, ast::CookedStr));
|
||||
Ok(())
|
||||
}));
|
||||
try!(s.print_string(&co, ast::CookedStr));
|
||||
Ok(())
|
||||
}));
|
||||
|
||||
let mut options = vec!();
|
||||
if a.volatile {
|
||||
@@ -1536,11 +1545,12 @@ pub fn print_expr(&mut self, expr: &hir::Expr) -> io::Result<()> {
|
||||
if !options.is_empty() {
|
||||
try!(space(&mut self.s));
|
||||
try!(self.word_space(":"));
|
||||
try!(self.commasep(Inconsistent, &*options,
|
||||
try!(self.commasep(Inconsistent,
|
||||
&*options,
|
||||
|s, &co| {
|
||||
try!(s.print_string(co, ast::CookedStr));
|
||||
Ok(())
|
||||
}));
|
||||
try!(s.print_string(co, ast::CookedStr));
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
|
||||
try!(self.pclose());
|
||||
@@ -1577,7 +1587,7 @@ pub fn print_decl(&mut self, decl: &hir::Decl) -> io::Result<()> {
|
||||
}
|
||||
self.end()
|
||||
}
|
||||
hir::DeclItem(ref item) => self.print_item(&**item)
|
||||
hir::DeclItem(ref item) => self.print_item(&**item),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1590,8 +1600,7 @@ pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> {
|
||||
self.ann.post(self, NodeName(&name))
|
||||
}
|
||||
|
||||
pub fn print_for_decl(&mut self, loc: &hir::Local,
|
||||
coll: &hir::Expr) -> io::Result<()> {
|
||||
pub fn print_for_decl(&mut self, loc: &hir::Local, coll: &hir::Expr) -> io::Result<()> {
|
||||
try!(self.print_local_decl(loc));
|
||||
try!(space(&mut self.s));
|
||||
try!(self.word_space("in"));
|
||||
@@ -1602,8 +1611,7 @@ fn print_path(&mut self,
|
||||
path: &hir::Path,
|
||||
colons_before_params: bool,
|
||||
depth: usize)
|
||||
-> io::Result<()>
|
||||
{
|
||||
-> io::Result<()> {
|
||||
try!(self.maybe_print_comment(path.span.lo));
|
||||
|
||||
let mut first = !path.global;
|
||||
@@ -1626,8 +1634,7 @@ fn print_qpath(&mut self,
|
||||
path: &hir::Path,
|
||||
qself: &hir::QSelf,
|
||||
colons_before_params: bool)
|
||||
-> io::Result<()>
|
||||
{
|
||||
-> io::Result<()> {
|
||||
try!(word(&mut self.s, "<"));
|
||||
try!(self.print_type(&qself.ty));
|
||||
if qself.position > 0 {
|
||||
@@ -1646,8 +1653,7 @@ fn print_qpath(&mut self,
|
||||
fn print_path_parameters(&mut self,
|
||||
parameters: &hir::PathParameters,
|
||||
colons_before_params: bool)
|
||||
-> io::Result<()>
|
||||
{
|
||||
-> io::Result<()> {
|
||||
if parameters.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -1673,11 +1679,8 @@ fn print_path_parameters(&mut self,
|
||||
if comma {
|
||||
try!(self.word_space(","))
|
||||
}
|
||||
try!(self.commasep(
|
||||
Inconsistent,
|
||||
&data.types,
|
||||
|s, ty| s.print_type(&**ty)));
|
||||
comma = true;
|
||||
try!(self.commasep(Inconsistent, &data.types, |s, ty| s.print_type(&**ty)));
|
||||
comma = true;
|
||||
}
|
||||
|
||||
for binding in data.bindings.iter() {
|
||||
@@ -1696,14 +1699,13 @@ fn print_path_parameters(&mut self,
|
||||
|
||||
hir::ParenthesizedParameters(ref data) => {
|
||||
try!(word(&mut self.s, "("));
|
||||
try!(self.commasep(
|
||||
Inconsistent,
|
||||
&data.inputs,
|
||||
|s, ty| s.print_type(&**ty)));
|
||||
try!(self.commasep(Inconsistent,
|
||||
&data.inputs,
|
||||
|s, ty| s.print_type(&**ty)));
|
||||
try!(word(&mut self.s, ")"));
|
||||
|
||||
match data.output {
|
||||
None => { }
|
||||
None => {}
|
||||
Some(ref ty) => {
|
||||
try!(self.space_if_not_bol());
|
||||
try!(self.word_space("->"));
|
||||
@@ -1741,7 +1743,7 @@ pub fn print_pat(&mut self, pat: &hir::Pat) -> io::Result<()> {
|
||||
try!(word(&mut self.s, "@"));
|
||||
try!(self.print_pat(&**p));
|
||||
}
|
||||
None => ()
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
hir::PatEnum(ref path, ref args_) => {
|
||||
@@ -1751,8 +1753,7 @@ pub fn print_pat(&mut self, pat: &hir::Pat) -> io::Result<()> {
|
||||
Some(ref args) => {
|
||||
if !args.is_empty() {
|
||||
try!(self.popen());
|
||||
try!(self.commasep(Inconsistent, &args[..],
|
||||
|s, p| s.print_pat(&**p)));
|
||||
try!(self.commasep(Inconsistent, &args[..], |s, p| s.print_pat(&**p)));
|
||||
try!(self.pclose());
|
||||
}
|
||||
}
|
||||
@@ -1765,20 +1766,22 @@ pub fn print_pat(&mut self, pat: &hir::Pat) -> io::Result<()> {
|
||||
try!(self.print_path(path, true, 0));
|
||||
try!(self.nbsp());
|
||||
try!(self.word_space("{"));
|
||||
try!(self.commasep_cmnt(
|
||||
Consistent, &fields[..],
|
||||
|s, f| {
|
||||
try!(s.cbox(indent_unit));
|
||||
if !f.node.is_shorthand {
|
||||
try!(s.print_name(f.node.name));
|
||||
try!(s.word_nbsp(":"));
|
||||
}
|
||||
try!(s.print_pat(&*f.node.pat));
|
||||
s.end()
|
||||
},
|
||||
|f| f.node.pat.span));
|
||||
try!(self.commasep_cmnt(Consistent,
|
||||
&fields[..],
|
||||
|s, f| {
|
||||
try!(s.cbox(indent_unit));
|
||||
if !f.node.is_shorthand {
|
||||
try!(s.print_name(f.node.name));
|
||||
try!(s.word_nbsp(":"));
|
||||
}
|
||||
try!(s.print_pat(&*f.node.pat));
|
||||
s.end()
|
||||
},
|
||||
|f| f.node.pat.span));
|
||||
if etc {
|
||||
if !fields.is_empty() { try!(self.word_space(",")); }
|
||||
if !fields.is_empty() {
|
||||
try!(self.word_space(","));
|
||||
}
|
||||
try!(word(&mut self.s, ".."));
|
||||
}
|
||||
try!(space(&mut self.s));
|
||||
@@ -1786,9 +1789,7 @@ pub fn print_pat(&mut self, pat: &hir::Pat) -> io::Result<()> {
|
||||
}
|
||||
hir::PatTup(ref elts) => {
|
||||
try!(self.popen());
|
||||
try!(self.commasep(Inconsistent,
|
||||
&elts[..],
|
||||
|s, p| s.print_pat(&**p)));
|
||||
try!(self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(&**p)));
|
||||
if elts.len() == 1 {
|
||||
try!(word(&mut self.s, ","));
|
||||
}
|
||||
@@ -1814,11 +1815,11 @@ pub fn print_pat(&mut self, pat: &hir::Pat) -> io::Result<()> {
|
||||
}
|
||||
hir::PatVec(ref before, ref slice, ref after) => {
|
||||
try!(word(&mut self.s, "["));
|
||||
try!(self.commasep(Inconsistent,
|
||||
&before[..],
|
||||
|s, p| s.print_pat(&**p)));
|
||||
try!(self.commasep(Inconsistent, &before[..], |s, p| s.print_pat(&**p)));
|
||||
if let Some(ref p) = *slice {
|
||||
if !before.is_empty() { try!(self.word_space(",")); }
|
||||
if !before.is_empty() {
|
||||
try!(self.word_space(","));
|
||||
}
|
||||
try!(self.print_pat(&**p));
|
||||
match **p {
|
||||
hir::Pat { node: hir::PatWild(hir::PatWildMulti), .. } => {
|
||||
@@ -1826,11 +1827,11 @@ pub fn print_pat(&mut self, pat: &hir::Pat) -> io::Result<()> {
|
||||
}
|
||||
_ => try!(word(&mut self.s, "..")),
|
||||
}
|
||||
if !after.is_empty() { try!(self.word_space(",")); }
|
||||
if !after.is_empty() {
|
||||
try!(self.word_space(","));
|
||||
}
|
||||
}
|
||||
try!(self.commasep(Inconsistent,
|
||||
&after[..],
|
||||
|s, p| s.print_pat(&**p)));
|
||||
try!(self.commasep(Inconsistent, &after[..], |s, p| s.print_pat(&**p)));
|
||||
try!(word(&mut self.s, "]"));
|
||||
}
|
||||
}
|
||||
@@ -1886,10 +1887,13 @@ fn print_arm(&mut self, arm: &hir::Arm) -> io::Result<()> {
|
||||
// Returns whether it printed anything
|
||||
fn print_explicit_self(&mut self,
|
||||
explicit_self: &hir::ExplicitSelf_,
|
||||
mutbl: hir::Mutability) -> io::Result<bool> {
|
||||
mutbl: hir::Mutability)
|
||||
-> io::Result<bool> {
|
||||
try!(self.print_mutability(mutbl));
|
||||
match *explicit_self {
|
||||
hir::SelfStatic => { return Ok(false); }
|
||||
hir::SelfStatic => {
|
||||
return Ok(false);
|
||||
}
|
||||
hir::SelfValue(_) => {
|
||||
try!(word(&mut self.s, "self"));
|
||||
}
|
||||
@@ -1916,7 +1920,8 @@ pub fn print_fn(&mut self,
|
||||
name: Option<ast::Name>,
|
||||
generics: &hir::Generics,
|
||||
opt_explicit_self: Option<&hir::ExplicitSelf_>,
|
||||
vis: hir::Visibility) -> io::Result<()> {
|
||||
vis: hir::Visibility)
|
||||
-> io::Result<()> {
|
||||
try!(self.print_fn_header_info(unsafety, constness, abi, vis));
|
||||
|
||||
if let Some(name) = name {
|
||||
@@ -1928,9 +1933,10 @@ pub fn print_fn(&mut self,
|
||||
self.print_where_clause(&generics.where_clause)
|
||||
}
|
||||
|
||||
pub fn print_fn_args(&mut self, decl: &hir::FnDecl,
|
||||
pub fn print_fn_args(&mut self,
|
||||
decl: &hir::FnDecl,
|
||||
opt_explicit_self: Option<&hir::ExplicitSelf_>)
|
||||
-> io::Result<()> {
|
||||
-> io::Result<()> {
|
||||
// It is unfortunate to duplicate the commasep logic, but we want the
|
||||
// self type and the args all in the same box.
|
||||
try!(self.rbox(0, Inconsistent));
|
||||
@@ -1940,8 +1946,8 @@ pub fn print_fn_args(&mut self, decl: &hir::FnDecl,
|
||||
&hir::SelfStatic => hir::MutImmutable,
|
||||
_ => match decl.inputs[0].pat.node {
|
||||
hir::PatIdent(hir::BindByValue(m), _, _) => m,
|
||||
_ => hir::MutImmutable
|
||||
}
|
||||
_ => hir::MutImmutable,
|
||||
},
|
||||
};
|
||||
first = !try!(self.print_explicit_self(explicit_self, m));
|
||||
}
|
||||
@@ -1954,16 +1960,21 @@ pub fn print_fn_args(&mut self, decl: &hir::FnDecl,
|
||||
};
|
||||
|
||||
for arg in args {
|
||||
if first { first = false; } else { try!(self.word_space(",")); }
|
||||
if first {
|
||||
first = false;
|
||||
} else {
|
||||
try!(self.word_space(","));
|
||||
}
|
||||
try!(self.print_arg(arg));
|
||||
}
|
||||
|
||||
self.end()
|
||||
}
|
||||
|
||||
pub fn print_fn_args_and_ret(&mut self, decl: &hir::FnDecl,
|
||||
pub fn print_fn_args_and_ret(&mut self,
|
||||
decl: &hir::FnDecl,
|
||||
opt_explicit_self: Option<&hir::ExplicitSelf_>)
|
||||
-> io::Result<()> {
|
||||
-> io::Result<()> {
|
||||
try!(self.popen());
|
||||
try!(self.print_fn_args(decl, opt_explicit_self));
|
||||
if decl.variadic {
|
||||
@@ -1974,10 +1985,7 @@ pub fn print_fn_args_and_ret(&mut self, decl: &hir::FnDecl,
|
||||
self.print_fn_output(decl)
|
||||
}
|
||||
|
||||
pub fn print_fn_block_args(
|
||||
&mut self,
|
||||
decl: &hir::FnDecl)
|
||||
-> io::Result<()> {
|
||||
pub fn print_fn_block_args(&mut self, decl: &hir::FnDecl) -> io::Result<()> {
|
||||
try!(word(&mut self.s, "|"));
|
||||
try!(self.print_fn_args(decl, None));
|
||||
try!(word(&mut self.s, "|"));
|
||||
@@ -2001,18 +2009,14 @@ pub fn print_fn_block_args(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_capture_clause(&mut self, capture_clause: hir::CaptureClause)
|
||||
-> io::Result<()> {
|
||||
pub fn print_capture_clause(&mut self, capture_clause: hir::CaptureClause) -> io::Result<()> {
|
||||
match capture_clause {
|
||||
hir::CaptureByValue => self.word_space("move"),
|
||||
hir::CaptureByRef => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_bounds(&mut self,
|
||||
prefix: &str,
|
||||
bounds: &[hir::TyParamBound])
|
||||
-> io::Result<()> {
|
||||
pub fn print_bounds(&mut self, prefix: &str, bounds: &[hir::TyParamBound]) -> io::Result<()> {
|
||||
if !bounds.is_empty() {
|
||||
try!(word(&mut self.s, prefix));
|
||||
let mut first = true;
|
||||
@@ -2043,17 +2047,11 @@ pub fn print_bounds(&mut self,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_lifetime(&mut self,
|
||||
lifetime: &hir::Lifetime)
|
||||
-> io::Result<()>
|
||||
{
|
||||
pub fn print_lifetime(&mut self, lifetime: &hir::Lifetime) -> io::Result<()> {
|
||||
self.print_name(lifetime.name)
|
||||
}
|
||||
|
||||
pub fn print_lifetime_def(&mut self,
|
||||
lifetime: &hir::LifetimeDef)
|
||||
-> io::Result<()>
|
||||
{
|
||||
pub fn print_lifetime_def(&mut self, lifetime: &hir::LifetimeDef) -> io::Result<()> {
|
||||
try!(self.print_lifetime(&lifetime.lifetime));
|
||||
let mut sep = ":";
|
||||
for v in &lifetime.bounds {
|
||||
@@ -2064,10 +2062,7 @@ pub fn print_lifetime_def(&mut self,
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_generics(&mut self,
|
||||
generics: &hir::Generics)
|
||||
-> io::Result<()>
|
||||
{
|
||||
pub fn print_generics(&mut self, generics: &hir::Generics) -> io::Result<()> {
|
||||
let total = generics.lifetimes.len() + generics.ty_params.len();
|
||||
if total == 0 {
|
||||
return Ok(());
|
||||
@@ -2080,16 +2075,18 @@ pub fn print_generics(&mut self,
|
||||
ints.push(i);
|
||||
}
|
||||
|
||||
try!(self.commasep(Inconsistent, &ints[..], |s, &idx| {
|
||||
if idx < generics.lifetimes.len() {
|
||||
let lifetime = &generics.lifetimes[idx];
|
||||
s.print_lifetime_def(lifetime)
|
||||
} else {
|
||||
let idx = idx - generics.lifetimes.len();
|
||||
let param = &generics.ty_params[idx];
|
||||
s.print_ty_param(param)
|
||||
}
|
||||
}));
|
||||
try!(self.commasep(Inconsistent,
|
||||
&ints[..],
|
||||
|s, &idx| {
|
||||
if idx < generics.lifetimes.len() {
|
||||
let lifetime = &generics.lifetimes[idx];
|
||||
s.print_lifetime_def(lifetime)
|
||||
} else {
|
||||
let idx = idx - generics.lifetimes.len();
|
||||
let param = &generics.ty_params[idx];
|
||||
s.print_ty_param(param)
|
||||
}
|
||||
}));
|
||||
|
||||
try!(word(&mut self.s, ">"));
|
||||
Ok(())
|
||||
@@ -2104,12 +2101,11 @@ pub fn print_ty_param(&mut self, param: &hir::TyParam) -> io::Result<()> {
|
||||
try!(self.word_space("="));
|
||||
self.print_type(&**default)
|
||||
}
|
||||
_ => Ok(())
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_where_clause(&mut self, where_clause: &hir::WhereClause)
|
||||
-> io::Result<()> {
|
||||
pub fn print_where_clause(&mut self, where_clause: &hir::WhereClause) -> io::Result<()> {
|
||||
if where_clause.predicates.is_empty() {
|
||||
return Ok(())
|
||||
}
|
||||
@@ -2183,23 +2179,24 @@ pub fn print_view_path(&mut self, vp: &hir::ViewPath) -> io::Result<()> {
|
||||
try!(self.print_path(path, false, 0));
|
||||
try!(word(&mut self.s, "::{"));
|
||||
}
|
||||
try!(self.commasep(Inconsistent, &segments[..], |s, w| {
|
||||
match w.node {
|
||||
hir::PathListIdent { name, .. } => {
|
||||
s.print_name(name)
|
||||
},
|
||||
hir::PathListMod { .. } => {
|
||||
word(&mut s.s, "self")
|
||||
}
|
||||
}
|
||||
}));
|
||||
try!(self.commasep(Inconsistent,
|
||||
&segments[..],
|
||||
|s, w| {
|
||||
match w.node {
|
||||
hir::PathListIdent { name, .. } => {
|
||||
s.print_name(name)
|
||||
}
|
||||
hir::PathListMod { .. } => {
|
||||
word(&mut s.s, "self")
|
||||
}
|
||||
}
|
||||
}));
|
||||
word(&mut self.s, "}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_mutability(&mut self,
|
||||
mutbl: hir::Mutability) -> io::Result<()> {
|
||||
pub fn print_mutability(&mut self, mutbl: hir::Mutability) -> io::Result<()> {
|
||||
match mutbl {
|
||||
hir::MutMutable => self.word_nbsp("mut"),
|
||||
hir::MutImmutable => Ok(()),
|
||||
@@ -2243,17 +2240,15 @@ pub fn print_fn_output(&mut self, decl: &hir::FnDecl) -> io::Result<()> {
|
||||
try!(self.ibox(indent_unit));
|
||||
try!(self.word_space("->"));
|
||||
match decl.output {
|
||||
hir::NoReturn(_) =>
|
||||
try!(self.word_nbsp("!")),
|
||||
hir::NoReturn(_) => try!(self.word_nbsp("!")),
|
||||
hir::DefaultReturn(..) => unreachable!(),
|
||||
hir::Return(ref ty) =>
|
||||
try!(self.print_type(&**ty))
|
||||
hir::Return(ref ty) => try!(self.print_type(&**ty)),
|
||||
}
|
||||
try!(self.end());
|
||||
|
||||
match decl.output {
|
||||
hir::Return(ref output) => self.maybe_print_comment(output.span.lo),
|
||||
_ => Ok(())
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2289,27 +2284,33 @@ pub fn print_ty_fn(&mut self,
|
||||
self.end()
|
||||
}
|
||||
|
||||
pub fn maybe_print_trailing_comment(&mut self, span: codemap::Span,
|
||||
pub fn maybe_print_trailing_comment(&mut self,
|
||||
span: codemap::Span,
|
||||
next_pos: Option<BytePos>)
|
||||
-> io::Result<()> {
|
||||
-> io::Result<()> {
|
||||
let cm = match self.cm {
|
||||
Some(cm) => cm,
|
||||
_ => return Ok(())
|
||||
_ => return Ok(()),
|
||||
};
|
||||
match self.next_comment() {
|
||||
Some(ref cmnt) => {
|
||||
if (*cmnt).style != comments::Trailing { return Ok(()) }
|
||||
if (*cmnt).style != comments::Trailing {
|
||||
return Ok(())
|
||||
}
|
||||
let span_line = cm.lookup_char_pos(span.hi);
|
||||
let comment_line = cm.lookup_char_pos((*cmnt).pos);
|
||||
let mut next = (*cmnt).pos + BytePos(1);
|
||||
match next_pos { None => (), Some(p) => next = p }
|
||||
match next_pos {
|
||||
None => (),
|
||||
Some(p) => next = p,
|
||||
}
|
||||
if span.hi < (*cmnt).pos && (*cmnt).pos < next &&
|
||||
span_line.line == comment_line.line {
|
||||
try!(self.print_comment(cmnt));
|
||||
self.cur_cmnt_and_lit.cur_cmnt += 1;
|
||||
}
|
||||
span_line.line == comment_line.line {
|
||||
try!(self.print_comment(cmnt));
|
||||
self.cur_cmnt_and_lit.cur_cmnt += 1;
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
_ => (),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -2326,7 +2327,7 @@ pub fn print_remaining_comments(&mut self) -> io::Result<()> {
|
||||
try!(self.print_comment(cmnt));
|
||||
self.cur_cmnt_and_lit.cur_cmnt += 1;
|
||||
}
|
||||
_ => break
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -2334,25 +2335,24 @@ pub fn print_remaining_comments(&mut self) -> io::Result<()> {
|
||||
|
||||
pub fn print_opt_abi_and_extern_if_nondefault(&mut self,
|
||||
opt_abi: Option<abi::Abi>)
|
||||
-> io::Result<()> {
|
||||
-> io::Result<()> {
|
||||
match opt_abi {
|
||||
Some(abi::Rust) => Ok(()),
|
||||
Some(abi) => {
|
||||
try!(self.word_nbsp("extern"));
|
||||
self.word_nbsp(&abi.to_string())
|
||||
}
|
||||
None => Ok(())
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_extern_opt_abi(&mut self,
|
||||
opt_abi: Option<abi::Abi>) -> io::Result<()> {
|
||||
pub fn print_extern_opt_abi(&mut self, opt_abi: Option<abi::Abi>) -> io::Result<()> {
|
||||
match opt_abi {
|
||||
Some(abi) => {
|
||||
try!(self.word_nbsp("extern"));
|
||||
self.word_nbsp(&abi.to_string())
|
||||
}
|
||||
None => Ok(())
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2360,13 +2360,14 @@ pub fn print_fn_header_info(&mut self,
|
||||
unsafety: hir::Unsafety,
|
||||
constness: hir::Constness,
|
||||
abi: abi::Abi,
|
||||
vis: hir::Visibility) -> io::Result<()> {
|
||||
vis: hir::Visibility)
|
||||
-> io::Result<()> {
|
||||
try!(word(&mut self.s, &visibility_qualified(vis, "")));
|
||||
try!(self.print_unsafety(unsafety));
|
||||
|
||||
match constness {
|
||||
hir::Constness::NotConst => {}
|
||||
hir::Constness::Const => try!(self.word_nbsp("const"))
|
||||
hir::Constness::Const => try!(self.word_nbsp("const")),
|
||||
}
|
||||
|
||||
if abi != abi::Rust {
|
||||
@@ -2395,12 +2396,12 @@ pub fn print_unsafety(&mut self, s: hir::Unsafety) -> io::Result<()> {
|
||||
/// isn't parsed as (if true {...} else {...} | x) | 5
|
||||
fn expr_requires_semi_to_be_stmt(e: &hir::Expr) -> bool {
|
||||
match e.node {
|
||||
hir::ExprIf(..)
|
||||
| hir::ExprMatch(..)
|
||||
| hir::ExprBlock(_)
|
||||
| hir::ExprWhile(..)
|
||||
| hir::ExprLoop(..) => false,
|
||||
_ => true
|
||||
hir::ExprIf(..) |
|
||||
hir::ExprMatch(..) |
|
||||
hir::ExprBlock(_) |
|
||||
hir::ExprWhile(..) |
|
||||
hir::ExprLoop(..) => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2412,10 +2413,14 @@ fn stmt_ends_with_semi(stmt: &hir::Stmt_) -> bool {
|
||||
hir::StmtDecl(ref d, _) => {
|
||||
match d.node {
|
||||
hir::DeclLocal(_) => true,
|
||||
hir::DeclItem(_) => false
|
||||
hir::DeclItem(_) => false,
|
||||
}
|
||||
}
|
||||
hir::StmtExpr(ref e, _) => { expr_requires_semi_to_be_stmt(&**e) }
|
||||
hir::StmtSemi(..) => { false }
|
||||
hir::StmtExpr(ref e, _) => {
|
||||
expr_requires_semi_to_be_stmt(&**e)
|
||||
}
|
||||
hir::StmtSemi(..) => {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+53
-46
@@ -17,9 +17,13 @@
|
||||
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 @@ fn walk_pat_<G>(pat: &Pat, it: &mut G) -> bool where G: 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 @@ fn visit_generics_helper(&mut self, generics: &Generics) {
|
||||
}
|
||||
|
||||
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 @@ fn visit_fn(&mut self,
|
||||
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(),
|
||||
}),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
+90
-51
@@ -56,25 +56,56 @@ fn visit_name(&mut self, _span: Span, _name: Name) {
|
||||
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 @@ fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: &'v TraitBoundModifie
|
||||
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 @@ fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &'v PathPa
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user