Skip to content

Commit dd30121

Browse files
committed
fix compile/docs errors
1 parent 0c07435 commit dd30121

File tree

14 files changed

+70
-68
lines changed

14 files changed

+70
-68
lines changed

src/liballoc/btree/map.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -782,13 +782,13 @@ impl<K: Ord, V> BTreeMap<K, V> {
782782
/// map.insert(3, "a");
783783
/// map.insert(5, "b");
784784
/// map.insert(8, "c");
785-
/// for (&key, &value) in map.range((Included(&4), Included(&8))) {
785+
/// for (&key, &value) in map.range((Included(4), Included(8))) {
786786
/// println!("{}: {}", key, value);
787787
/// }
788788
/// assert_eq!(Some((&5, &"b")), map.range(4..).next());
789789
/// ```
790790
#[stable(feature = "btree_range", since = "1.17.0")]
791-
pub fn range<T: ?Sized, R>(&self, range: R) -> Range<K, V>
791+
pub fn range<T, R>(&self, range: R) -> Range<K, V>
792792
where T: Ord, K: Borrow<T>, R: Into<RangeBounds<T>>
793793
{
794794
let root1 = self.root.as_ref();
@@ -828,7 +828,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
828828
/// }
829829
/// ```
830830
#[stable(feature = "btree_range", since = "1.17.0")]
831-
pub fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<K, V>
831+
pub fn range_mut<T, R>(&mut self, range: R) -> RangeMut<K, V>
832832
where T: Ord, K: Borrow<T>, R: Into<RangeBounds<T>>
833833
{
834834
let root1 = self.root.as_mut();
@@ -1779,21 +1779,21 @@ fn last_leaf_edge<BorrowType, K, V>
17791779
}
17801780
}
17811781

1782-
fn range_search<BorrowType, K, V, Q: ?Sized>(
1782+
fn range_search<BorrowType, K, V, Q>(
17831783
root1: NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
17841784
root2: NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
1785-
range: RangeBounds<&Q>
1785+
range: RangeBounds<Q>
17861786
)-> (Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>,
17871787
Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>)
17881788
where Q: Ord, K: Borrow<Q>
17891789
{
1790-
match (range.start, range.end) {
1791-
(Excluded(s), Excluded(e)) if s==e =>
1790+
match (&range.start, &range.end) {
1791+
(&Excluded(ref s), &Excluded(ref e)) if *s == *e =>
17921792
panic!("range start and end are equal and excluded in BTreeMap"),
1793-
(Included(s), Included(e)) |
1794-
(Included(s), Excluded(e)) |
1795-
(Excluded(s), Included(e)) |
1796-
(Excluded(s), Excluded(e)) if s>e =>
1793+
(&Included(ref s), &Included(ref e)) |
1794+
(&Included(ref s), &Excluded(ref e)) |
1795+
(&Excluded(ref s), &Included(ref e)) |
1796+
(&Excluded(ref s), &Excluded(ref e)) if *s > *e =>
17971797
panic!("range start is greater than range end in BTreeMap"),
17981798
_ => {},
17991799
};
@@ -1805,32 +1805,32 @@ fn range_search<BorrowType, K, V, Q: ?Sized>(
18051805
let mut diverged = false;
18061806

18071807
loop {
1808-
let min_edge = match (min_found, range.start()) {
1809-
(false, Included(key)) => match search::search_linear(&min_node, key) {
1808+
let min_edge = match (min_found, &range.start) {
1809+
(false, &Included(ref key)) => match search::search_linear(&min_node, key) {
18101810
(i, true) => { min_found = true; i },
18111811
(i, false) => i,
18121812
},
1813-
(false, Excluded(key)) => match search::search_linear(&min_node, key) {
1813+
(false, &Excluded(ref key)) => match search::search_linear(&min_node, &key) {
18141814
(i, true) => { min_found = true; i+1 },
18151815
(i, false) => i,
18161816
},
1817-
(_, Unbounded) => 0,
1818-
(true, Included(_)) => min_node.keys().len(),
1819-
(true, Excluded(_)) => 0,
1817+
(_, &Unbounded) => 0,
1818+
(true, &Included(_)) => min_node.keys().len(),
1819+
(true, &Excluded(_)) => 0,
18201820
};
18211821

1822-
let max_edge = match (max_found, range.end()) {
1823-
(false, Included(key)) => match search::search_linear(&max_node, key) {
1822+
let max_edge = match (max_found, &range.end) {
1823+
(false, &Included(ref key)) => match search::search_linear(&max_node, key) {
18241824
(i, true) => { max_found = true; i+1 },
18251825
(i, false) => i,
18261826
},
1827-
(false, Excluded(key)) => match search::search_linear(&max_node, key) {
1827+
(false, &Excluded(ref key)) => match search::search_linear(&max_node, key) {
18281828
(i, true) => { max_found = true; i },
18291829
(i, false) => i,
18301830
},
1831-
(_, Unbounded) => max_node.keys().len(),
1832-
(true, Included(_)) => 0,
1833-
(true, Excluded(_)) => max_node.keys().len(),
1831+
(_, &Unbounded) => max_node.keys().len(),
1832+
(true, &Included(_)) => 0,
1833+
(true, &Excluded(_)) => max_node.keys().len(),
18341834
};
18351835

18361836
if !diverged {

src/liballoc/btree/set.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,13 @@ impl<T: Ord> BTreeSet<T> {
281281
/// set.insert(3);
282282
/// set.insert(5);
283283
/// set.insert(8);
284-
/// for &elem in set.range((Included(&4), Included(&8))) {
284+
/// for &elem in set.range((Included(4), Included(8))) {
285285
/// println!("{}", elem);
286286
/// }
287287
/// assert_eq!(Some(&5), set.range(4..).next());
288288
/// ```
289289
#[stable(feature = "btree_range", since = "1.17.0")]
290-
pub fn range<K: ?Sized, R>(&self, range: R) -> Range<T>
290+
pub fn range<K, R>(&self, range: R) -> Range<T>
291291
where K: Ord, T: Borrow<K>, R: Into<RangeBounds<K>>
292292
{
293293
Range { iter: self.map.range(range.into()) }

src/liballoc/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
#![feature(pattern)]
107107
#![feature(placement_in_syntax)]
108108
#![feature(placement_new_protocol)]
109+
#![feature(range_argument)]
109110
#![feature(rustc_attrs)]
110111
#![feature(shared)]
111112
#![feature(slice_get_slice)]
@@ -204,10 +205,9 @@ trait SpecExtend<I: IntoIterator> {
204205
}
205206

206207
#[rustc_deprecated(reason = "moved to core::ops", since = "1.22.0")]
208+
#[unstable(feature = "range_argument", issue = "30877")]
207209
pub use core::ops::Bound;
208210

209-
pub use oom::oom;
210-
211211
#[doc(no_inline)]
212212
pub use binary_heap::BinaryHeap;
213213
#[doc(no_inline)]

src/liballoc/string.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,7 @@ impl String {
13751375
// Because the range removal happens in Drop, if the Drain iterator is leaked,
13761376
// the removal will not happen.
13771377
let len = self.len();
1378+
let range = range.into();
13781379
let start = match range.start {
13791380
Included(n) => n,
13801381
Excluded(n) => n + 1,
@@ -1429,25 +1430,24 @@ impl String {
14291430
/// assert_eq!(s, "Α is capital alpha; β is beta");
14301431
/// ```
14311432
#[unstable(feature = "splice", reason = "recently added", issue = "32310")]
1432-
pub fn splice<'a, 'b, R>(&'a mut self, range: R, replace_with: &'b str) -> Splice<'a, 'b>
1433+
pub fn splice<'a, 'b, R>(&'a mut self, range: R, replace_with: &'b str)
14331434
where R: Into<RangeBounds<usize>>
14341435
{
14351436
// Memory safety
14361437
//
14371438
// The String version of Splice does not have the memory safety issues
14381439
// of the vector version. The data is just plain bytes.
1439-
// Because the range removal happens in Drop, if the Splice iterator is leaked,
1440-
// the removal will not happen.
1441-
let len = self.len();
1442-
let start = match range.start {
1443-
Included(n) => n,
1444-
Excluded(n) => n + 1,
1445-
Unbounded => 0,
1440+
1441+
let range = range.into();
1442+
match range.start {
1443+
Included(n) => assert!(self.is_char_boundary(n)),
1444+
Excluded(n) => assert!(self.is_char_boundary(n + 1)),
1445+
Unbounded => {},
14461446
};
1447-
let end = match range.end {
1448-
Included(n) => n + 1,
1449-
Excluded(n) => n,
1450-
Unbounded => len,
1447+
match range.end {
1448+
Included(n) => assert!(self.is_char_boundary(n + 1)),
1449+
Excluded(n) => assert!(self.is_char_boundary(n)),
1450+
Unbounded => {},
14511451
};
14521452

14531453
unsafe {

src/liballoc/tests/btree/map.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// except according to those terms.
1010

1111
use std::collections::BTreeMap;
12-
use std::collections::Bound::{self, Excluded, Included, Unbounded};
1312
use std::collections::btree_map::Entry::{Occupied, Vacant};
13+
use std::ops::Bound::{self, Excluded, Included, Unbounded};
1414
use std::rc::Rc;
1515

1616
use std::iter::FromIterator;
@@ -262,7 +262,7 @@ fn test_range_1000() {
262262
let size = 1000;
263263
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
264264

265-
fn test(map: &BTreeMap<u32, u32>, size: u32, min: Bound<&u32>, max: Bound<&u32>) {
265+
fn test(map: &BTreeMap<u32, u32>, size: u32, min: Bound<u32>, max: Bound<u32>) {
266266
let mut kvs = map.range((min, max)).map(|(&k, &v)| (k, v));
267267
let mut pairs = (0..size).map(|i| (i, i));
268268

@@ -272,11 +272,11 @@ fn test_range_1000() {
272272
assert_eq!(kvs.next(), None);
273273
assert_eq!(pairs.next(), None);
274274
}
275-
test(&map, size, Included(&0), Excluded(&size));
276-
test(&map, size, Unbounded, Excluded(&size));
277-
test(&map, size, Included(&0), Included(&(size - 1)));
278-
test(&map, size, Unbounded, Included(&(size - 1)));
279-
test(&map, size, Included(&0), Unbounded);
275+
test(&map, size, Included(0), Excluded(size));
276+
test(&map, size, Unbounded, Excluded(size));
277+
test(&map, size, Included(0), Included(size - 1));
278+
test(&map, size, Unbounded, Included(size - 1));
279+
test(&map, size, Included(0), Unbounded);
280280
test(&map, size, Unbounded, Unbounded);
281281
}
282282

@@ -288,7 +288,7 @@ fn test_range_borrowed_key() {
288288
map.insert("coyote".to_string(), 3);
289289
map.insert("dingo".to_string(), 4);
290290
// NOTE: would like to use simply "b".."d" here...
291-
let mut iter = map.range::<str, _>((Included("b"),Excluded("d")));
291+
let mut iter = map.range::<String, _>((Included("b".to_string()),Excluded("d".to_string())));
292292
assert_eq!(iter.next(), Some((&"baboon".to_string(), &2)));
293293
assert_eq!(iter.next(), Some((&"coyote".to_string(), &3)));
294294
assert_eq!(iter.next(), None);
@@ -301,7 +301,7 @@ fn test_range() {
301301

302302
for i in 0..size {
303303
for j in i..size {
304-
let mut kvs = map.range((Included(&i), Included(&j))).map(|(&k, &v)| (k, v));
304+
let mut kvs = map.range((Included(i), Included(j))).map(|(&k, &v)| (k, v));
305305
let mut pairs = (i..j + 1).map(|i| (i, i));
306306

307307
for (kv, pair) in kvs.by_ref().zip(pairs.by_ref()) {
@@ -320,7 +320,7 @@ fn test_range_mut() {
320320

321321
for i in 0..size {
322322
for j in i..size {
323-
let mut kvs = map.range_mut((Included(&i), Included(&j))).map(|(&k, &mut v)| (k, v));
323+
let mut kvs = map.range_mut((Included(i), Included(j))).map(|(&k, &mut v)| (k, v));
324324
let mut pairs = (i..j + 1).map(|i| (i, i));
325325

326326
for (kv, pair) in kvs.by_ref().zip(pairs.by_ref()) {

src/liballoc/vec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ impl<T> Vec<T> {
11011101
// the hole, and the vector length is restored to the new length.
11021102
//
11031103
let len = self.len();
1104+
let range = range.into();
11041105
let start = match range.start {
11051106
Included(n) => n,
11061107
Excluded(n) => n + 1,

src/liballoc/vec_deque.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ impl<T> VecDeque<T> {
856856
// and the head/tail values will be restored correctly.
857857
//
858858
let len = self.len();
859+
let range = range.into();
859860
let start = match range.start {
860861
Included(n) => n,
861862
Excluded(n) => n + 1,

src/libcollections/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#![deny(warnings)]
2525

2626
#![feature(alloc)]
27-
#![feature(collections_range)]
2827
#![feature(macro_reexport)]
2928
#![feature(staged_api)]
3029

@@ -33,13 +32,12 @@
3332
//! See [`std::collections`](../std/collections/index.html) for a detailed
3433
//! discussion of collections in Rust.
3534
36-
extern crate core;
37-
3835
#[macro_reexport(vec, format)]
3936
extern crate alloc;
4037

4138
#[rustc_deprecated(reason = "moved to core::ops", since = "1.22.0")]
42-
pub use core::ops::range;
39+
#[unstable(feature = "range_argument", issue = "30877")]
40+
pub mod range { }
4341

4442
pub use alloc::Bound;
4543

src/libcore/ops/range.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,22 +389,21 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
389389
/// `Bound`s are range endpoints:
390390
///
391391
/// ```
392-
/// #![feature(collections_range)]
392+
/// # #![feature(range_argument)]
393+
/// use std::ops::RangeBounds;
394+
/// use std::ops::Bound::*;
393395
///
394-
/// use std::collections::range::RangeArgument;
395-
/// use std::collections::Bound::*;
396-
///
397-
/// assert_eq!((..100).start(), Unbounded);
398-
/// assert_eq!((1..12).start(), Included(&1));
399-
/// assert_eq!((1..12).end(), Excluded(&12));
396+
/// assert_eq!(Into::<RangeBounds<i32>>::into((..100)).start, Unbounded);
397+
/// assert_eq!(Into::<RangeBounds<i32>>::into((1..12)).start, Included(1));
398+
/// assert_eq!(Into::<RangeBounds<i32>>::into((1..12)).end, Excluded(12));
400399
/// ```
401400
///
402401
/// Using a tuple of `Bound`s as an argument to [`BTreeMap::range`].
403402
/// Note that in most cases, it's better to use range syntax (`1..5`) instead.
404403
///
405404
/// ```
406405
/// use std::collections::BTreeMap;
407-
/// use std::collections::Bound::{Excluded, Included, Unbounded};
406+
/// use std::ops::Bound::{Excluded, Included, Unbounded};
408407
///
409408
/// let mut map = BTreeMap::new();
410409
/// map.insert(3, "a");
@@ -418,7 +417,7 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
418417
/// assert_eq!(Some((&3, &"a")), map.range((Unbounded, Included(5))).next());
419418
/// ```
420419
///
421-
/// [`BTreeMap::range`]: btree_map/struct.BTreeMap.html#method.range
420+
/// [`BTreeMap::range`]: ../std/collections/struct.BTreeMap.html#method.range
422421
#[stable(feature = "collections_bound", since = "1.17.0")]
423422
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
424423
pub enum Bound<T> {

src/librustc_data_structures/array_vec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ impl<A: Array> ArrayVec<A> {
118118
// the hole, and the vector length is restored to the new length.
119119
//
120120
let len = self.len();
121+
let range = range.into();
121122
let start = match range.start {
122123
Included(n) => n,
123124
Excluded(n) => n + 1,

src/librustc_data_structures/indexed_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<I: Idx, T> IndexVec<I, T> {
152152
}
153153

154154
#[inline]
155-
pub fn drain_enumerated<'a, R: RangeArgument<usize>>(
155+
pub fn drain_enumerated<'a, R: Into<RangeBounds<usize>>> (
156156
&'a mut self, range: R) -> impl Iterator<Item=(I, T)> + 'a {
157157
self.raw.drain(range).enumerate().map(IntoIdx { _marker: PhantomData })
158158
}

src/librustc_data_structures/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
#![deny(warnings)]
2323

2424
#![feature(shared)]
25-
#![feature(collections_range)]
2625
#![feature(nonzero)]
2726
#![feature(unboxed_closures)]
2827
#![feature(fn_traits)]
2928
#![feature(unsize)]
3029
#![feature(i128_type)]
3130
#![feature(conservative_impl_trait)]
3231
#![feature(specialization)]
32+
#![feature(range_argument)]
3333

3434
#![cfg_attr(unix, feature(libc))]
3535
#![cfg_attr(test, feature(test))]

src/libstd/collections/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,9 @@ pub use self::hash_map::HashMap;
436436
pub use self::hash_set::HashSet;
437437

438438
#[rustc_deprecated(reason = "moved to std::ops", since = "1.22.0")]
439-
pub use std::ops::range;
439+
#[unstable(feature = "range_argument", issue = "30877")]
440+
/// `RangeArgument` is deprecated and moved to std::ops
441+
pub mod range { }
440442

441443
mod hash;
442444

src/test/run-pass/sync-send-iterators-in-libcollections.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ fn main() {
5050
all_sync_send!(BinaryHeap::<usize>::new(), iter, drain, into_iter);
5151

5252
all_sync_send!(BTreeMap::<usize, usize>::new(), iter, iter_mut, into_iter, keys, values);
53-
is_sync_send!(BTreeMap::<usize, usize>::new(), range((Included(&0), Included(&9))));
54-
is_sync_send!(BTreeMap::<usize, usize>::new(), range_mut((Included(&0), Included(&9))));
53+
is_sync_send!(BTreeMap::<usize, usize>::new(), range((Included(0), Included(9))));
54+
is_sync_send!(BTreeMap::<usize, usize>::new(), range_mut((Included(0), Included(9))));
5555

5656
all_sync_send!(BTreeSet::<usize>::new(), iter, into_iter);
57-
is_sync_send!(BTreeSet::<usize>::new(), range((Included(&0), Included(&9))));
57+
is_sync_send!(BTreeSet::<usize>::new(), range((Included(0), Included(9))));
5858
is_sync_send!(BTreeSet::<usize>::new(), difference(&BTreeSet::<usize>::new()));
5959
is_sync_send!(BTreeSet::<usize>::new(), symmetric_difference(&BTreeSet::<usize>::new()));
6060
is_sync_send!(BTreeSet::<usize>::new(), intersection(&BTreeSet::<usize>::new()));

0 commit comments

Comments
 (0)