about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-09-23 04:39:27 -0700
committerNiko Matsakis <niko@alum.mit.edu>2012-09-23 13:30:13 -0500
commitba3eebd41db384c2a46535e8db8c7b2337d55f0b (patch)
tree0a746d1b95cd85358fa07aca67683524c8dd1f79 /src/libsyntax
parent2e7ddee8239ceba5989c5dfd83e9a935775b00d1 (diff)
downloadrust-ba3eebd41db384c2a46535e8db8c7b2337d55f0b.tar.gz
rust-ba3eebd41db384c2a46535e8db8c7b2337d55f0b.zip
Make it illegal to use modes in a fn signature with providing
an explicit variable name. (Step one to changing the defaults)

First step to #3535
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs2
-rw-r--r--src/libsyntax/ext/auto_serialize.rs8
-rw-r--r--src/libsyntax/ext/expand.rs2
-rw-r--r--src/libsyntax/ext/pipes/ast_builder.rs4
-rw-r--r--src/libsyntax/fold.rs46
-rw-r--r--src/libsyntax/parse/obsolete.rs8
-rw-r--r--src/libsyntax/parse/parser.rs16
7 files changed, 51 insertions, 35 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 3f41c03b927..94536924afe 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -34,7 +34,7 @@ type spanned<T> = {node: T, span: span};
 /* can't import macros yet, so this is copied from token.rs. See its comment
  * there. */
 macro_rules! interner_key (
-    () => (cast::transmute::<(uint, uint), &fn(+@@token::ident_interner)>(
+    () => (cast::transmute::<(uint, uint), &fn(+v: @@token::ident_interner)>(
         (-3 as uint, 0u)))
 )
 
diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs
index 5e99314712f..4ebb8501041 100644
--- a/src/libsyntax/ext/auto_serialize.rs
+++ b/src/libsyntax/ext/auto_serialize.rs
@@ -351,8 +351,8 @@ fn ser_variant(cx: ext_ctxt,
                span: span,
                -s: @ast::expr,
                pfn: fn(~[@ast::pat]) -> ast::pat_,
-               bodyfn: fn(-@ast::expr, ast::blk) -> @ast::expr,
-               argfn: fn(-@ast::expr, uint, ast::blk) -> @ast::expr)
+               bodyfn: fn(-v: @ast::expr, ast::blk) -> @ast::expr,
+               argfn: fn(-v: @ast::expr, uint, ast::blk) -> @ast::expr)
     -> ast::arm {
     let vnames = do vec::from_fn(vec::len(tys)) |i| {
         cx.parse_sess().interner.intern(@fmt!("__v%u", i))
@@ -535,7 +535,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
 fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
              tps: ~[ast::ty_param],
              f: fn(ext_ctxt, ser_tps_map,
-                   -@ast::expr, -@ast::expr) -> ~[@ast::stmt])
+                   -v: @ast::expr, -v: @ast::expr) -> ~[@ast::stmt])
     -> @ast::item {
     let ext_cx = cx; // required for #ast
 
@@ -747,7 +747,7 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map,
 
 fn mk_deser_fn(cx: ext_ctxt, span: span,
                name: ast::ident, tps: ~[ast::ty_param],
-               f: fn(ext_ctxt, deser_tps_map, -@ast::expr) -> @ast::expr)
+               f: fn(ext_ctxt, deser_tps_map, -v: @ast::expr) -> @ast::expr)
     -> @ast::item {
     let ext_cx = cx; // required for #ast
 
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index ffe86c94a24..dbe475c1b50 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -167,7 +167,7 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
 // When we enter a module, record it, for the sake of `module!`
 fn expand_item(exts: HashMap<~str, syntax_extension>,
                cx: ext_ctxt, &&it: @ast::item, fld: ast_fold,
-               orig: fn@(&&@ast::item, ast_fold) -> Option<@ast::item>)
+               orig: fn@(&&v: @ast::item, ast_fold) -> Option<@ast::item>)
     -> Option<@ast::item>
 {
     let is_mod = match it.node {
diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs
index 1b25ea73f07..bfe0f4dd0e6 100644
--- a/src/libsyntax/ext/pipes/ast_builder.rs
+++ b/src/libsyntax/ext/pipes/ast_builder.rs
@@ -77,9 +77,9 @@ trait ext_ctxt_ast_builder {
     fn item_ty(name: ident, span: span, ty: @ast::ty) -> @ast::item;
     fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::ty];
     fn ty_field_imm(name: ident, ty: @ast::ty) -> ast::ty_field;
-    fn ty_rec(+~[ast::ty_field]) -> @ast::ty;
+    fn ty_rec(+v: ~[ast::ty_field]) -> @ast::ty;
     fn field_imm(name: ident, e: @ast::expr) -> ast::field;
-    fn rec(+~[ast::field]) -> @ast::expr;
+    fn rec(+v: ~[ast::field]) -> @ast::expr;
     fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk;
     fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt;
     fn stmt_expr(e: @ast::expr) -> @ast::stmt;
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index f9b1959f051..07362e1b31e 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -20,27 +20,27 @@ export extensions;
 
 trait ast_fold {
     fn fold_crate(crate) -> crate;
-    fn fold_crate_directive(&&@crate_directive) -> @crate_directive;
-    fn fold_view_item(&&@view_item) -> @view_item;
-    fn fold_foreign_item(&&@foreign_item) -> @foreign_item;
-    fn fold_item(&&@item) -> Option<@item>;
-    fn fold_struct_field(&&@struct_field) -> @struct_field;
+    fn fold_crate_directive(&&v: @crate_directive) -> @crate_directive;
+    fn fold_view_item(&&v: @view_item) -> @view_item;
+    fn fold_foreign_item(&&v: @foreign_item) -> @foreign_item;
+    fn fold_item(&&v: @item) -> Option<@item>;
+    fn fold_struct_field(&&v: @struct_field) -> @struct_field;
     fn fold_item_underscore(item_) -> item_;
-    fn fold_method(&&@method) -> @method;
+    fn fold_method(&&v: @method) -> @method;
     fn fold_block(blk) -> blk;
-    fn fold_stmt(&&@stmt) -> @stmt;
+    fn fold_stmt(&&v: @stmt) -> @stmt;
     fn fold_arm(arm) -> arm;
-    fn fold_pat(&&@pat) -> @pat;
-    fn fold_decl(&&@decl) -> @decl;
-    fn fold_expr(&&@expr) -> @expr;
-    fn fold_ty(&&@ty) -> @ty;
+    fn fold_pat(&&v: @pat) -> @pat;
+    fn fold_decl(&&v: @decl) -> @decl;
+    fn fold_expr(&&v: @expr) -> @expr;
+    fn fold_ty(&&v: @ty) -> @ty;
     fn fold_mod(_mod) -> _mod;
     fn fold_foreign_mod(foreign_mod) -> foreign_mod;
     fn fold_variant(variant) -> variant;
-    fn fold_ident(&&ident) -> ident;
-    fn fold_path(&&@path) -> @path;
-    fn fold_local(&&@local) -> @local;
-    fn map_exprs(fn@(&&@expr) -> @expr, ~[@expr]) -> ~[@expr];
+    fn fold_ident(&&v: ident) -> ident;
+    fn fold_path(&&v: @path) -> @path;
+    fn fold_local(&&v: @local) -> @local;
+    fn map_exprs(fn@(&&v: @expr) -> @expr, ~[@expr]) -> ~[@expr];
     fn new_id(node_id) -> node_id;
     fn new_span(span) -> span;
 }
@@ -53,11 +53,11 @@ type ast_fold_precursor = @{
     fold_crate_directive: fn@(crate_directive_, span,
                               ast_fold) -> (crate_directive_, span),
     fold_view_item: fn@(view_item_, ast_fold) -> view_item_,
-    fold_foreign_item: fn@(&&@foreign_item, ast_fold) -> @foreign_item,
-    fold_item: fn@(&&@item, ast_fold) -> Option<@item>,
-    fold_struct_field: fn@(&&@struct_field, ast_fold) -> @struct_field,
+    fold_foreign_item: fn@(&&v: @foreign_item, ast_fold) -> @foreign_item,
+    fold_item: fn@(&&v: @item, ast_fold) -> Option<@item>,
+    fold_struct_field: fn@(&&v: @struct_field, ast_fold) -> @struct_field,
     fold_item_underscore: fn@(item_, ast_fold) -> item_,
-    fold_method: fn@(&&@method, ast_fold) -> @method,
+    fold_method: fn@(&&v: @method, ast_fold) -> @method,
     fold_block: fn@(blk_, span, ast_fold) -> (blk_, span),
     fold_stmt: fn@(stmt_, span, ast_fold) -> (stmt_, span),
     fold_arm: fn@(arm, ast_fold) -> arm,
@@ -68,10 +68,10 @@ type ast_fold_precursor = @{
     fold_mod: fn@(_mod, ast_fold) -> _mod,
     fold_foreign_mod: fn@(foreign_mod, ast_fold) -> foreign_mod,
     fold_variant: fn@(variant_, span, ast_fold) -> (variant_, span),
-    fold_ident: fn@(&&ident, ast_fold) -> ident,
+    fold_ident: fn@(&&v: ident, ast_fold) -> ident,
     fold_path: fn@(path, ast_fold) -> path,
     fold_local: fn@(local_, span, ast_fold) -> (local_, span),
-    map_exprs: fn@(fn@(&&@expr) -> @expr, ~[@expr]) -> ~[@expr],
+    map_exprs: fn@(fn@(&&v: @expr) -> @expr, ~[@expr]) -> ~[@expr],
     new_id: fn@(node_id) -> node_id,
     new_span: fn@(span) -> span};
 
@@ -643,7 +643,7 @@ fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
 
 /* temporarily eta-expand because of a compiler bug with using `fn<T>` as a
    value */
-fn noop_map_exprs(f: fn@(&&@expr) -> @expr, es: ~[@expr]) -> ~[@expr] {
+fn noop_map_exprs(f: fn@(&&v: @expr) -> @expr, es: ~[@expr]) -> ~[@expr] {
     return vec::map(es, |x| f(*x));
 }
 
@@ -773,7 +773,7 @@ impl ast_fold_precursor: ast_fold {
         let (n, s) = self.fold_local(x.node, x.span, self as ast_fold);
         return @{node: n, span: self.new_span(s)};
     }
-    fn map_exprs(f: fn@(&&@expr) -> @expr, e: ~[@expr]) -> ~[@expr] {
+    fn map_exprs(f: fn@(&&v: @expr) -> @expr, e: ~[@expr]) -> ~[@expr] {
         self.map_exprs(f, e)
     }
     fn new_id(node_id: ast::node_id) -> node_id {
diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs
index 3891e7b6d17..d787123bf61 100644
--- a/src/libsyntax/parse/obsolete.rs
+++ b/src/libsyntax/parse/obsolete.rs
@@ -21,7 +21,8 @@ pub enum ObsoleteSyntax {
     ObsoleteWith,
     ObsoleteClassMethod,
     ObsoleteClassTraits,
-    ObsoletePrivSection
+    ObsoletePrivSection,
+    ObsoleteModeInFnType
 }
 
 #[cfg(stage0)]
@@ -99,6 +100,11 @@ impl parser : ObsoleteReporter {
                 "the `priv` keyword is applied to individual items, methods, \
                  and fields"
             ),
+            ObsoleteModeInFnType => (
+                "mode without identifier in fn type",
+                "to use a (deprecated) mode in a fn type, you should \
+                 give the argument an explicit name (like `&&v: int`)"
+            ),
         };
 
         self.report(sp, kind, kind_str, desc);
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index a6ad5b35484..f2e7245a1d4 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -19,7 +19,8 @@ use obsolete::{
     ObsoleteReporter, ObsoleteSyntax,
     ObsoleteLowerCaseKindBounds, ObsoleteLet,
     ObsoleteFieldTerminator, ObsoleteStructCtor,
-    ObsoleteWith, ObsoleteClassMethod, ObsoleteClassTraits
+    ObsoleteWith, ObsoleteClassMethod, ObsoleteClassTraits,
+    ObsoleteModeInFnType
 };
 use ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute,
              bind_by_ref, bind_by_implicit_ref, bind_by_value, bind_by_move,
@@ -618,6 +619,15 @@ impl parser {
             } else { special_idents::invalid }
         };
 
+        match m {
+            expl(_) => {
+                if i == special_idents::invalid {
+                    self.obsolete(copy self.span, ObsoleteModeInFnType);
+                }
+            }
+            _ => {}
+        }
+
         let t = self.parse_ty(false);
 
         {mode: m, ty: t, ident: i, id: self.get_id()}
@@ -1585,7 +1595,7 @@ impl parser {
     }
 
     fn parse_sugary_call_expr(keyword: ~str,
-                              ctor: fn(+@expr) -> expr_) -> @expr {
+                              ctor: fn(+v: @expr) -> expr_) -> @expr {
         let lo = self.last_span;
         // Parse the callee `foo` in
         //    for foo || {
@@ -2400,7 +2410,7 @@ impl parser {
                                     fn(parser) -> arg_or_capture_item)
                             -> (self_ty, fn_decl, capture_clause) {
 
-        fn maybe_parse_self_ty(cnstr: fn(+mutability) -> ast::self_ty_,
+        fn maybe_parse_self_ty(cnstr: fn(+v: mutability) -> ast::self_ty_,
                                p: parser) -> ast::self_ty_ {
             // We need to make sure it isn't a mode or a type
             if p.token_is_keyword(~"self", p.look_ahead(1)) ||