diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2014-08-27 21:46:52 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2014-08-27 21:46:52 -0400 |
| commit | 1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f (patch) | |
| tree | 552fabade603ab0d148a49ae3cf1abd3f399740a /src/libsyntax/fold.rs | |
| parent | 3ee047ae1ffab454270bc1859b3beef3556ef8f9 (diff) | |
| download | rust-1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f.tar.gz rust-1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f.zip | |
Implement generalized object and type parameter bounds (Fixes #16462)
Diffstat (limited to 'src/libsyntax/fold.rs')
| -rw-r--r-- | src/libsyntax/fold.rs | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 4a0787aeb9e..be1c0d96711 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -227,15 +227,20 @@ pub trait Folder { noop_fold_variant_arg(va, self) } - fn fold_ty_param_bound(&mut self, tpb: &TyParamBound) -> TyParamBound { - noop_fold_ty_param_bound(tpb, self) - } - 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> { + noop_fold_bounds(b, self) + } + + fn fold_ty_param_bound(&mut self, tpb: &TyParamBound) -> TyParamBound { + noop_fold_ty_param_bound(tpb, self) + } + fn fold_mt(&mut self, mt: &MutTy) -> MutTy { noop_fold_mt(mt, self) } @@ -349,20 +354,20 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> { TyRptr(ref region, ref mt) => { TyRptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt)) } - TyClosure(ref f, ref region) => { + TyClosure(ref f) => { TyClosure(box(GC) ClosureTy { fn_style: f.fn_style, onceness: f.onceness, - bounds: fld.fold_opt_bounds(&f.bounds), + bounds: fld.fold_bounds(&f.bounds), decl: fld.fold_fn_decl(&*f.decl), lifetimes: fld.fold_lifetime_defs(f.lifetimes.as_slice()), - }, fld.fold_opt_lifetime(region)) + }) } TyProc(ref f) => { TyProc(box(GC) ClosureTy { fn_style: f.fn_style, onceness: f.onceness, - bounds: fld.fold_opt_bounds(&f.bounds), + bounds: fld.fold_bounds(&f.bounds), decl: fld.fold_fn_decl(&*f.decl), lifetimes: fld.fold_lifetime_defs(f.lifetimes.as_slice()), }) @@ -648,14 +653,13 @@ pub fn noop_fold_ty_param_bound<T: Folder>(tpb: &TyParamBound, fld: &mut T) -> TyParamBound { match *tpb { TraitTyParamBound(ref ty) => TraitTyParamBound(fld.fold_trait_ref(ty)), - StaticRegionTyParamBound => StaticRegionTyParamBound, + RegionTyParamBound(ref lifetime) => RegionTyParamBound(fld.fold_lifetime(lifetime)), UnboxedFnTyParamBound(ref unboxed_function_type) => { UnboxedFnTyParamBound(UnboxedFnTy { decl: fld.fold_fn_decl(&*unboxed_function_type.decl), kind: unboxed_function_type.kind, }) } - OtherRegionTyParamBound(s) => OtherRegionTyParamBound(s) } } @@ -664,7 +668,7 @@ pub fn noop_fold_ty_param<T: Folder>(tp: &TyParam, fld: &mut T) -> TyParam { TyParam { ident: tp.ident, id: id, - bounds: tp.bounds.map(|x| fld.fold_ty_param_bound(x)), + bounds: fld.fold_bounds(&tp.bounds), unbound: tp.unbound.as_ref().map(|x| fld.fold_ty_param_bound(x)), default: tp.default.map(|x| fld.fold_ty(x)), span: tp.span @@ -792,11 +796,12 @@ pub fn noop_fold_mt<T: Folder>(mt: &MutTy, folder: &mut T) -> MutTy { pub fn noop_fold_opt_bounds<T: Folder>(b: &Option<OwnedSlice<TyParamBound>>, folder: &mut T) -> Option<OwnedSlice<TyParamBound>> { - b.as_ref().map(|bounds| { - bounds.map(|bound| { - folder.fold_ty_param_bound(bound) - }) - }) + b.as_ref().map(|bounds| folder.fold_bounds(bounds)) +} + +fn noop_fold_bounds<T: Folder>(bounds: &TyParamBounds, folder: &mut T) + -> TyParamBounds { + bounds.map(|bound| folder.fold_ty_param_bound(bound)) } pub fn noop_fold_variant_arg<T: Folder>(va: &VariantArg, folder: &mut T) -> VariantArg { @@ -889,7 +894,8 @@ pub fn noop_fold_item_underscore<T: Folder>(i: &Item_, folder: &mut T) -> Item_ }).collect() ) } - ItemTrait(ref generics, ref unbound, ref traits, ref methods) => { + ItemTrait(ref generics, ref unbound, ref bounds, ref methods) => { + let bounds = folder.fold_bounds(bounds); let methods = methods.iter().flat_map(|method| { let r = match *method { RequiredMethod(ref m) => { @@ -911,7 +917,7 @@ pub fn noop_fold_item_underscore<T: Folder>(i: &Item_, folder: &mut T) -> Item_ }).collect(); ItemTrait(folder.fold_generics(generics), unbound.clone(), - traits.iter().map(|p| folder.fold_trait_ref(p)).collect(), + bounds, methods) } ItemMac(ref m) => ItemMac(folder.fold_mac(m)), |
