From 035c01af93fd23f10e233a8a9b651af20744e1d1 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 10 May 2013 15:57:27 -0400 Subject: Add BuiltinBounds to closure type: parse and handle subtyping, but do not integrate with kindck etc (requires a snapshot first) --- src/libsyntax/ast.rs | 3 ++- src/libsyntax/fold.rs | 1 + src/libsyntax/parse/parser.rs | 23 +++++++++++++---------- 3 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 4a3ae7d94ad..dcbbd7ab531 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -828,7 +828,8 @@ pub struct TyClosure { lifetimes: OptVec, purity: purity, onceness: Onceness, - decl: fn_decl + decl: fn_decl, + bounds: OptVec } #[deriving(Eq, Encodable, Decodable)] diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index f6dbbbf420d..275a7b963a4 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -589,6 +589,7 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ { purity: f.purity, region: f.region, onceness: f.onceness, + bounds: f.bounds.map(|x| fold_ty_param_bound(x, fld)), decl: fold_fn_decl(&f.decl, fld), lifetimes: copy f.lifetimes, }) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ce9bbe7e17a..25b45a5f3b5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -395,12 +395,13 @@ pub impl Parser { -> ty_ { /* - (&|~|@) ['r] [pure|unsafe] [once] fn <'lt> (S) -> T - ^~~~~~^ ^~~^ ^~~~~~~~~~~~^ ^~~~~^ ^~~~^ ^~^ ^ - | | | | | | | - | | | | | | Return type - | | | | | Argument types - | | | | Lifetimes + (&|~|@) ['r] [pure|unsafe] [once] fn [:Bounds] <'lt> (S) -> T + ^~~~~~^ ^~~^ ^~~~~~~~~~~~^ ^~~~~^ ^~~~~~~~^ ^~~~^ ^~^ ^ + | | | | | | | | + | | | | | | | Return type + | | | | | | Argument types + | | | | | Lifetimes + | | | | Closure bounds | | | Once-ness (a.k.a., affine) | | Purity | Lifetime bound @@ -414,6 +415,7 @@ pub impl Parser { let purity = self.parse_unsafety(); let onceness = parse_onceness(self); self.expect_keyword("fn"); + let bounds = self.parse_optional_ty_param_bounds(); if self.parse_fn_ty_sigil().is_some() { self.obsolete(*self.span, ObsoletePostFnTySigil); @@ -426,6 +428,7 @@ pub impl Parser { region: region, purity: purity, onceness: onceness, + bounds: bounds, decl: decl, lifetimes: lifetimes, }); @@ -2851,9 +2854,9 @@ pub impl Parser { // matches optbounds = ( ( : ( boundseq )? )? ) // where boundseq = ( bound + boundseq ) | bound // and bound = 'static | ty - fn parse_optional_ty_param_bounds(&self) -> @OptVec { + fn parse_optional_ty_param_bounds(&self) -> OptVec { if !self.eat(&token::COLON) { - return @opt_vec::Empty; + return opt_vec::Empty; } let mut result = opt_vec::Empty; @@ -2907,13 +2910,13 @@ pub impl Parser { } } - return @result; + return result; } // matches typaram = IDENT optbounds fn parse_ty_param(&self) -> TyParam { let ident = self.parse_ident(); - let bounds = self.parse_optional_ty_param_bounds(); + let bounds = @self.parse_optional_ty_param_bounds(); ast::TyParam { ident: ident, id: self.get_id(), bounds: bounds } } -- cgit 1.4.1-3-g733a5