about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Mansi <markm@cs.wisc.edu>2019-05-06 16:31:59 -0500
committerMark Mansi <markm@cs.wisc.edu>2019-05-07 17:37:37 -0500
commit606bb6f6fe4cfb6e3054e90cc400553f280ad94a (patch)
tree7bb147f57bfd364bc080e1097d85d7a0483f3a14
parent6d26c5f73ca1c6d1615c141b181374e152cab61a (diff)
downloadrust-606bb6f6fe4cfb6e3054e90cc400553f280ad94a.tar.gz
rust-606bb6f6fe4cfb6e3054e90cc400553f280ad94a.zip
avoid extra copy
-rw-r--r--src/libsyntax/ext/tt/transcribe.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs
index 5eb5475b2a9..424b94173a7 100644
--- a/src/libsyntax/ext/tt/transcribe.rs
+++ b/src/libsyntax/ext/tt/transcribe.rs
@@ -98,16 +98,11 @@ pub fn transcribe(
         };
 
         match tree {
-            quoted::TokenTree::Sequence(sp, seq) => {
-                // FIXME(pcwalton): Bad copy.
-                match lockstep_iter_size(
-                    &quoted::TokenTree::Sequence(sp, seq.clone()),
-                    &interpolations,
-                    &repeats,
-                ) {
+            seq @ quoted::TokenTree::Sequence(..) => {
+                match lockstep_iter_size(&seq, interp, &repeats) {
                     LockstepIterSize::Unconstrained => {
                         cx.span_fatal(
-                            sp.entire(), /* blame macro writer */
+                            seq.span(), /* blame macro writer */
                             "attempted to repeat an expression \
                              containing no syntax \
                              variables matched as repeating at this depth",
@@ -115,9 +110,15 @@ pub fn transcribe(
                     }
                     LockstepIterSize::Contradiction(ref msg) => {
                         // FIXME #2887 blame macro invoker instead
-                        cx.span_fatal(sp.entire(), &msg[..]);
+                        cx.span_fatal(seq.span(), &msg[..]);
                     }
                     LockstepIterSize::Constraint(len, _) => {
+                        let (sp, seq) = if let quoted::TokenTree::Sequence(sp, seq) = seq {
+                            (sp, seq)
+                        } else {
+                            unreachable!()
+                        };
+
                         if len == 0 {
                             if seq.op == quoted::KleeneOp::OneOrMore {
                                 // FIXME #2887 blame invoker
@@ -201,10 +202,8 @@ enum LockstepIterSize {
     Contradiction(String),
 }
 
-impl Add for LockstepIterSize {
-    type Output = LockstepIterSize;
-
-    fn add(self, other: LockstepIterSize) -> LockstepIterSize {
+impl LockstepIterSize {
+    fn with(self, other: LockstepIterSize) -> LockstepIterSize {
         match self {
             LockstepIterSize::Unconstrained => other,
             LockstepIterSize::Contradiction(_) => self,