Skip to content

Commit 79c84dd

Browse files
committed
---
yaml --- r: 232319 b: refs/heads/try c: aed55dc h: refs/heads/master i: 232317: b6775ef 232315: 6cb2d68 232311: 7b056ec 232303: d90c8fc 232287: 2fc6291 232255: 6c34593 232191: 6e95bd3 v: v3
1 parent bc72946 commit 79c84dd

File tree

7 files changed

+249
-1
lines changed

7 files changed

+249
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 43f6c2fab76fc7cf92876a7de70579e5b781196d
4+
refs/heads/try: aed55dcd5719505d245158dcb1b245067b025306
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/libcore/slice.rs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use ptr;
5050
use mem;
5151
use mem::size_of;
5252
use marker::{Send, Sync, self};
53+
use num::wrapping::OverflowingOps;
5354
use raw::Repr;
5455
// Avoid conflicts with *both* the Slice trait (buggy) and the `slice::raw` module.
5556
use raw::Slice as RawSlice;
@@ -1180,6 +1181,34 @@ impl<'a, T> Iterator for Windows<'a, T> {
11801181
(size, Some(size))
11811182
}
11821183
}
1184+
1185+
#[inline]
1186+
fn count(self) -> usize {
1187+
self.size_hint().0
1188+
}
1189+
1190+
#[inline]
1191+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
1192+
let (end, overflow) = self.size.overflowing_add(n);
1193+
if end > self.v.len() || overflow {
1194+
self.v = &[];
1195+
None
1196+
} else {
1197+
let nth = &self.v[n..end];
1198+
self.v = &self.v[n+1..];
1199+
Some(nth)
1200+
}
1201+
}
1202+
1203+
#[inline]
1204+
fn last(self) -> Option<Self::Item> {
1205+
if self.size > self.v.len() {
1206+
None
1207+
} else {
1208+
let start = self.v.len() - self.size;
1209+
Some(&self.v[start..])
1210+
}
1211+
}
11831212
}
11841213

11851214
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1266,6 +1295,38 @@ impl<'a, T> Iterator for Chunks<'a, T> {
12661295
(n, Some(n))
12671296
}
12681297
}
1298+
1299+
#[inline]
1300+
fn count(self) -> usize {
1301+
self.size_hint().0
1302+
}
1303+
1304+
#[inline]
1305+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
1306+
let (start, overflow) = n.overflowing_mul(self.size);
1307+
if start >= self.v.len() || overflow {
1308+
self.v = &[];
1309+
None
1310+
} else {
1311+
let end = match start.checked_add(self.size) {
1312+
Some(sum) => cmp::min(self.v.len(), sum),
1313+
None => self.v.len(),
1314+
};
1315+
let nth = &self.v[start..end];
1316+
self.v = &self.v[end..];
1317+
Some(nth)
1318+
}
1319+
}
1320+
1321+
#[inline]
1322+
fn last(self) -> Option<Self::Item> {
1323+
if self.v.is_empty() {
1324+
None
1325+
} else {
1326+
let start = (self.v.len() - 1) / self.size * self.size;
1327+
Some(&self.v[start..])
1328+
}
1329+
}
12691330
}
12701331

12711332
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1346,6 +1407,40 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
13461407
(n, Some(n))
13471408
}
13481409
}
1410+
1411+
#[inline]
1412+
fn count(self) -> usize {
1413+
self.size_hint().0
1414+
}
1415+
1416+
#[inline]
1417+
fn nth(&mut self, n: usize) -> Option<&'a mut [T]> {
1418+
let (start, overflow) = n.overflowing_mul(self.chunk_size);
1419+
if start >= self.v.len() || overflow {
1420+
self.v = &mut [];
1421+
None
1422+
} else {
1423+
let end = match start.checked_add(self.chunk_size) {
1424+
Some(sum) => cmp::min(self.v.len(), sum),
1425+
None => self.v.len(),
1426+
};
1427+
let tmp = mem::replace(&mut self.v, &mut []);
1428+
let (head, tail) = tmp.split_at_mut(end);
1429+
let (_, nth) = head.split_at_mut(start);
1430+
self.v = tail;
1431+
Some(nth)
1432+
}
1433+
}
1434+
1435+
#[inline]
1436+
fn last(self) -> Option<Self::Item> {
1437+
if self.v.is_empty() {
1438+
None
1439+
} else {
1440+
let start = (self.v.len() - 1) / self.chunk_size * self.chunk_size;
1441+
Some(&mut self.v[start..])
1442+
}
1443+
}
13491444
}
13501445

