Skip to content

Commit c4fa2a3

Browse files
author
Jorge Aparicio
committed
libsyntax: convert LockstepIterSize binops to by value
1 parent 265b89a commit c4fa2a3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ enum LockstepIterSize {
106106
LisContradiction(String),
107107
}
108108

109+
// NOTE(stage0): Remove impl after a snapshot
110+
#[cfg(stage0)]
109111
impl Add<LockstepIterSize, LockstepIterSize> for LockstepIterSize {
110112
fn add(&self, other: &LockstepIterSize) -> LockstepIterSize {
111113
match *self {
@@ -127,6 +129,28 @@ impl Add<LockstepIterSize, LockstepIterSize> for LockstepIterSize {
127129
}
128130
}
129131

132+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
133+
impl Add<LockstepIterSize, LockstepIterSize> for LockstepIterSize {
134+
fn add(self, other: LockstepIterSize) -> LockstepIterSize {
135+
match self {
136+
LisUnconstrained => other,
137+
LisContradiction(_) => self,
138+
LisConstraint(l_len, ref l_id) => match other {
139+
LisUnconstrained => self.clone(),
140+
LisContradiction(_) => other,
141+
LisConstraint(r_len, _) if l_len == r_len => self.clone(),
142+
LisConstraint(r_len, r_id) => {
143+
let l_n = token::get_ident(l_id.clone());
144+
let r_n = token::get_ident(r_id);
145+
LisContradiction(format!("inconsistent lockstep iteration: \
146+
'{}' has {} items, but '{}' has {}",
147+
l_n, l_len, r_n, r_len).to_string())
148+
}
149+
},
150+
}
151+
}
152+
}
153+
130154
fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize {
131155
match *t {
132156
TtDelimited(_, ref delimed) => {

0 commit comments

Comments
 (0)