]> git.lizzy.rs Git - rust.git/commitdiff
libsyntax: Allow `+` to separate trait bounds from objects.
authorPatrick Walton <pcwalton@mimiga.net>
Wed, 11 Jun 2014 19:14:38 +0000 (12:14 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 13 Jun 2014 20:53:34 +0000 (13:53 -0700)
RFC #27.

After a snapshot, the old syntax will be removed.

This can break some code that looked like `foo as &Trait:Send`. Now you
will need to write `foo as (&Trait+Send)`.

Closes #12778.

[breaking-change]

24 files changed:
src/librustc/middle/typeck/astconv.rs
src/librustc/middle/typeck/infer/error_reporting.rs
src/librustdoc/clean/mod.rs
src/libsyntax/ast.rs
src/libsyntax/ast_util.rs
src/libsyntax/fold.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs
src/libsyntax/visit.rs
src/test/auxiliary/plugin_crate_outlive_expansion_phase.rs
src/test/compile-fail/issue-7013.rs
src/test/compile-fail/kindck-copy.rs
src/test/compile-fail/kindck-send.rs
src/test/compile-fail/trait-bounds-cant-coerce.rs
src/test/compile-fail/trait-bounds-sugar.rs
src/test/run-fail/fail-macro-any.rs
src/test/run-pass/alignment-gep-tup-like-1.rs
src/test/run-pass/as-precedence.rs [new file with mode: 0644]
src/test/run-pass/capturing-logging.rs
src/test/run-pass/close-over-big-then-small-data.rs
src/test/run-pass/trait-bounds-basic.rs
src/test/run-pass/trait-bounds-in-arc.rs
src/test/run-pass/trait-cast.rs
src/test/run-pass/trait-contravariant-self.rs

index 83c5be238168a1f163ee8ede7eda4911d9af18a7..f380004fb081e7cccf564928794eed18c9396812 100644 (file)
@@ -724,6 +724,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
                                  .collect();
                 ty::mk_tup(tcx, flds)
             }
+            ast::TyParen(ref typ) => ast_ty_to_ty(this, rscope, &**typ),
             ast::TyBareFn(ref bf) => {
                 if bf.decl.variadic && bf.abi != abi::C {
                     tcx.sess.span_err(ast_ty.span,
index 2e02c798339eae63a5ee060e72e20545a10a0ab3..4d396ed4f6e5cccfaa7ecc6fd5ddf9b68394a2e5 100644 (file)
@@ -1140,6 +1140,7 @@ fn build_to(from: ast::P<ast::Ty>,
                     }
                     ast::TyTup(new_tys)
                 }
+                ast::TyParen(ref typ) => ast::TyParen(build_to(*typ, to)),
                 ref other => other.clone()
             };
             box(GC) ast::Ty { id: from.id, node: new_node, span: from.span }
index dd6cc978ae71c93cf800c9b796991c5407b5d3ac..7e68be09f1d56041d365163db73c5e3a3b8fc6e7 100644 (file)
@@ -60,7 +60,7 @@ fn clean(&self) -> VecPerParamSpace<U> {
     }
 }
 
-impl<T: Clean<U>, U> Clean<U> for Gc<T> {
+impl<T: 'static + Clean<U>, U> Clean<U> for Gc<T> {
     fn clean(&self) -> U {
         (**self).clean()
     }
@@ -1198,6 +1198,7 @@ fn clean(&self) -> Type {
             TyClosure(ref c, region) => Closure(box c.clean(), region.clean()),
             TyProc(ref c) => Proc(box c.clean()),
             TyBareFn(ref barefn) => BareFunction(box barefn.clean()),
+            TyParen(ref ty) => ty.clean(),
             TyBot => Bottom,
             ref x => fail!("Unimplemented type {:?}", x),
         }
index 941078b158b87718cc0e9a94e9b16d4d42884b2c..b8e08dab722eaa292bccfbfae387277e4b3e913c 100644 (file)
@@ -784,6 +784,8 @@ pub enum Ty_ {
     TyUnboxedFn(Gc<UnboxedFnTy>),
     TyTup(Vec<P<Ty>> ),
     TyPath(Path, Option<OwnedSlice<TyParamBound>>, NodeId), // for #7264; see above
+    // No-op; kept solely so that we can pretty-print faithfully
+    TyParen(P<Ty>),
     TyTypeof(Gc<Expr>),
     // TyInfer means the type should be inferred instead of it having been
     // specified. This can appear anywhere in a type.
index fcddbfa9a89b957b499f3830cb7e7cd77b3fcb23..8e0a2218ea369f7f8b12d960fb977ff6ef8b98cc 100644 (file)
@@ -737,6 +737,7 @@ pub fn get_inner_tys(ty: P<Ty>) -> Vec<P<Ty>> {
         | ast::TyUniq(ty)
         | ast::TyFixedLengthVec(ty, _) => vec!(ty),
         ast::TyTup(ref tys) => tys.clone(),
+        ast::TyParen(ty) => get_inner_tys(ty),
         _ => Vec::new()
     }
 }
index d8c7ffe4db7ac185f22d0973e5758c5785224178..d61a79e4e80be3e0a298c208640430866c5a192b 100644 (file)
@@ -192,6 +192,7 @@ fn fold_ty(&mut self, t: P<Ty>) -> P<Ty> {
                 })
             }
             TyTup(ref tys) => TyTup(tys.iter().map(|&ty| self.fold_ty(ty)).collect()),
