]> git.lizzy.rs Git - rust.git/commitdiff
Parse fully-qualified associated types in generics without whitespace
authorP1start <rewi-github@whanau.org>
Tue, 23 Dec 2014 00:13:49 +0000 (13:13 +1300)
committerP1start <rewi-github@whanau.org>
Thu, 25 Dec 2014 05:58:47 +0000 (18:58 +1300)
This breaks code that looks like this:

    let x = foo as bar << 13;

Change such code to look like this:

    let x = (foo as bar) << 13;

Closes #17362.

[breaking-change]

src/libcollections/bit.rs
src/libcore/hash/sip.rs
src/librand/lib.rs
src/libstd/io/net/ip.rs
src/libstd/sys/common/net.rs
src/libsyntax/parse/parser.rs
src/libtime/lib.rs
src/libunicode/u_str.rs
src/test/bench/shootout-reverse-complement.rs
src/test/run-pass/parse-assoc-type-lt.rs [new file with mode: 0644]

index 430d7210bf69b105be1a6ef4032974562548213b..c3e9d91b7edc6cf908306be683de676ceafc5d0d 100644 (file)
@@ -314,17 +314,17 @@ pub fn from_bytes(bytes: &[u8]) -> Bitv {
 
         for i in range(0, complete_words) {
             bitv.storage.push(
-                (reverse_bits(bytes[i * 4 + 0]) as u32 << 0) |
-                (reverse_bits(bytes[i * 4 + 1]) as u32 << 8) |
-                (reverse_bits(bytes[i * 4 + 2]) as u32 << 16) |
-                (reverse_bits(bytes[i * 4 + 3]) as u32 << 24)
+                ((reverse_bits(bytes[i * 4 + 0]) as u32) << 0) |
+                ((reverse_bits(bytes[i * 4 + 1]) as u32) << 8) |
+                ((reverse_bits(bytes[i * 4 + 2]) as u32) << 16) |
+                ((reverse_bits(bytes[i * 4 + 3]) as u32) << 24)
             );
         }
 
         if extra_bytes > 0 {
             let mut last_word = 0u32;
             for (i, &byte) in bytes[complete_words*4..].iter().enumerate() {
-                last_word |= reverse_bits(byte) as u32 << (i * 8);
+                last_word |= (reverse_bits(byte) as u32) << (i * 8);
             }
             bitv.storage.push(last_word);
         }
@@ -645,7 +645,7 @@ fn bit(bitv: &Bitv, byte: uint, bit: uint) -> u8 {
             if offset >= bitv.nbits {
                 0
             } else {
-                bitv[offset] as u8 << (7 - bit)
+                (bitv[offset] as u8) << (7 - bit)
             }
         }
 
index ab6b0986c686df72b92a04b0aa93a2faa7d06cf6..2501037107a22e6b95cae5095772ee3713b792b0 100644 (file)
@@ -50,19 +50,19 @@ pub struct SipState {
 macro_rules! u8to64_le {
     ($buf:expr, $i:expr) =>
     ($buf[0+$i] as u64 |
-     $buf[1+$i] as u64 << 8 |
-     $buf[2+$i] as u64 << 16 |
-     $buf[3+$i] as u64 << 24 |
-     $buf[4+$i] as u64 << 32 |
-     $buf[5+$i] as u64 << 40 |
-     $buf[6+$i] as u64 << 48 |
-     $buf[7+$i] as u64 << 56);
+     ($buf[1+$i] as u64) << 8 |
+     ($buf[2+$i] as u64) << 16 |
+     ($buf[3+$i] as u64) << 24 |
+     ($buf[4+$i] as u64) << 32 |
+     ($buf[5+$i] as u64) << 40 |
+     ($buf[6+$i] as u64) << 48 |
+     ($buf[7+$i] as u64) << 56);
     ($buf:expr, $i:expr, $len:expr) =>
     ({
         let mut t = 0;
         let mut out = 0u64;
         while t < $len {
-            out |= $buf[t+$i] as u64 << t*8;
+            out |= ($buf[t+$i] as u64) << t*8;
             t += 1;
         }
         out
index 514ff81da518ec789c5614c169b197aa7a9887b0..0faf43fc2ef641552af1e65538df93d6908175e5 100644 (file)
@@ -74,7 +74,7 @@ pub trait Rng {
     /// these two methods. Similarly to `next_u32`, this rarely needs
     /// to be called directly, prefer `r.gen()` to `r.next_u64()`.
     fn next_u64(&mut self) -> u64 {
-        (self.next_u32() as u64 << 32) | (self.next_u32() as u64)
+        ((self.next_u32() as u64) << 32) | (self.next_u32() as u64)
     }
 
     /// Return the next random f32 selected from the half-open
index add986387daf7db4df672497d38e8f25a05999e4..83be9574f78b60e62c8fb6be9cd8320d5d7db824 100644 (file)
@@ -267,8 +267,8 @@ fn read_groups(p: &mut Parser, groups: &mut [u16, ..8], limit: uint) -> (uint, b
                     });
                     match ipv4 {
                         Some(Ipv4Addr(a, b, c, d)) => {
-                            groups[i + 0] = (a as u16 << 8) | (b as u16);
-                            groups[i + 1] = (c as u16 << 8) | (d as u16);
+                            groups[i + 0] = ((a as u16) << 8) | (b as u16);
+                            groups[i + 1] = ((c as u16) << 8) | (d as u16);
                             return (i + 2, true);
                         }
                         _ => {}
index 382f6875b281d01c3c788659978862f17608a381..1e8246dabc5e4e08dd072d7243813fb15149423c 100644 (file)
@@ -55,10 +55,10 @@ pub enum InAddr {
 pub fn ip_to_inaddr(ip: IpAddr) -> InAddr {
     match ip {
         Ipv4Addr(a, b, c, d) => {
-            let ip = (a as u32 << 24) |
-                     (b as u32 << 16) |
-                     (c as u32 <<  8) |
-                     (d as u32 <<  0);
+            let ip = ((a as u32) << 24) |
+                     ((b as u32) << 16) |
+                     ((c as u32) <<  8) |
+                     ((d as u32) <<  0);
             In4Addr(libc::in_addr {
                 s_addr: Int::from_be(ip)
             })
index 94b61ba56d2e5b938d3012f8f6991ae2a8c4dbf6..b3dc8c3a61a10bd876d8f92f1595e33ec5e87fc8 100644 (file)
@@ -669,45 +669,22 @@ pub fn expect_no_suffix(&mut self, sp: Span, kind: &str, suffix: Option<ast::Nam
     /// `<` and continue. If a `<` is not seen, return false.
     ///
     /// This is meant to be used when parsing generics on a path to get the
-    /// starting token. The `force` parameter is used to forcefully break up a
-    /// `<<` token. If `force` is false, then `<<` is only broken when a lifetime
-    /// shows up next. For example, consider the expression:
-    ///
-    ///      foo as bar << test
-    ///
-    /// The parser needs to know if `bar <<` is the start of a generic path or if
-    /// it's a left-shift token. If `test` were a lifetime, then it's impossible
-    /// for the token to be a left-shift, but if it's not a lifetime, then it's
-    /// considered a left-shift.
-    ///
-    /// The reason for this is that the only current ambiguity with `<<` is when
-    /// parsing closure types:
-    ///
-    ///      foo::<<'a> ||>();
-    ///      impl Foo<<'a> ||>() { ... }
-    fn eat_lt(&mut self, force: bool) -> bool {
+    /// starting token.
+    fn eat_lt(&mut self) -> bool {
         match self.token {
             token::Lt => { self.bump(); true }
             token::BinOp(token::Shl) => {
-                let next_lifetime = self.look_ahead(1, |t| match *t {
-                    token::Lifetime(..) => true,
-                    _ => false,
-                });
-                if force || next_lifetime {
-                    let span = self.span;
-                    let lo = span.lo + BytePos(1);
-                    self.replace_token(token::Lt, lo, span.hi);
-                    true
-                } else {
-                    false
-                }
+                let span = self.span;
+                let lo = span.lo + BytePos(1);
+                self.replace_token(token::Lt, lo, span.hi);
+                true
             }
             _ => false,
         }
     }
 
     fn expect_lt(&mut self) {
-        if !self.eat_lt(true) {
+        if !self.eat_lt() {
             let found_token = self.this_token_to_string();
             let token_str = Parser::token_to_string(&token::Lt);
             self.fatal(format!("expected `{}`, found `{}`",
@@ -1582,9 +1559,8 @@ pub fn parse_ty(&mut self) -> P<Ty> {
             TyTypeof(e)
         } else if self.eat_keyword(keywords::Proc) {
             self.parse_proc_type(Vec::new())
-        } else if self.check(&token::Lt) {
+        } else if self.eat_lt() {
             // QUALIFIED PATH `<TYPE as TRAIT_REF>::item`
-            self.bump();
             let self_type = self.parse_ty_sum();
             self.expect_keyword(keywords::As);
             let trait_ref = self.parse_trait_ref();
@@ -1870,7 +1846,7 @@ pub fn parse_path_segments_without_colons(&mut self) -> Vec<ast::PathSegment> {
             let identifier = self.parse_ident();
 
             // Parse types, optionally.
-            let parameters = if self.eat_lt(false) {
+            let parameters = if self.eat_lt() {
                 let (lifetimes, types, bindings) = self.parse_generic_values_after_lt();
 
                 ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
@@ -1931,7 +1907,7 @@ pub fn parse_path_segments_with_colons(&mut self) -> Vec<ast::PathSegment> {
             }
 
             // Check for a type segment.
-            if self.eat_lt(false) {
+            if self.eat_lt() {
                 // Consumed `a::b::<`, go look for types
                 let (lifetimes, types, bindings) = self.parse_generic_values_after_lt();
                 segments.push(ast::PathSegment {
index e58a0229d69623fd1bce2f55e8720c437a0d2e18..ec41904fd19c08a5352d55eab580410ef55fd8ff 100644 (file)
@@ -149,8 +149,8 @@ unsafe fn os_get_time() -> (i64, i32) {
         // A FILETIME contains a 64-bit value representing the number of
         // hectonanosecond (100-nanosecond) intervals since 1601-01-01T00:00:00Z.
         // http://support.microsoft.com/kb/167296/en-us
-        let ns_since_1601 = ((time.dwHighDateTime as u64 << 32) |
-                             (time.dwLowDateTime  as u64 <<  0)) / 10;
+        let ns_since_1601 = (((time.dwHighDateTime as u64) << 32) |
+                             ((time.dwLowDateTime  as u64) <<  0)) / 10;
         let ns_since_1970 = ns_since_1601 - NANOSECONDS_FROM_1601_TO_1970;
 
         ((ns_since_1970 / 1000000) as i64,
index a3d4dd057d0024780eb74780e6f8a9ef417b910d..9a09c13c1ab20c0a76f692c109eb8a37cba849f3 100644 (file)
@@ -459,7 +459,7 @@ fn next(&mut self) -> Option<Utf16Item> {
             }
 
             // all ok, so lets decode it.
-            let c = ((u - 0xD800) as u32 << 10 | (u2 - 0xDC00) as u32) + 0x1_0000;
+            let c = (((u - 0xD800) as u32) << 10 | (u2 - 0xDC00) as u32) + 0x1_0000;
             Some(Utf16Item::ScalarValue(unsafe {mem::transmute(c)}))
         }
     }
index d746ec1dbabd555ca940a4765dbb7def04526db0..e0939dcb43b8d03e6758ab60f772cb0645aa79ef 100644 (file)
@@ -62,7 +62,7 @@ fn new() -> Tables {
         }
         let mut table16 = [0;1 << 16];
         for (i, v) in table16.iter_mut().enumerate() {
-            *v = table8[i & 255] as u16 << 8 |
+            *v = (table8[i & 255] as u16) << 8 |
                  table8[i >> 8]  as u16;
         }
         Tables { table8: table8, table16: table16 }
diff --git a/src/test/run-pass/parse-assoc-type-lt.rs b/src/test/run-pass/parse-assoc-type-lt.rs
new file mode 100644 (file)
index 0000000..8a68711
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(associated_types)]
+
+trait Foo {
+    type T;
+    fn foo() -> Box<<Self as Foo>::T>;
+}
+
+fn main() {}