Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #40167

Merged
merged 29 commits into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3288189
impl RangeArgument for RangeInclusive and add appropriate tests
djzin Feb 18, 2017
65c876f
add test for max value
djzin Feb 18, 2017
4338290
add impl for RangeToInclusive
djzin Feb 18, 2017
6a10e63
added Error and Display impl for std::ffi::FromBytesWithNulError
chordowl Feb 19, 2017
48331ef
changed stability annotations
chordowl Feb 21, 2017
097398e
impl FromIter<&char> for String
withoutboats Feb 22, 2017
081336e
Improve associated constant rendering in rustdoc
GuillaumeGomez Feb 18, 2017
5ac7a03
Put the const type and value into <code>
GuillaumeGomez Feb 26, 2017
d21b0e3
Move two large error_reporting fn's to a separate file
Feb 27, 2017
2f8ef50
Lower moved fn's visibility to supermodule
Feb 27, 2017
e136bf6
Format note.rs with rustfmt
Feb 27, 2017
d06f72d
Apply the same transformation to every types
GuillaumeGomez Feb 27, 2017
bd704ba
Update tests accordingly
GuillaumeGomez Feb 27, 2017
d09e512
Remove a `loop` in `ext::tt::transcribe`.
jseyfried Jan 26, 2017
abdc689
Clean up `ext::tt::transcribe::TtFrame`, rename to `Frame`.
jseyfried Jan 27, 2017
8c4960b
Remove `ext::tt::transcribe::tt_next_token`.
jseyfried Jan 27, 2017
2471888
Avoid `Token::{OpenDelim, CloseDelim}`.
jseyfried Jan 28, 2017
d8b34e9
Add `syntax::ext::tt::quoted::{TokenTree, ..}` and remove `tokenstrea…
jseyfried Jan 29, 2017
0cc7053
Remove `Token::MatchNt`.
jseyfried Jan 30, 2017
7524130
Merge `repeat_idx` and `repeat_len`.
jseyfried Jan 31, 2017
7f822c8
Refactor out `parser.expect_delimited_token_tree()`.
jseyfried Jan 31, 2017
61a9a14
Add warning cycle.
jseyfried Feb 26, 2017
839398a
Add regression test.
jseyfried Feb 28, 2017
4ba49ab
Rollup merge of #39419 - jseyfried:simplify_tokentree, r=nrc
frewsxcv Mar 1, 2017
43df65f
Rollup merge of #39936 - djzin:inclusive_rangeargument, r=alexcrichton
frewsxcv Mar 1, 2017
fda3f98
Rollup merge of #39944 - GuillaumeGomez:associated-consts, r=frewsxcv
frewsxcv Mar 1, 2017
06a0233
Rollup merge of #39960 - lukaramu:issue-39925, r=alexcrichton
frewsxcv Mar 1, 2017
0a008b9
Rollup merge of #40028 - withoutboats:string_from_iter, r=alexcrichton
frewsxcv Mar 1, 2017
0b5bf67
Rollup merge of #40128 - cengizIO:master, r=nikomatsakis
frewsxcv Mar 1, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/libcollections/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

//! Range syntax.

use core::ops::{RangeFull, Range, RangeTo, RangeFrom};
use core::ops::{RangeFull, Range, RangeTo, RangeFrom, RangeInclusive, RangeToInclusive};
use Bound::{self, Excluded, Included, Unbounded};

/// **RangeArgument** is implemented by Rust's built-in range types, produced
Expand Down Expand Up @@ -105,6 +105,32 @@ impl<T> RangeArgument<T> for Range<T> {
}
}

#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
impl<T> RangeArgument<T> for RangeInclusive<T> {
fn start(&self) -> Bound<&T> {
match *self {
RangeInclusive::Empty{ ref at } => Included(at),
RangeInclusive::NonEmpty { ref start, .. } => Included(start),
}
}
fn end(&self) -> Bound<&T> {
match *self {
RangeInclusive::Empty{ ref at } => Excluded(at),
RangeInclusive::NonEmpty { ref end, .. } => Included(end),
}
}
}

#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
impl<T> RangeArgument<T> for RangeToInclusive<T> {
fn start(&self) -> Bound<&T> {
Unbounded
}
fn end(&self) -> Bound<&T> {
Included(&self.end)
}
}

impl<T> RangeArgument<T> for (Bound<T>, Bound<T>) {
fn start(&self) -> Bound<&T> {
match *self {
Expand Down
9 changes: 9 additions & 0 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,15 @@ impl FromIterator<char> for String {
}
}

#[stable(feature = "string_from_iter_by_ref", since = "1.17.0")]
impl<'a> FromIterator<&'a char> for String {
fn from_iter<I: IntoIterator<Item = &'a char>>(iter: I) -> String {
let mut buf = String::new();
buf.extend(iter);
buf
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> FromIterator<&'a str> for String {
fn from_iter<I: IntoIterator<Item = &'a str>>(iter: I) -> String {
Expand Down
37 changes: 37 additions & 0 deletions src/libcollectionstest/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,43 @@ fn test_range_small() {
assert_eq!(j, size - 2);
}

#[test]
fn test_range_inclusive() {
let size = 500;

let map: BTreeMap<_, _> = (0...size).map(|i| (i, i)).collect();

fn check<'a, L, R>(lhs: L, rhs: R)
where L: IntoIterator<Item=(&'a i32, &'a i32)>,
R: IntoIterator<Item=(&'a i32, &'a i32)>,
{
let lhs: Vec<_> = lhs.into_iter().collect();
let rhs: Vec<_> = rhs.into_iter().collect();
assert_eq!(lhs, rhs);
}

check(map.range(size + 1...size + 1), vec![]);
check(map.range(size...size), vec![(&size, &size)]);
check(map.range(size...size + 1), vec![(&size, &size)]);
check(map.range(0...0), vec![(&0, &0)]);
check(map.range(0...size - 1), map.range(..size));
check(map.range(-1...-1), vec![]);
check(map.range(-1...size), map.range(..));
check(map.range(...size), map.range(..));
check(map.range(...200), map.range(..201));
check(map.range(5...8), vec![(&5, &5), (&6, &6), (&7, &7), (&8, &8)]);
check(map.range(-1...0), vec![(&0, &0)]);
check(map.range(-1...2), vec![(&0, &0), (&1, &1), (&2, &2)]);
}

#[test]
fn test_range_inclusive_max_value() {
let max = ::std::usize::MAX;
let map: BTreeMap<_, _> = vec![(max, 0)].into_iter().collect();

assert_eq!(map.range(max...max).collect::<Vec<_>>(), &[(&max, &0)]);
}

#[test]
fn test_range_equal_empty_cases() {
let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect();
Expand Down
1 change: 1 addition & 0 deletions src/libcollectionstest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![feature(binary_heap_peek_mut_pop)]
#![feature(box_syntax)]
#![feature(btree_range)]
#![feature(inclusive_range_syntax)]
#![feature(collection_placement)]
#![feature(collections)]
#![feature(collections_bound)]
Expand Down
50 changes: 50 additions & 0 deletions src/libcollectionstest/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,56 @@ fn test_drain_range() {
assert_eq!(v, &[(), ()]);
}

#[test]
fn test_drain_inclusive_range() {
let mut v = vec!['a', 'b', 'c', 'd', 'e'];
for _ in v.drain(1...3) {
}
assert_eq!(v, &['a', 'e']);

let mut v: Vec<_> = (0...5).map(|x| x.to_string()).collect();
for _ in v.drain(1...5) {
}
assert_eq!(v, &["0".to_string()]);

let mut v: Vec<String> = (0...5).map(|x| x.to_string()).collect();
for _ in v.drain(0...5) {
}
assert_eq!(v, Vec::<String>::new());

let mut v: Vec<_> = (0...5).map(|x| x.to_string()).collect();
for _ in v.drain(0...3) {
}
assert_eq!(v, &["4".to_string(), "5".to_string()]);

let mut v: Vec<_> = (0...1).map(|x| x.to_string()).collect();
for _ in v.drain(...0) {
}
assert_eq!(v, &["1".to_string()]);
}

#[test]
fn test_drain_max_vec_size() {
let mut v = Vec::<()>::with_capacity(usize::max_value());
unsafe { v.set_len(usize::max_value()); }
for _ in v.drain(usize::max_value() - 1..) {
}
assert_eq!(v.len(), usize::max_value() - 1);

let mut v = Vec::<()>::with_capacity(usize::max_value());
unsafe { v.set_len(usize::max_value()); }
for _ in v.drain(usize::max_value() - 1...usize::max_value() - 1) {
}
assert_eq!(v.len(), usize::max_value() - 1);
}

#[test]
#[should_panic]
fn test_drain_inclusive_out_of_bounds() {
let mut v = vec![1, 2, 3, 4, 5];
v.drain(5...5);
}

#[test]
fn test_into_boxed_slice() {
let xs = vec![1, 2, 3];
Expand Down
3 changes: 1 addition & 2 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ impl FromStr for TokenStream {
__internal::with_parse_sess(|sess| {
let src = src.to_string();
let name = "<proc-macro source code>".to_string();
let tts = try!(parse::parse_tts_from_source_str(name, src, sess)
.map_err(parse_to_lex_err));
let tts = parse::parse_tts_from_source_str(name, src, sess);

Ok(__internal::token_stream_wrap(tts.into_iter().collect()))
})
Expand Down
1 change: 0 additions & 1 deletion src/libproc_macro_plugin/qquote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ impl Quote for TokenTree {
::syntax::tokenstream::TokenTree::Delimited(::syntax::ext::quote::rt::DUMMY_SP,
(quote delimited))
},
_ => panic!("unexpected `TokenTree::Sequence` in `qquote`"),
}
}
}
Expand Down
Loading