13511446
#[stable(feature = "rust1", since = "1.0.0")]

branches/try/src/libcoretest/slice.rs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,123 @@ fn test_iterator_count() {
6464
iter2.next();
6565
assert_eq!(iter2.count(), 3);
6666
}
67+
68+
#[test]
69+
fn test_chunks_count() {
70+
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
71+
let c = v.chunks(3);
72+
assert_eq!(c.count(), 2);
73+
74+
let v2: &[i32] = &[0, 1, 2, 3, 4];
75+
let c2 = v2.chunks(2);
76+
assert_eq!(c2.count(), 3);
77+
78+
let v3: &[i32] = &[];
79+
let c3 = v3.chunks(2);
80+
assert_eq!(c3.count(), 0);
81+
}
82+
83+
#[test]
84+
fn test_chunks_nth() {
85+
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
86+
let mut c = v.chunks(2);
87+
assert_eq!(c.nth(1).unwrap()[1], 3);
88+
assert_eq!(c.next().unwrap()[0], 4);
89+
90+
let v2: &[i32] = &[0, 1, 2, 3, 4];
91+
let mut c2 = v2.chunks(3);
92+
assert_eq!(c2.nth(1).unwrap()[1], 4);
93+
assert_eq!(c2.next(), None);
94+
}
95+
96+
#[test]
97+
fn test_chunks_last() {
98+
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
99+
let c = v.chunks(2);
100+
assert_eq!(c.last().unwrap()[1], 5);
101+
102+
let v2: &[i32] = &[0, 1, 2, 3, 4];
103+
let c2 = v2.chunks(2);
104+
assert_eq!(c2.last().unwrap()[0], 4);
105+
}
106+
107+
#[test]
108+
fn test_chunks_mut_count() {
109+
let mut v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5];
110+
let c = v.chunks_mut(3);
111+
assert_eq!(c.count(), 2);
112+
113+
let mut v2: &mut [i32] = &mut [0, 1, 2, 3, 4];
114+
let c2 = v2.chunks_mut(2);
115+
assert_eq!(c2.count(), 3);
116+
117+
let mut v3: &mut [i32] = &mut [];
118+
let c3 = v3.chunks_mut(2);
119+
assert_eq!(c3.count(), 0);
120+
}
121+
122+
#[test]
123+
fn test_chunks_mut_nth() {
124+
let mut v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5];
125+
let mut c = v.chunks_mut(2);
126+
assert_eq!(c.nth(1).unwrap()[1], 3);
127+
assert_eq!(c.next().unwrap()[0], 4);
128+
129+
let mut v2: &mut [i32] = &mut [0, 1, 2, 3, 4];
130+
let mut c2 = v2.chunks_mut(3);
131+
assert_eq!(c2.nth(1).unwrap()[1], 4);
132+
assert_eq!(c2.next(), None);
133+
}
134+
135+
#[test]
136+
fn test_chunks_mut_last() {
137+
let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5];
138+
let c = v.chunks_mut(2);
139+
assert_eq!(c.last().unwrap()[1], 5);
140+
141+
let v2: &mut [i32] = &mut [0, 1, 2, 3, 4];
142+
let c2 = v2.chunks_mut(2);
143+
assert_eq!(c2.last().unwrap()[0], 4);
144+
}
145+
146+
147+
148+
149+
#[test]
150+
fn test_windows_count() {
151+
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
152+
let c = v.windows(3);
153+
assert_eq!(c.count(), 4);
154+
155+
let v2: &[i32] = &[0, 1, 2, 3, 4];
156+
let c2 = v2.windows(6);
157+
assert_eq!(c2.count(), 0);
158+
159+
let v3: &[i32] = &[];
160+
let c3 = v3.windows(2);
161+
assert_eq!(c3.count(), 0);
162+
}
163+
164+
#[test]
165+
fn test_windows_nth() {
166+
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
167+
let mut c = v.windows(2);
168+
assert_eq!(c.nth(2).unwrap()[1], 3);
169+
assert_eq!(c.next().unwrap()[0], 3);
170+
171+
let v2: &[i32] = &[0, 1, 2, 3, 4];
172+
let mut c2 = v2.windows(4);
173+
assert_eq!(c2.nth(1).unwrap()[1], 2);
174+
assert_eq!(c2.next(), None);
175+
}
176+
177+
#[test]
178+
fn test_windows_last() {
179+
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
180+
let c = v.windows(2);
181+
assert_eq!(c.last().unwrap()[1], 5);
182+
183+
let v2: &[i32] = &[0, 1, 2, 3, 4];
184+
let c2 = v2.windows(2);
185+
assert_eq!(c2.last().unwrap()[0], 3);
186+
}

