]> git.lizzy.rs Git - rust.git/commitdiff
libsyntax: convert `LockstepIterSize` binops to by value
authorJorge Aparicio <japaricious@gmail.com>
Mon, 1 Dec 2014 20:09:03 +0000 (15:09 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Sun, 14 Dec 2014 01:15:39 +0000 (20:15 -0500)
src/libsyntax/ext/tt/transcribe.rs

index 99799fecb7882a03bc115ae12973a53b6c997b44..e2439bad178fe5c8257f7a86a5859b6f175a2363 100644 (file)
@@ -106,6 +106,8 @@ enum LockstepIterSize {
     LisContradiction(String),
 }
 
+// NOTE(stage0): Remove impl after a snapshot
+#[cfg(stage0)]
 impl Add<LockstepIterSize, LockstepIterSize> for LockstepIterSize {
     fn add(&self, other: &LockstepIterSize) -> LockstepIterSize {
         match *self {
@@ -127,6 +129,28 @@ fn add(&self, other: &LockstepIterSize) -> LockstepIterSize {
     }
 }
 
+#[cfg(not(stage0))]  // NOTE(stage0): Remove cfg after a snapshot
+impl Add<LockstepIterSize, LockstepIterSize> for LockstepIterSize {
+    fn add(self, other: LockstepIterSize) -> LockstepIterSize {
+        match self {
+            LisUnconstrained => other,
+            LisContradiction(_) => self,
+            LisConstraint(l_len, ref l_id) => match other {
+                LisUnconstrained => self.clone(),
+                LisContradiction(_) => other,
+                LisConstraint(r_len, _) if l_len == r_len => self.clone(),
+                LisConstraint(r_len, r_id) => {
+                    let l_n = token::get_ident(l_id.clone());
+                    let r_n = token::get_ident(r_id);
+                    LisContradiction(format!("inconsistent lockstep iteration: \
+                                              '{}' has {} items, but '{}' has {}",
+                                              l_n, l_len, r_n, r_len).to_string())
+                }
+            },
+        }
+    }
+}
+
 fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize {
     match *t {
         TtDelimited(_, ref delimed) => {