+            TyParen(ref ty) => TyParen(self.fold_ty(*ty)),
             TyPath(ref path, ref bounds, id) => {
                 let id = self.new_id(id);
                 TyPath(self.fold_path(path),
index aaedb5709550d2e32e4105920404bfe623ebc899..e1a45e5643d2597ca9c01d889ee16ff7df091c4e 100644 (file)
@@ -51,7 +51,7 @@
 use ast::{TTNonterminal, TupleVariantKind, Ty, Ty_, TyBot, TyBox};
 use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn};
 use ast::{TyTypeof, TyInfer, TypeMethod};
-use ast::{TyNil, TyParam, TyParamBound, TyPath, TyPtr, TyRptr};
+use ast::{TyNil, TyParam, TyParamBound, TyParen, TyPath, TyPtr, TyRptr};
 use ast::{TyTup, TyU32, TyUnboxedFn, TyUniq, TyVec, UnUniq};
 use ast::{UnboxedFnTy, UnboxedFnTyParamBound, UnnamedField, UnsafeBlock};
 use ast::{UnsafeFn, ViewItem, ViewItem_, ViewItemExternCrate, ViewItemUse};
@@ -105,7 +105,7 @@ pub enum PathParsingMode {
     /// the type parameters; e.g. `foo::bar::<'a>::Baz::<T>`
     LifetimeAndTypesWithColons,
     /// A path with a lifetime and type parameters with bounds before the last
-    /// set of type parameters only; e.g. `foo::bar<'a>::Baz:X+Y<T>` This
+    /// set of type parameters only; e.g. `foo::bar<'a>::Baz+X+Y<T>` This
     /// form does not use extra double colons.
     LifetimeAndTypesAndBounds,
 }
@@ -1015,7 +1015,14 @@ pub fn parse_proc_type(&mut self) -> Ty_ {
         };
 
         let (inputs, variadic) = self.parse_fn_args(false, false);
-        let (_, bounds) = self.parse_optional_ty_param_bounds(false);
+        let bounds = {
+            if self.eat(&token::COLON) {
+                let (_, bounds) = self.parse_ty_param_bounds(false);
+                Some(bounds)
+            } else {
+                None
+            }
+        };
         let (ret_style, ret_ty) = self.parse_ret_ty();
         let decl = P(FnDecl {
             inputs: inputs,
@@ -1083,7 +1090,14 @@ pub fn parse_ty_closure(&mut self) -> Ty_ {
             (is_unboxed, inputs)
         };
 
-        let (region, bounds) = self.parse_optional_ty_param_bounds(true);
+        let (region, bounds) = {
+            if self.eat(&token::COLON) {
+                let (region, bounds) = self.parse_ty_param_bounds(true);
+                (region, Some(bounds))
+            } else {
+                (None, None)
+            }
+        };
 
         let (return_style, output) = self.parse_ret_ty();
         let decl = P(FnDecl {
@@ -1227,7 +1241,7 @@ pub fn parse_trait_methods(&mut self) -> Vec<TraitMethod> {
     // parse a possibly mutable type
     pub fn parse_mt(&mut self) -> MutTy {
         let mutbl = self.parse_mutability();
-        let t = self.parse_ty(false);
+        let t = self.parse_ty(true);
         MutTy { ty: t, mutbl: mutbl }
     }
 
@@ -1238,7 +1252,7 @@ pub fn parse_ty_field(&mut self) -> TypeField {
         let mutbl = self.parse_mutability();
         let id = self.parse_ident();
         self.expect(&token::COLON);
-        let ty = self.parse_ty(false);
+        let ty = self.parse_ty(true);
         let hi = ty.span.hi;
         ast::TypeField {
             ident: id,
@@ -1261,7 +1275,7 @@ pub fn parse_ret_ty(&mut self) -> (RetStyle, P<Ty>) {
                     })
                 )
             } else {
-                (Return, self.parse_ty(false))
+                (Return, self.parse_ty(true))
             }
         } else {
             let pos = self.span.lo;
@@ -1276,10 +1290,11 @@ pub fn parse_ret_ty(&mut self) -> (RetStyle, P<Ty>) {
         }
     }
 
-    // parse a type.
-    // Useless second parameter for compatibility with quasiquote macros.
-    // Bleh!
-    pub fn parse_ty(&mut self, _: bool) -> P<Ty> {
+    /// Parse a type.
+    ///
+    /// The second parameter specifies whether the `+` binary operator is
+    /// allowed in the type grammar.
+    pub fn parse_ty(&mut self, plus_allowed: bool) -> P<Ty> {
         maybe_whole!(no_clone self, NtTy);
 
         let lo = self.span.lo;
@@ -1293,12 +1308,12 @@ pub fn parse_ty(&mut self, _: bool) -> P<Ty> {
                 // (t) is a parenthesized ty
                 // (t,) is the type of a tuple with only one field,
                 // of type t
-                let mut ts = vec!(self.parse_ty(false));
+                let mut ts = vec!(self.parse_ty(true));
                 let mut one_tuple = false;
                 while self.token == token::COMMA {
                     self.bump();
                     if self.token != token::RPAREN {
-                        ts.push(self.parse_ty(false));
+                        ts.push(self.parse_ty(true));
                     }
                     else {
                         one_tuple = true;
@@ -1307,17 +1322,17 @@ pub fn parse_ty(&mut self, _: bool) -> P<Ty> {
 
                 if ts.len() == 1 && !one_tuple {
                     self.expect(&token::RPAREN);
-                    return *ts.get(0)
+                    TyParen(*ts.get(0))
+                } else {
+                    let t = TyTup(ts);
+                    self.expect(&token::RPAREN);
+                    t
                 }
-
-                let t = TyTup(ts);
-                self.expect(&token::RPAREN);
-                t
             }
         } else if self.token == token::AT {
             // MANAGED POINTER
             self.bump();
-            TyBox(self.parse_ty(false))
+            TyBox(self.parse_ty(plus_allowed))
         } else if self.token == token::TILDE {
             // OWNED POINTER
             self.bump();
@@ -1326,7 +1341,7 @@ pub fn parse_ty(&mut self, _: bool) -> P<Ty> {
                     self.obsolete(self.last_span, ObsoleteOwnedVector),
                 _ => self.obsolete(self.last_span, ObsoleteOwnedType),
             };
-            TyUniq(self.parse_ty(false))
+            TyUniq(self.parse_ty(true))
         } else if self.token == token::BINOP(token::STAR) {
             // STAR POINTER (bare pointer?)
             self.bump();
@@ -1334,7 +1349,7 @@ pub fn parse_ty(&mut self, _: bool) -> P<Ty> {
         } else if self.token == token::LBRACKET {
             // VECTOR
             self.expect(&token::LBRACKET);
-            let t = self.parse_ty(false);
+            let t = self.parse_ty(true);
 
             // Parse the `, ..e` in `[ int, ..e ]`
             // where `e` is a const expression
@@ -1377,10 +1392,15 @@ pub fn parse_ty(&mut self, _: bool) -> P<Ty> {
         } else if self.token == token::MOD_SEP
             || is_ident_or_path(&self.token) {
             // NAMED TYPE
+            let mode = if plus_allowed {
+                LifetimeAndTypesAndBounds
+            } else {
+                LifetimeAndTypesWithoutColons
+            };
             let PathAndBounds {
                 path,
                 bounds
-            } = self.parse_path(LifetimeAndTypesAndBounds);
+            } = self.parse_path(mode);
             TyPath(path, bounds, ast::DUMMY_NODE_ID)
         } else if self.eat(&token::UNDERSCORE) {
             // TYPE TO BE INFERRED
@@ -1438,7 +1458,7 @@ pub fn parse_arg_general(&mut self, require_name: bool) -> Arg {
                                    special_idents::invalid)
         };
 
-        let t = self.parse_ty(false);
+        let t = self.parse_ty(true);
 
         Arg {
             ty: t,
@@ -1456,7 +1476,7 @@ pub fn parse_arg(&mut self) -> Arg {
     pub fn parse_fn_block_arg(&mut self) -> Arg {
         let pat = self.parse_pat();
         let t = if self.eat(&token::COLON) {
-            self.parse_ty(false)
+            self.parse_ty(true)
         } else {
             P(Ty {
                 id: ast::DUMMY_NODE_ID,
@@ -1611,9 +1631,19 @@ pub fn parse_path(&mut self, mode: PathParsingMode) -> PathAndBounds {
             }
         }
 
-        // Next, parse a colon and bounded type parameters, if applicable.
+        // Next, parse a plus and bounded type parameters, if applicable.
+        //
+        // NOTE(stage0, pcwalton): Remove `token::COLON` after a snapshot.
         let bounds = if mode == LifetimeAndTypesAndBounds {
-            let (_, bounds) = self.parse_optional_ty_param_bounds(false);
+            let bounds = {
+                if self.eat(&token::BINOP(token::PLUS)) ||
+                        self.eat(&token::COLON) {
+                    let (_, bounds) = self.parse_ty_param_bounds(false);
+                    Some(bounds)
+                } else {
+                    None
+                }
+            };
             bounds
         } else {
             None
@@ -2438,7 +2468,7 @@ pub fn parse_more_binops(&mut self, lhs: Gc<Expr>,
             }
             None => {
                 if as_prec > min_prec && self.eat_keyword(keywords::As) {
-                    let rhs = self.parse_ty(true);
+                    let rhs = self.parse_ty(false);
                     let _as = self.mk_expr(lhs.span.lo,
                                            rhs.span.hi,
                                            ExprCast(lhs, rhs));
@@ -3067,7 +3097,9 @@ fn parse_local(&mut self) -> Gc<Local> {
             node: TyInfer,
             span: mk_sp(lo, lo),
         });
-        if self.eat(&token::COLON) { ty = self.parse_ty(false); }
+        if self.eat(&token::COLON) {
+            ty = self.parse_ty(true);
+        }
         let init = self.parse_initializer();
         box(GC) ast::Local {
             ty: ty,
@@ -3095,7 +3127,7 @@ fn parse_name_and_ty(&mut self, pr: Visibility,
         }
         let name = self.parse_ident();
         self.expect(&token::COLON);
-        let ty = self.parse_ty(false);
+        let ty = self.parse_ty(true);
         spanned(lo, self.last_span.hi, ast::StructField_ {
             kind: NamedField(name, pr),
             id: ast::DUMMY_NODE_ID,
@@ -3427,7 +3459,7 @@ fn parse_unboxed_function_type(&mut self) -> UnboxedFnTy {
         }
     }
 
-    // matches optbounds = ( ( : ( boundseq )? )? )
+    // matches bounds    = ( boundseq )?
     // where   boundseq  = ( bound + boundseq ) | bound
     // and     bound     = 'static | ty
     // Returns "None" if there's no colon (e.g. "T");
@@ -3439,13 +3471,9 @@ fn parse_unboxed_function_type(&mut self) -> UnboxedFnTy {
     // AST doesn't support arbitrary lifetimes in bounds on type parameters. In
     // the future, this flag should be removed, and the return value of this
     // function should be Option<~[TyParamBound]>
-    fn parse_optional_ty_param_bounds(&mut self, allow_any_lifetime: bool)
-        -> (Option<ast::Lifetime>, Option<OwnedSlice<TyParamBound>>)
-    {
-        if !self.eat(&token::COLON) {
-            return (None, None);
-        }
-
+    fn parse_ty_param_bounds(&mut self, allow_any_lifetime: bool)
+                             -> (Option<ast::Lifetime>,
+                                 OwnedSlice<TyParamBound>) {
         let mut ret_lifetime = None;
         let mut result = vec!();
         loop {
@@ -3489,7 +3517,7 @@ fn parse_optional_ty_param_bounds(&mut self, allow_any_lifetime: bool)
             }
         }
 
-        return (ret_lifetime, Some(OwnedSlice::from_vec(result)));
+        return (ret_lifetime, OwnedSlice::from_vec(result));
     }
 
     // matches typaram = type? IDENT optbounds ( EQ ty )?
@@ -3497,13 +3525,20 @@ fn parse_ty_param(&mut self) -> TyParam {
         let sized = self.parse_sized();
         let span = self.span;
         let ident = self.parse_ident();
-        let (_, opt_bounds) = self.parse_optional_ty_param_bounds(false);
+        let opt_bounds = {
+            if self.eat(&token::COLON) {
+                let (_, bounds) = self.parse_ty_param_bounds(false);
+                Some(bounds)
+            } else {
+                None
+            }
+        };
         // For typarams we don't care about the difference b/w "<T>" and "<T:>".
         let bounds = opt_bounds.unwrap_or_default();
 
         let default = if self.token == token::EQ {
             self.bump();
-            Some(self.parse_ty(false))
+            Some(self.parse_ty(true))
         }
         else { None };
 
@@ -3548,7 +3583,7 @@ fn parse_generic_values_after_lt(&mut self) -> (Vec<ast::Lifetime>, Vec<P<Ty>> )
             Some(token::COMMA),
             |p| {
                 p.forbid_lifetime();
-                p.parse_ty(false)
+                p.parse_ty(true)
             }
         );
         (lifetimes, result.into_vec())
@@ -3804,7 +3839,7 @@ fn parse_fn_block_decl(&mut self) -> P<FnDecl> {
             }
         };
         let output = if self.eat(&token::RARROW) {
-            self.parse_ty(false)
+            self.parse_ty(true)
         } else {
             P(Ty {
                 id: ast::DUMMY_NODE_ID,
@@ -3830,7 +3865,7 @@ fn parse_proc_decl(&mut self) -> P<FnDecl> {
                                      |p| p.parse_fn_block_arg());
 
         let output = if self.eat(&token::RARROW) {
-            self.parse_ty(false)
+            self.parse_ty(true)
         } else {
             P(Ty {
                 id: ast::DUMMY_NODE_ID,
@@ -3942,7 +3977,7 @@ fn parse_item_impl(&mut self) -> ItemInfo {
         let could_be_trait = self.token != token::LPAREN;
 
         // Parse the trait.
-        let mut ty = self.parse_ty(false);
+        let mut ty = self.parse_ty(true);
 
         // Parse traits, if necessary.
         let opt_trait = if could_be_trait && self.eat_keyword(keywords::For) {
@@ -3965,7 +4000,7 @@ fn parse_item_impl(&mut self) -> ItemInfo {
                 }
             };
 
-            ty = self.parse_ty(false);
+            ty = self.parse_ty(true);
             opt_trait_ref
         } else {
             None
@@ -4008,7 +4043,7 @@ fn parse_item_struct(&mut self, is_virtual: bool) -> ItemInfo {
         let generics = self.parse_generics();
 
         let super_struct = if self.eat(&token::COLON) {
-            let ty = self.parse_ty(false);
+            let ty = self.parse_ty(true);
             match ty.node {
                 TyPath(_, None, _) => {
                     Some(ty)
@@ -4051,7 +4086,7 @@ fn parse_item_struct(&mut self, is_virtual: bool) -> ItemInfo {
                 let struct_field_ = ast::StructField_ {
                     kind: UnnamedField(p.parse_visibility()),
                     id: ast::DUMMY_NODE_ID,
-                    ty: p.parse_ty(false),
+                    ty: p.parse_ty(true),
                     attrs: attrs,
                 };
                 spanned(lo, p.span.hi, struct_field_)
@@ -4205,7 +4240,7 @@ fn parse_item_const(&mut self) -> ItemInfo {
         let m = if self.eat_keyword(keywords::Mut) {MutMutable} else {MutImmutable};
         let id = self.parse_ident();
         self.expect(&token::COLON);
-        let ty = self.parse_ty(false);
+        let ty = self.parse_ty(true);
         self.expect(&token::EQ);
         let e = self.parse_expr();
         self.commit_expr_expecting(e, token::SEMI);
@@ -4386,7 +4421,7 @@ fn parse_item_foreign_static(&mut self, vis: ast::Visibility,
 
         let ident = self.parse_ident();
         self.expect(&token::COLON);
-        let ty = self.parse_ty(false);
+        let ty = self.parse_ty(true);
         let hi = self.span.hi;
         self.expect(&token::SEMI);
         box(GC) ast::ForeignItem {
@@ -4514,7 +4549,7 @@ fn parse_item_type(&mut self) -> ItemInfo {
         let ident = self.parse_ident();
         let tps = self.parse_generics();
         self.expect(&token::EQ);
-        let ty = self.parse_ty(false);
+        let ty = self.parse_ty(true);
         self.expect(&token::SEMI);
         (ident, ItemTy(ty, tps), None)
     }
@@ -4562,7 +4597,7 @@ fn parse_enum_def(&mut self, _generics: &ast::Generics) -> EnumDef {
                     &token::LPAREN,
                     &token::RPAREN,
                     seq_sep_trailing_disallowed(token::COMMA),
-                    |p| p.parse_ty(false)
+                    |p| p.parse_ty(true)
                 );
                 for ty in arg_tys.move_iter() {
                     args.push(ast::VariantArg {
index 77bc967b92d07070ad8c55fae92f9da18e482787..63acdb1a6ca758d576e585cc630d9d932cf1aaa3 100644 (file)
@@ -495,6 +495,11 @@ pub fn print_type(&mut self, ty: &ast::Ty) -> IoResult<()> {
                 }
                 try!(self.pclose());
             }
+            ast::TyParen(ref typ) => {
+                try!(self.popen());
+                try!(self.print_type(&**typ));
+                try!(self.pclose());
+            }
             ast::TyBareFn(f) => {
                 let generics = ast::Generics {
                     lifetimes: f.lifetimes.clone(),
@@ -1673,7 +1678,7 @@ fn print_path_(&mut self,
 
         match *opt_bounds {
             None => Ok(()),
-            Some(ref bounds) => self.print_bounds(&None, bounds, true),
+            Some(ref bounds) => self.print_bounds(&None, bounds, true, true),
         }
     }
 
@@ -1932,9 +1937,16 @@ pub fn print_proc_args(&mut self, decl: &ast::FnDecl) -> IoResult<()> {
     pub fn print_bounds(&mut self,
                         region: &Option<ast::Lifetime>,
                         bounds: &OwnedSlice<ast::TyParamBound>,
-                        print_colon_anyway: bool) -> IoResult<()> {
+                        print_colon_anyway: bool,
+                        print_plus_before_bounds: bool)
+                        -> IoResult<()> {
+        let separator = if print_plus_before_bounds {
+            "+"
+        } else {
+            ":"
+        };
         if !bounds.is_empty() || region.is_some() {
-            try!(word(&mut self.s, ":"));
+            try!(word(&mut self.s, separator));
             let mut first = true;
             match *region {
                 Some(ref lt) => {
@@ -1976,7 +1988,7 @@ pub fn print_bounds(&mut self,
             }
             Ok(())
         } else if print_colon_anyway {
-            word(&mut self.s, ":")
+            word(&mut self.s, separator)
         } else {
             Ok(())
         }
@@ -2011,7 +2023,10 @@ pub fn print_generics(&mut self,
                             try!(s.word_space("type"));
                         }
                         try!(s.print_ident(param.ident));
-                        try!(s.print_bounds(&None, &param.bounds, false));
+                        try!(s.print_bounds(&None,
+                                            &param.bounds,
+                                            false,
+                                            false));
                         match param.default {
                             Some(ref default) => {
                                 try!(space(&mut s.s));
@@ -2214,7 +2229,7 @@ pub fn print_ty_fn(&mut self,
         }
 
         opt_bounds.as_ref().map(|bounds| {
-            self.print_bounds(opt_region, bounds, true)
+            self.print_bounds(opt_region, bounds, true, false)
         });
 
         try!(self.maybe_print_comment(decl.output.span.lo));
index 59771a57dfa50bdfda64b19d89aaccc93aa530d7..6f0fc217533fc5070b25007d2bad6cfaa9aa9175 100644 (file)
@@ -336,7 +336,7 @@ pub fn skip_ty<E, V: Visitor<E>>(_: &mut V, _: &Ty, _: E) {
 
 pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
     match typ.node {
-        TyUniq(ty) | TyVec(ty) | TyBox(ty) => {
+        TyUniq(ty) | TyVec(ty) | TyBox(ty) | TyParen(ty) => {
             visitor.visit_ty(&*ty, env)
         }
         TyPtr(ref mutable_type) => {
index 213fdd6b74a292355cd4a39202c541e41c57ae6e..1592ffb6c6790b976f02901f91088a28717f3f88 100644 (file)
@@ -27,7 +27,7 @@ fn drop(&mut self) {}
 
 #[plugin_registrar]
 pub fn registrar(_: &mut Registry) {
-    local_data_key!(foo: Box<Any:Send>);
-    foo.replace(Some(box Foo { foo: 10 } as Box<Any:Send>));
+    local_data_key!(foo: Box<Any+Send>);
+    foo.replace(Some(box Foo { foo: 10 } as Box<Any+Send>));
 }
 
index 1bc4e0765532381e03c82576d76b7eb7f8f32b78..3028db00f5871801fdcd0c06cc12e91ebafa522d 100644 (file)
@@ -31,7 +31,7 @@ struct A {
 }
 
 fn main() {
-    let a = A {v: box B{v: None} as Box<Foo:Send>};
+    let a = A {v: box B{v: None} as Box<Foo+Send>};
     //~^ ERROR cannot pack type `~B`, which does not fulfill `Send`
     let v = Rc::new(RefCell::new(a));
     let w = v.clone();
index 5404b32eb2421d43551d56468428ef18a72eccd9..651ea6abf08ccf4df8874f58b593815f014b5818 100644 (file)
@@ -45,15 +45,15 @@ fn test<'a,T,U:Copy>(_: &'a int) {
 
     // borrowed object types are generally ok
     assert_copy::<&'a Dummy>();
-    assert_copy::<&'a Dummy:Copy>();
-    assert_copy::<&'static Dummy:Copy>();
+    assert_copy::<&'a Dummy+Copy>();
+    assert_copy::<&'static Dummy+Copy>();
 
     // owned object types are not ok
     assert_copy::<Box<Dummy>>(); //~ ERROR does not fulfill
-    assert_copy::<Box<Dummy:Copy>>(); //~ ERROR does not fulfill
+    assert_copy::<Box<Dummy+Copy>>(); //~ ERROR does not fulfill
 
     // mutable object types are not ok
-    assert_copy::<&'a mut Dummy:Copy>();  //~ ERROR does not fulfill
+    assert_copy::<&'a mut Dummy+Copy>();  //~ ERROR does not fulfill
 
     // closures are like an `&mut` object
     assert_copy::<||>(); //~ ERROR does not fulfill
index aa9d2dda22a960ae1e69c7f798a0fc4a7cc3dfe2..0414e64f1b7bf0dbc870da2506032d131178d332 100644 (file)
@@ -39,17 +39,17 @@ fn test<'a,T,U:Send>(_: &'a int) {
     // careful with object types, who knows what they close over...
     assert_send::<&'static Dummy>(); //~ ERROR does not fulfill `Send`
     assert_send::<&'a Dummy>(); //~ ERROR does not fulfill `Send`
-    assert_send::<&'a Dummy:Send>(); //~ ERROR does not fulfill `Send`
-    assert_send::<Box<Dummy:>>(); //~ ERROR does not fulfill `Send`
+    assert_send::<&'a Dummy+Send>(); //~ ERROR does not fulfill `Send`
+    assert_send::<Box<Dummy+>>(); //~ ERROR does not fulfill `Send`
 
     // ...unless they are properly bounded
-    assert_send::<&'static Dummy:Send>();
-    assert_send::<Box<Dummy:Send>>();
+    assert_send::<&'static Dummy+Send>();
+    assert_send::<Box<Dummy+Send>>();
 
     // but closure and object types can have lifetime bounds which make
     // them not ok (FIXME #5121)
     // assert_send::<proc:'a()>(); // ERROR does not fulfill `Send`
-    // assert_send::<Box<Dummy:'a>>(); // ERROR does not fulfill `Send`
+    // assert_send::<Box<Dummy+'a>>(); // ERROR does not fulfill `Send`
 
     // unsafe ptrs are ok unless they point at unsendable things
     assert_send::<*int>();
index 12205ef062da0877c1adfa4c99b79cac03d28a7c..3737025da6c121274315238753fc22dc1c5e5afa 100644 (file)
 trait Foo {
 }
 
-fn a(_x: Box<Foo:Send>) {
+fn a(_x: Box<Foo+Send>) {
 }
 
-fn c(x: Box<Foo:Share+Send>) {
+fn c(x: Box<Foo+Share+Send>) {
     a(x);
 }
 
-fn d(x: Box<Foo:>) {
+fn d(x: Box<Foo+>) {
     a(x); //~ ERROR found no bounds
 }
 
index 9447030a7f461aca92037bfb25dc19d66db3d0d6..d548098ebe13ed8dadb9a9a48b7e4ac1303a0932 100644 (file)
 
 trait Foo {}
 
-fn a(_x: Box<Foo:Send>) {
+fn a(_x: Box<Foo+Send>) {
 }
 
-fn b(_x: &'static Foo) { // should be same as &'static Foo:'static
+fn b(_x: &'static Foo) { // should be same as &'static Foo+'static
 }
 
-fn c(x: Box<Foo:Share>) {
+fn c(x: Box<Foo+Share>) {
     a(x); //~ ERROR expected bounds `Send`
 }
 
-fn d(x: &'static Foo:Share) {
+fn d(x: &'static Foo+Share) {
     b(x); //~ ERROR expected bounds `'static`
 }
 
index 09b507433080e23179e8b27e45f4dad2185f3f3b..c56eabbb3b4aae5468e9c6f9a9718079c28228ae 100644 (file)
@@ -12,5 +12,5 @@
 
 
 fn main() {
-    fail!(box 413 as Box<::std::any::Any:Send>);
+    fail!(box 413 as Box<::std::any::Any+Send>);
 }
index 38a3d3c5fffdc475bb19189098e3e6d33647e9af..4fa695de5228dd89d7954ca8a77d95a97058d4da 100644 (file)
@@ -33,7 +33,7 @@ fn f<A:Clone + 'static>(a: A, b: u16) -> Box<Invokable<A>:> {
     box Invoker {
         a: a,
         b: b,
-    } as Box<Invokable<A>>:
+    } as (Box<Invokable<A>>+)
 }
 
 pub fn main() {
diff --git a/src/test/run-pass/as-precedence.rs b/src/test/run-pass/as-precedence.rs
new file mode 100644 (file)
index 0000000..0760f13
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    assert_eq!(3 as uint * 3, 9);
+    assert_eq!(3 as (uint) * 3, 9);
+    assert_eq!(3 as (uint) / 3, 1);
+    assert_eq!(3 as uint + 3, 6);
+    assert_eq!(3 as (uint) + 3, 6);
+}
+
index 3402db7c355a942ac93127554baa1ccec5665c36..23607e16795edba637dce9a9a5de02de8200a3af 100644 (file)
@@ -41,7 +41,7 @@ fn main() {
     let (tx, rx) = channel();
     let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
     spawn(proc() {
-        set_logger(box MyWriter(w) as Box<Logger:Send>);
+        set_logger(box MyWriter(w) as Box<Logger+Send>);
         debug!("debug");
         info!("info");
     });
index acae61359370bb1d44f2c78904d786a900ea74a8..3d642be082c0ab3f25a857c50fa7f541f41b8aeb 100644 (file)
@@ -33,11 +33,11 @@ fn f(&self) -> (A, u16) {
     }
 }
 
-fn f<A:Clone + 'static>(a: A, b: u16) -> Box<Invokable<A>:> {
+fn f<A:Clone + 'static>(a: A, b: u16) -> Box<Invokable<A>+> {
     box Invoker {
         a: a,
         b: b,
-    } as Box<Invokable<A>>:
+    } as (Box<Invokable<A>>+)
 }
 
 pub fn main() {
index 68ebf2c6382ca2eee5747dc596ae0f4d933d4487..d1bb0db511b8fea838959f520a59f1b03bff0611 100644 (file)
 trait Foo {
 }
 
-fn a(_x: Box<Foo:>) {
+fn a(_x: Box<Foo+>) {
 }
 
-fn b(_x: Box<Foo:Send>) {
+fn b(_x: Box<Foo+Send>) {
 }
 
-fn c(x: Box<Foo:Share+Send>) {
+fn c(x: Box<Foo+Share+Send>) {
     a(x);
 }
 
-fn d(x: Box<Foo:Send>) {
+fn d(x: Box<Foo+Send>) {
     b(x);
 }
 
-fn e(x: Box<Foo>) { // sugar for Box<Foo:Owned>
+fn e(x: Box<Foo>) { // sugar for Box<Foo+Owned>
     a(x);
 }
 
index 4ca67811982d1c93c1c6278bfbe7566bdae27967..18a0e5d471c4a91fa3134034c6334ab324fee4d6 100644 (file)
@@ -71,10 +71,10 @@ pub fn main() {
         swim_speed: 998,
         name: "alec_guinness".to_string(),
     };
-    let arc = Arc::new(vec!(box catte  as Box<Pet:Share+Send>,
-                            box dogge1 as Box<Pet:Share+Send>,
-                            box fishe  as Box<Pet:Share+Send>,
-                            box dogge2 as Box<Pet:Share+Send>));
+    let arc = Arc::new(vec!(box catte  as Box<Pet+Share+Send>,
+                            box dogge1 as Box<Pet+Share+Send>,
+                            box fishe  as Box<Pet+Share+Send>,
+                            box dogge2 as Box<Pet+Share+Send>));
     let (tx1, rx1) = channel();
     let arc1 = arc.clone();
     task::spawn(proc() { check_legs(arc1); tx1.send(()); });
@@ -89,21 +89,21 @@ pub fn main() {
     rx3.recv();
 }
 
-fn check_legs(arc: Arc<Vec<Box<Pet:Share+Send>>>) {
+fn check_legs(arc: Arc<Vec<Box<Pet+Share+Send>>>) {
     let mut legs = 0;
     for pet in arc.iter() {
         legs += pet.num_legs();
     }
     assert!(legs == 12);
 }
-fn check_names(arc: Arc<Vec<Box<Pet:Share+Send>>>) {
+fn check_names(arc: Arc<Vec<Box<Pet+Share+Send>>>) {
     for pet in arc.iter() {
         pet.name(|name| {
             assert!(name[0] == 'a' as u8 && name[1] == 'l' as u8);
         })
     }
 }
-fn check_pedigree(arc: Arc<Vec<Box<Pet:Share+Send>>>) {
+fn check_pedigree(arc: Arc<Vec<Box<Pet+Share+Send>>>) {
     for pet in arc.iter() {
         assert!(pet.of_good_pedigree());
     }
index a9067ef87ba31ce5587fa1be8710347ccee181d8..0f99998b7a6edc2eeed8de5de0c55ceb7273a07d 100644 (file)
@@ -20,7 +20,7 @@
 struct TreeR {
     left: Option<Tree>,
     right: Option<Tree>,
-    val: Box<to_str:Send>
+    val: Box<to_str+Send>
 }
 
 trait to_str {
@@ -57,10 +57,10 @@ fn foo<T:to_str>(x: T) -> String { x.to_str_() }
 pub fn main() {
     let t1 = Tree(@RefCell::new(TreeR{left: None,
                                       right: None,
-                                      val: box 1 as Box<to_str:Send>}));
+                                      val: box 1 as Box<to_str+Send>}));
     let t2 = Tree(@RefCell::new(TreeR{left: Some(t1),
                                       right: Some(t1),
-                                      val: box 2 as Box<to_str:Send>}));
+                                      val: box 2 as Box<to_str+Send>}));
     let expected =
         "[2, some([1, none, none]), some([1, none, none])]".to_string();
     assert!(t2.to_str_() == expected);
index 1576c646286a4b6445a8ad5aab69b95233086aa3..d8df5d5600c902d98ccc995c1d0645e1c1e27bd5 100644 (file)
@@ -10,8 +10,8 @@
 
 // This is an interesting test case. We have a trait (Bar) that is
 // implemented for a `Box<Foo>` object (note: no bounds). And then we
-// have a `Box<Foo:Send>` object. The impl for `Box<Foo>` is applicable
-// to `Box<Foo:Send>` because:
+// have a `Box<Foo+Send>` object. The impl for `Box<Foo>` is applicable
+// to `Box<Foo+Send>` because:
 //
 // 1. The trait Bar is contravariant w/r/t Self because `Self` appears
 //    only in argument position.
@@ -30,7 +30,7 @@ impl Bar for Box<Foo> { fn dummy(&self) { } }
 fn wants_bar<B:Bar>(b: &B) { }
 
 fn main() {
-    let x: Box<Foo:Send> = (box SFoo);
+    let x: Box<Foo+Send> = (box SFoo);
     wants_bar(&x);
 }