diff options
| author | bors <bors@rust-lang.org> | 2014-12-15 22:11:44 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-12-15 22:11:44 +0000 |
| commit | 0669a432a2e09ad08886cb2138dbe9f5d681fb7f (patch) | |
| tree | 5183544df317d80a6bce406242596dd997e61b64 /src/libsyntax/ext | |
| parent | 92e9e70d15bcf8d29890bf93793be402ad629229 (diff) | |
| parent | 89d2061c8f1cc2bcd5e9bb8a97e214f482d5ff2c (diff) | |
| download | rust-0669a432a2e09ad08886cb2138dbe9f5d681fb7f.tar.gz rust-0669a432a2e09ad08886cb2138dbe9f5d681fb7f.zip | |
auto merge of #19448 : japaric/rust/binops-by-value, r=nikomatsakis
- The following operator traits now take their arguments by value: `Add`, `Sub`, `Mul`, `Div`, `Rem`, `BitAnd`, `BitOr`, `BitXor`, `Shl`, `Shr`. This breaks all existing implementations of these traits. - The binary operation `a OP b` now "desugars" to `OpTrait::op_method(a, b)` and consumes both arguments. - `String` and `Vec` addition have been changed to reuse the LHS owned value, and to avoid internal cloning. Only the following asymmetric operations are available: `String + &str` and `Vec<T> + &[T]`, which are now a short-hand for the "append" operation. [breaking-change] --- This passes `make check` locally. I haven't touch the unary operators in this PR, but converting them to by value should be very similar to this PR. I can work on them after this gets the thumbs up. @nikomatsakis r? the compiler changes @aturon r? the library changes. I think the only controversial bit is the semantic change of the `Vec`/`String` `Add` implementation. cc #19148
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 99799fecb78..e2439bad178 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -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 @@ impl Add<LockstepIterSize, LockstepIterSize> for 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) => { |
