librustc: Implement the syntax in the RFC for unboxed closure sugar.

Part of issue #16640. I am leaving this issue open to handle parsing of
higher-rank lifetimes in traits.

This change breaks code that used unboxed closures:

* Instead of `F:|&: int| -> int`, write `F:Fn(int) -> int`.

* Instead of `F:|&mut: int| -> int`, write `F:FnMut(int) -> int`.

* Instead of `F:|: int| -> int`, write `F:FnOnce(int) -> int`.

[breaking-change]
This commit is contained in:
Patrick Walton
2014-09-05 21:27:47 -07:00
parent 9c41064308
commit 7c00d77e8b
17 changed files with 207 additions and 117 deletions

View File

@@ -657,16 +657,26 @@ pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> {
})
}
pub fn noop_fold_ty_param_bound<T: Folder>(tpb: TyParamBound, fld: &mut T)
-> TyParamBound {
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)),
RegionTyParamBound(lifetime) => RegionTyParamBound(fld.fold_lifetime(lifetime)),
UnboxedFnTyParamBound(UnboxedFnTy {decl, kind}) => {
UnboxedFnTyParamBound(UnboxedFnTy {
decl: fld.fold_fn_decl(decl),
kind: kind,
})
UnboxedFnTyParamBound(bound) => {
match *bound {
UnboxedFnBound {
ref path,
ref decl,
ref_id
} => {
UnboxedFnTyParamBound(P(UnboxedFnBound {
path: fld.fold_path(path.clone()),
decl: fld.fold_fn_decl(decl.clone()),
ref_id: fld.new_id(ref_id),
}))
}
}
}
}
}