Take advantage of the lifetime refactoring

This commit is contained in:
varkor
2018-05-31 15:52:17 +01:00
parent 6015edf9af
commit 831b5c02df
8 changed files with 50 additions and 66 deletions

View File

@@ -143,6 +143,10 @@ pub trait Folder : Sized {
noop_fold_ty(t, self)
}
fn fold_lifetime(&mut self, l: Lifetime) -> Lifetime {
noop_fold_lifetime(l, self)
}
fn fold_ty_binding(&mut self, t: TypeBinding) -> TypeBinding {
noop_fold_ty_binding(t, self)
}
@@ -240,10 +244,6 @@ pub trait Folder : Sized {
noop_fold_variant_data(vdata, self)
}
fn fold_ty_param(&mut self, tp: TyParam) -> TyParam {
noop_fold_ty_param(tp, self)
}
fn fold_generic_param(&mut self, param: GenericParam) -> GenericParam {
noop_fold_generic_param(param, self)
}
@@ -268,17 +268,16 @@ pub trait Folder : Sized {
noop_fold_interpolated(nt, self)
}
fn fold_opt_bounds(&mut self, b: Option<TyParamBounds>) -> Option<TyParamBounds> {
fn fold_opt_bounds(&mut self, b: Option<ParamBounds>) -> Option<ParamBounds> {
noop_fold_opt_bounds(b, self)
}
fn fold_bounds(&mut self, b: ParamBounds)
-> ParamBounds {
fn fold_bounds(&mut self, b: ParamBounds) -> ParamBounds {
noop_fold_bounds(b, self)
}
fn fold_ty_param_bound(&mut self, tpb: ParamBound) -> ParamBound {
noop_fold_ty_param_bound(tpb, self)
fn fold_param_bound(&mut self, tpb: ParamBound) -> ParamBound {
noop_fold_param_bound(tpb, self)
}
fn fold_mt(&mut self, mt: MutTy) -> MutTy {
@@ -391,10 +390,10 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
TyKind::Typeof(fld.fold_anon_const(expr))
}
TyKind::TraitObject(bounds, syntax) => {
TyKind::TraitObject(bounds.move_map(|b| fld.fold_ty_param_bound(b)), syntax)
TyKind::TraitObject(bounds.move_map(|b| fld.fold_param_bound(b)), syntax)
}
TyKind::ImplTrait(bounds) => {
TyKind::ImplTrait(bounds.move_map(|b| fld.fold_ty_param_bound(b)))
TyKind::ImplTrait(bounds.move_map(|b| fld.fold_param_bound(b)))
}
TyKind::Mac(mac) => {
TyKind::Mac(fld.fold_mac(mac))
@@ -677,32 +676,31 @@ pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> {
})
}
pub fn noop_fold_ty_param_bound<T>(tpb: ParamBound, fld: &mut T)
-> ParamBound
where T: Folder {
match tpb {
TraitTyParamBound(ty, modifier) => TraitTyParamBound(fld.fold_poly_trait_ref(ty), modifier),
pub fn noop_fold_param_bound<T>(pb: ParamBound, fld: &mut T) -> ParamBound where T: Folder {
match pb {
TraitTyParamBound(ty, modifier) => {
TraitTyParamBound(fld.fold_poly_trait_ref(ty), modifier)
}
Outlives(lifetime) => Outlives(noop_fold_lifetime(lifetime, fld)),
}
}
pub fn noop_fold_generic_param<T: Folder>(param: GenericParam, fld: &mut T) -> GenericParam {
match param.kind {
GenericParamKind::Lifetime { bounds, lifetime } => {
let attrs: Vec<_> = param.attrs.into();
GenericParamKind::Lifetime(LifetimeDef {
attrs: attrs.into_iter()
let attrs: Vec<_> = param.attrs.into();
GenericParam {
ident: fld.fold_ident(param.ident),
id: fld.new_id(param.id),
attrs: attrs.into_iter()
.flat_map(|x| fld.fold_attribute(x).into_iter())
.collect::<Vec<_>>()
.into(),
lifetime: Lifetime {
id: fld.new_id(param.id),
ident: fld.fold_ident(param.ident),
},
bounds: bounds.move_map(|l| noop_fold_lifetime(l, fld)),
})
bounds: param.bounds.move_map(|l| noop_fold_param_bound(l, fld)),
kind: match param.kind {
GenericParamKind::Lifetime => GenericParamKind::Lifetime,
GenericParamKind::Type { default } => GenericParamKind::Type {
default: default.map(|ty| fld.fold_ty(ty))
}
}
GenericParamKind::Type { .. } => GenericParamKind::Type(fld.fold_ty_param(param)),
}
}
@@ -760,7 +758,7 @@ pub fn noop_fold_where_predicate<T: Folder>(
ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
bound_generic_params: fld.fold_generic_params(bound_generic_params),
bounded_ty: fld.fold_ty(bounded_ty),
bounds: bounds.move_map(|x| fld.fold_ty_param_bound(x)),
bounds: bounds.move_map(|x| fld.fold_param_bound(x)),
span: fld.new_span(span)
})
}
@@ -770,7 +768,7 @@ pub fn noop_fold_where_predicate<T: Folder>(
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
span: fld.new_span(span),
lifetime: noop_fold_lifetime(lifetime, fld),
bounds: bounds.move_map(|bound| noop_fold_lifetime(bound, fld))
bounds: bounds.move_map(|bound| noop_fold_param_bound(bound, fld))
})
}
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{id,
@@ -856,7 +854,7 @@ pub fn noop_fold_opt_bounds<T: Folder>(b: Option<ParamBounds>, folder: &mut T)
fn noop_fold_bounds<T: Folder>(bounds: ParamBounds, folder: &mut T)
-> ParamBounds {
bounds.move_map(|bound| folder.fold_ty_param_bound(bound))
bounds.move_map(|bound| folder.fold_param_bound(bound))
}
pub fn noop_fold_block<T: Folder>(b: P<Block>, folder: &mut T) -> P<Block> {