about summary refs log tree commit diff
path: root/src/libsyntax_ext
diff options
context:
space:
mode:
authorWang Xuerui <idontknw.wang@gmail.com>2016-05-17 01:02:42 +0800
committerWang Xuerui <idontknw.wang@gmail.com>2016-07-14 02:54:47 +0800
commit06b034ae8b418beab7d0767a9a8d29023558d701 (patch)
treedeeae34e65e8aef561d7d04b9873c134ca9b24bd /src/libsyntax_ext
parent71949f3b0dfdacbddc0c012accefbb8e8ec759d4 (diff)
downloadrust-06b034ae8b418beab7d0767a9a8d29023558d701.tar.gz
rust-06b034ae8b418beab7d0767a9a8d29023558d701.zip
format: remove all implicit ref handling outside of libfmt_macros
format: beautifully get rid of ArgumentNext and CountIsNextParam

Now that CountIsNextParam and ArgumentNext are resolved during parse,
the need for handling them outside of libfmt_macros is obviated.

Note: *one* instance of implicit reference handling still remains, and
that's for implementing `all_args_simple`. It's trivial enough though,
so in this case it may be tolerable.
Diffstat (limited to 'src/libsyntax_ext')
-rw-r--r--src/libsyntax_ext/format.rs29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs
index dc572e652c6..c0150e5ce1d 100644
--- a/src/libsyntax_ext/format.rs
+++ b/src/libsyntax_ext/format.rs
@@ -68,8 +68,10 @@ struct Context<'a, 'b:'a> {
 
     name_positions: HashMap<String, usize>,
 
-    /// Updated as arguments are consumed
-    next_arg: usize,
+    /// Current position of the implicit positional arg pointer, as if it
+    /// still existed in this phase of processing.
+    /// Used only for `all_pieces_simple` tracking in `trans_piece`.
+    curarg: usize,
 }
 
 /// Parses the arguments from the given list of tokens, returning None
@@ -159,11 +161,6 @@ impl<'a, 'b> Context<'a, 'b> {
                 // argument second, if it's an implicit positional parameter
                 // it's written second, so it should come after width/precision.
                 let pos = match arg.position {
-                    parse::ArgumentNext => {
-                        let i = self.next_arg;
-                        self.next_arg += 1;
-                        Exact(i)
-                    }
                     parse::ArgumentIs(i) => Exact(i),
                     parse::ArgumentNamed(s) => Named(s.to_string()),
                 };
@@ -183,11 +180,6 @@ impl<'a, 'b> Context<'a, 'b> {
             parse::CountIsName(s) => {
                 self.verify_arg_type(Named(s.to_string()), Unsigned);
             }
-            parse::CountIsNextParam => {
-                let next_arg = self.next_arg;
-                self.verify_arg_type(Exact(next_arg), Unsigned);
-                self.next_arg += 1;
-            }
         }
     }
 
@@ -309,7 +301,6 @@ impl<'a, 'b> Context<'a, 'b> {
                 count("Param", Some(self.ecx.expr_usize(sp, i)))
             }
             parse::CountImplied => count("Implied", None),
-            parse::CountIsNextParam => count("NextParam", None),
             parse::CountIsName(n) => {
                 let i = match self.name_positions.get(n) {
                     Some(&i) => i,
@@ -355,8 +346,6 @@ impl<'a, 'b> Context<'a, 'b> {
                         }
                     };
                     match arg.position {
-                        // These two have a direct mapping
-                        parse::ArgumentNext => pos("Next", None),
                         parse::ArgumentIs(i) => pos("At", Some(i)),
 
                         // Named arguments are converted to positional arguments
@@ -373,7 +362,13 @@ impl<'a, 'b> Context<'a, 'b> {
                 };
 
                 let simple_arg = parse::Argument {
-                    position: parse::ArgumentNext,
+                    position: {
+                        // We don't have ArgumentNext any more, so we have to
+                        // track the current argument ourselves.
+                        let i = self.curarg;
+                        self.curarg += 1;
+                        parse::ArgumentIs(i)
+                    },
                     format: parse::FormatSpec {
                         fill: arg.format.fill,
                         align: parse::AlignUnknown,
@@ -640,7 +635,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
         name_positions: HashMap::new(),
         name_types: HashMap::new(),
         name_ordering: name_ordering,
-        next_arg: 0,
+        curarg: 0,
         literal: String::new(),
         pieces: Vec::new(),
         str_pieces: Vec::new(),