1
Fork 0

auto merge of #18743 : nikomatsakis/rust/hrtb-refactor-2, r=pcwalton

Various miscellaneous changes pushing towards HRTB support:

1. Update parser and adjust ast to support `for<'a,'b>` syntax, both in closures and trait bounds. Warn on the old syntax (not error, for stage0).
2. Refactor TyTrait representation to include a TraitRef.
3. Purge `once_fns` feature gate and `once` keyword.

r? @pcwalton 

This is a [breaking-change]:

- The `once_fns` feature is now officially deprecated. Rewrite using normal closures or unboxed closures.
- The new `for`-based syntax now issues warnings (but not yet errors):
  - `fn<'a>(T) -> U` becomes `for<'a> fn(T) -> U`
  - `<'a> |T| -> U` becomes `for<'a> |T| -> U`
This commit is contained in:
bors 2014-11-09 03:51:41 +00:00
commit a2f303ad09
52 changed files with 748 additions and 736 deletions

View file

@ -227,6 +227,10 @@ pub trait Folder {
noop_fold_trait_ref(p, self)
}
fn fold_poly_trait_ref(&mut self, p: PolyTraitRef) -> PolyTraitRef {
noop_fold_poly_trait_ref(p, self)
}
fn fold_struct_def(&mut self, struct_def: P<StructDef>) -> P<StructDef> {
noop_fold_struct_def(struct_def, self)
}
@ -442,7 +446,10 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> {
TyFixedLengthVec(ty, e) => {
TyFixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e))
}
TyTypeof(expr) => TyTypeof(fld.fold_expr(expr))
TyTypeof(expr) => TyTypeof(fld.fold_expr(expr)),
TyPolyTraitRef(poly_trait_ref) => {
TyPolyTraitRef(poly_trait_ref.map(|p| fld.fold_poly_trait_ref(p)))
},
},
span: fld.new_span(span)
})
@ -711,7 +718,7 @@ pub fn noop_fold_ty_param_bound<T>(tpb: TyParamBound, fld: &mut T)
-> TyParamBound
where T: Folder {
match tpb {
TraitTyParamBound(ty) => TraitTyParamBound(fld.fold_trait_ref(ty)),
TraitTyParamBound(ty) => TraitTyParamBound(fld.fold_poly_trait_ref(ty)),
RegionTyParamBound(lifetime) => RegionTyParamBound(fld.fold_lifetime(lifetime)),
}
}
@ -722,7 +729,7 @@ pub fn noop_fold_ty_param<T: Folder>(tp: TyParam, fld: &mut T) -> TyParam {
id: fld.new_id(id),
ident: ident,
bounds: fld.fold_bounds(bounds),
unbound: unbound.map(|x| fld.fold_ty_param_bound(x)),
unbound: unbound.map(|x| fld.fold_trait_ref(x)),
default: default.map(|x| fld.fold_ty(x)),
span: span
}
@ -842,13 +849,18 @@ pub fn noop_fold_trait_ref<T: Folder>(p: TraitRef, fld: &mut T) -> TraitRef {
let id = fld.new_id(p.ref_id);
let TraitRef {
path,
lifetimes,
..
ref_id: _,
} = p;
ast::TraitRef {
path: fld.fold_path(path),
ref_id: id,
lifetimes: fld.fold_lifetime_defs(lifetimes),
}
}
pub fn noop_fold_poly_trait_ref<T: Folder>(p: PolyTraitRef, fld: &mut T) -> PolyTraitRef {
ast::PolyTraitRef {
bound_lifetimes: fld.fold_lifetime_defs(p.bound_lifetimes),
trait_ref: fld.fold_trait_ref(p.trait_ref)
}
}