branches/try/src/librustc_resolve/build_reduced_graph.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,11 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
785785
debug!("(building reduced graph for external \
786786
crate) building type {}", final_ident);
787787

788+
let modifiers = match new_parent.kind.get() {
789+
NormalModuleKind => modifiers,
790+
_ => modifiers & !DefModifiers::IMPORTABLE
791+
};
792+
788793
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
789794
}
790795
DefStruct(def_id) => {

branches/try/src/test/auxiliary/use_from_trait_xc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(associated_consts)]
12+
1113
pub use self::sub::{Bar, Baz};
1214

1315
pub trait Trait {
1416
fn foo(&self);
17+
type Assoc;
18+
const CONST: u32;
1519
}
1620

1721
struct Foo;
1822

1923
impl Foo {
2024
pub fn new() {}
25+
26+
pub const C: u32 = 0;
2127
}
2228

2329
mod sub {

branches/try/src/test/compile-fail/use-from-trait-xc.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@ extern crate use_from_trait_xc;
1515
use use_from_trait_xc::Trait::foo;
1616
//~^ ERROR `foo` is not directly importable
1717

18+
use use_from_trait_xc::Trait::Assoc;
19+
//~^ ERROR `Assoc` is not directly importable
20+
21+
use use_from_trait_xc::Trait::CONST;
22+
//~^ ERROR `CONST` is not directly importable
23+
1824
use use_from_trait_xc::Foo::new;
1925
//~^ ERROR `new` is not directly importable
2026

27+
use use_from_trait_xc::Foo::C;
28+
//~^ ERROR unresolved import `use_from_trait_xc::Foo::C`
29+
2130
use use_from_trait_xc::Bar::new as bnew;
2231
//~^ ERROR `bnew` is not directly importable
2332

branches/try/src/test/compile-fail/use-from-trait.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,32 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(associated_consts)]
12+
1113
use Trait::foo;
1214
//~^ ERROR `foo` is not directly importable
15+
use Trait::Assoc;
16+
//~^ ERROR `Assoc` is not directly importable
17+
use Trait::C;
18+
//~^ ERROR `C` is not directly importable
19+
1320
use Foo::new;
1421
//~^ ERROR unresolved import `Foo::new`. Not a module `Foo`
1522

23+
use Foo::C2;
24+
//~^ ERROR unresolved import `Foo::C2`. Not a module `Foo`
25+
1626
pub trait Trait {
1727
fn foo();
28+
type Assoc;
29+
const C: u32;
1830
}
1931

2032
struct Foo;
2133

2234
impl Foo {
2335
fn new() {}
36+
const C2: u32 = 0;
2437
}
2538

2639
fn main() {}

0 commit comments

Comments
 (0)