Skip to content

Commit 9c3e608

Browse files
committed
auto merge of #20154 : P1start/rust/qualified-assoc-type-generics, r=nikomatsakis
This modifies `Parser::eat_lt` to always split up `<<`s, instead of doing so only when a lifetime name followed or the `force` parameter (now removed) was `true`. This is because `Foo<<TYPE` is now a valid start to a type, whereas previously only `Foo<<LIFETIME` was valid. This is a [breaking-change]. Change code that looks like this: ```rust let x = foo as bar << 13; ``` to use parentheses, like this: ```rust let x = (foo as bar) << 13; ``` Closes #17362.
2 parents a6b1097 + d9769ec commit 9c3e608

File tree

10 files changed

+53
-59
lines changed

10 files changed

+53
-59
lines changed

src/libcollections/bit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,17 @@ impl Bitv {
319319

320320
for i in range(0, complete_words) {
321321
bitv.storage.push(
322-
(reverse_bits(bytes[i * 4 + 0]) as u32 << 0) |
323-
(reverse_bits(bytes[i * 4 + 1]) as u32 << 8) |
324-
(reverse_bits(bytes[i * 4 + 2]) as u32 << 16) |
325-
(reverse_bits(bytes[i * 4 + 3]) as u32 << 24)
322+
((reverse_bits(bytes[i * 4 + 0]) as u32) << 0) |
323+
((reverse_bits(bytes[i * 4 + 1]) as u32) << 8) |
324+
((reverse_bits(bytes[i * 4 + 2]) as u32) << 16) |
325+
((reverse_bits(bytes[i * 4 + 3]) as u32) << 24)
326326
);
327327
}
328328

329329
if extra_bytes > 0 {
330330
let mut last_word = 0u32;
331331
for (i, &byte) in bytes[complete_words*4..].iter().enumerate() {
332-
last_word |= reverse_bits(byte) as u32 << (i * 8);
332+
last_word |= (reverse_bits(byte) as u32) << (i * 8);
333333
}
334334
bitv.storage.push(last_word);
335335
}
@@ -650,7 +650,7 @@ impl Bitv {
650650
if offset >= bitv.nbits {
651651
0
652652
} else {
653-
bitv[offset] as u8 << (7 - bit)
653+
(bitv[offset] as u8) << (7 - bit)
654654
}
655655
}
656656

src/libcore/hash/sip.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ pub struct SipState {
5050
macro_rules! u8to64_le {
5151
($buf:expr, $i:expr) =>
5252
($buf[0+$i] as u64 |
53-
$buf[1+$i] as u64 << 8 |
54-
$buf[2+$i] as u64 << 16 |
55-
$buf[3+$i] as u64 << 24 |
56-
$buf[4+$i] as u64 << 32 |
57-
$buf[5+$i] as u64 << 40 |
58-
$buf[6+$i] as u64 << 48 |
59-
$buf[7+$i] as u64 << 56);
53+
($buf[1+$i] as u64) << 8 |
54+
($buf[2+$i] as u64) << 16 |
55+
($buf[3+$i] as u64) << 24 |
56+
($buf[4+$i] as u64) << 32 |
57+
($buf[5+$i] as u64) << 40 |
58+
($buf[6+$i] as u64) << 48 |
59+
($buf[7+$i] as u64) << 56);
6060
($buf:expr, $i:expr, $len:expr) =>
6161
({
6262
let mut t = 0;
6363
let mut out = 0u64;
6464
while t < $len {
65-
out |= $buf[t+$i] as u64 << t*8;
65+
out |= ($buf[t+$i] as u64) << t*8;
6666
t += 1;
6767
}
6868
out

src/librand/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub trait Rng : Sized {
7474
/// these two methods. Similarly to `next_u32`, this rarely needs
7575
/// to be called directly, prefer `r.gen()` to `r.next_u64()`.
7676
fn next_u64(&mut self) -> u64 {
77-
(self.next_u32() as u64 << 32) | (self.next_u32() as u64)
77+
((self.next_u32() as u64) << 32) | (self.next_u32() as u64)
7878
}
7979

8080
/// Return the next random f32 selected from the half-open

src/libstd/io/net/ip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ impl<'a> Parser<'a> {
267267
});
268268
match ipv4 {
269269
Some(Ipv4Addr(a, b, c, d)) => {
270-
groups[i + 0] = (a as u16 << 8) | (b as u16);
271-
groups[i + 1] = (c as u16 << 8) | (d as u16);
270+
groups[i + 0] = ((a as u16) << 8) | (b as u16);
271+
groups[i + 1] = ((c as u16) << 8) | (d as u16);
272272
return (i + 2, true);
273273
}
274274
_ => {}

src/libstd/sys/common/net.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ pub enum InAddr {
5656
pub fn ip_to_inaddr(ip: IpAddr) -> InAddr {
5757
match ip {
5858
Ipv4Addr(a, b, c, d) => {
59-
let ip = (a as u32 << 24) |
60-
(b as u32 << 16) |
61-
(c as u32 << 8) |
62-
(d as u32 << 0);
59+
let ip = ((a as u32) << 24) |
60+
((b as u32) << 16) |
61+
((c as u32) << 8) |
62+
((d as u32) << 0);
6363
In4Addr(libc::in_addr {
6464
s_addr: Int::from_be(ip)
6565
})

src/libsyntax/parse/parser.rs

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -681,45 +681,22 @@ impl<'a> Parser<'a> {
681681
/// `<` and continue. If a `<` is not seen, return false.
682682
///
683683
/// This is meant to be used when parsing generics on a path to get the
684-
/// starting token. The `force` parameter is used to forcefully break up a
685-
/// `<<` token. If `force` is false, then `<<` is only broken when a lifetime
686-
/// shows up next. For example, consider the expression:
687-
///
688-
/// foo as bar << test
689-
///
690-
/// The parser needs to know if `bar <<` is the start of a generic path or if
691-
/// it's a left-shift token. If `test` were a lifetime, then it's impossible
692-
/// for the token to be a left-shift, but if it's not a lifetime, then it's
693-
/// considered a left-shift.
694-
///
695-
/// The reason for this is that the only current ambiguity with `<<` is when
696-
/// parsing closure types:
697-
///
698-
/// foo::<<'a> ||>();
699-
/// impl Foo<<'a> ||>() { ... }
700-
fn eat_lt(&mut self, force: bool) -> bool {
684+
/// starting token.
685+
fn eat_lt(&mut self) -> bool {
701686
match self.token {
702687
token::Lt => { self.bump(); true }
703688
token::BinOp(token::Shl) => {
704-
let next_lifetime = self.look_ahead(1, |t| match *t {
705-
token::Lifetime(..) => true,
706-
_ => false,
707-
});
708-
if force || next_lifetime {
709-
let span = self.span;
710-
let lo = span.lo + BytePos(1);
711-
self.replace_token(token::Lt, lo, span.hi);
712-
true
713-
} else {
714-
false
715-
}
689+
let span = self.span;
690+
let lo = span.lo + BytePos(1);
691+
self.replace_token(token::Lt, lo, span.hi);
692+
true
716693
}
717694
_ => false,
718695
}
719696
}
720697

721698
fn expect_lt(&mut self) {
722-
if !self.eat_lt(true) {
699+
if !self.eat_lt() {
723700
let found_token = self.this_token_to_string();
724701
let token_str = Parser::token_to_string(&token::Lt);
725702
self.fatal(format!("expected `{}`, found `{}`",
@@ -1594,9 +1571,8 @@ impl<'a> Parser<'a> {
15941571
TyTypeof(e)
15951572
} else if self.eat_keyword(keywords::Proc) {
15961573
self.parse_proc_type(Vec::new())
1597-
} else if self.check(&token::Lt) {
1574+
} else if self.eat_lt() {
15981575
// QUALIFIED PATH `<TYPE as TRAIT_REF>::item`
1599-
self.bump();
16001576
let self_type = self.parse_ty_sum();
16011577
self.expect_keyword(keywords::As);
16021578
let trait_ref = self.parse_trait_ref();
@@ -1877,7 +1853,7 @@ impl<'a> Parser<'a> {
18771853
let identifier = self.parse_ident();
18781854

18791855
// Parse types, optionally.
1880-
let parameters = if self.eat_lt(false) {
1856+
let parameters = if self.eat_lt() {
18811857
let (lifetimes, types, bindings) = self.parse_generic_values_after_lt();
18821858

18831859
ast::AngleBracketedParameters(ast::AngleBracketedParameterData {
@@ -1938,7 +1914,7 @@ impl<'a> Parser<'a> {
19381914
}
19391915

19401916
// Check for a type segment.
1941-
if self.eat_lt(false) {
1917+
if self.eat_lt() {
19421918
// Consumed `a::b::<`, go look for types
19431919
let (lifetimes, types, bindings) = self.parse_generic_values_after_lt();
19441920
segments.push(ast::PathSegment {

src/libtime/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ pub fn get_time() -> Timespec {
149149
// A FILETIME contains a 64-bit value representing the number of
150150
// hectonanosecond (100-nanosecond) intervals since 1601-01-01T00:00:00Z.
151151
// http://support.microsoft.com/kb/167296/en-us
152-
let ns_since_1601 = ((time.dwHighDateTime as u64 << 32) |
153-
(time.dwLowDateTime as u64 << 0)) / 10;
152+
let ns_since_1601 = (((time.dwHighDateTime as u64) << 32) |
153+
((time.dwLowDateTime as u64) << 0)) / 10;
154154
let ns_since_1970 = ns_since_1601 - NANOSECONDS_FROM_1601_TO_1970;
155155

156156
((ns_since_1970 / 1000000) as i64,

src/libunicode/u_str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl<'a> Iterator<Utf16Item> for Utf16Items<'a> {
458458
}
459459

460460
// all ok, so lets decode it.
461-
let c = ((u - 0xD800) as u32 << 10 | (u2 - 0xDC00) as u32) + 0x1_0000;
461+
let c = (((u - 0xD800) as u32) << 10 | (u2 - 0xDC00) as u32) + 0x1_0000;
462462
Some(Utf16Item::ScalarValue(unsafe {mem::transmute(c)}))
463463
}
464464
}

src/test/bench/shootout-reverse-complement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl Tables {
6363
}
6464
let mut table16 = [0;1 << 16];
6565
for (i, v) in table16.iter_mut().enumerate() {
66-
*v = table8[i & 255] as u16 << 8 |
66+
*v = (table8[i & 255] as u16) << 8 |
6767
table8[i >> 8] as u16;
6868
}
6969
Tables { table8: table8, table16: table16 }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(associated_types)]
12+
13+
trait Foo {
14+
type T;
15+
fn foo() -> Box<<Self as Foo>::T>;
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)