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 #28051

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dddc4ca
Improve E0046
GuillaumeGomez Aug 26, 2015
9e51cee
Improve E0062 error explanation
GuillaumeGomez Aug 26, 2015
612221f
Improve E0063 error explanation
GuillaumeGomez Aug 26, 2015
5d8dc90
Improve E0025 error explanation
GuillaumeGomez Aug 26, 2015
af02bcc
Fix typo in E0087
GuillaumeGomez Aug 26, 2015
0c4faf2
Add erroneous code example for E0131
GuillaumeGomez Aug 26, 2015
9f15b28
Add missing ';' in E0132
GuillaumeGomez Aug 26, 2015
dfb0677
Remove unnecessary whitespace
GuillaumeGomez Aug 26, 2015
805e4e6
Remove unnecessary empty lines
GuillaumeGomez Aug 26, 2015
acafe3b
Add E0370 error explanation
GuillaumeGomez Aug 26, 2015
c891fae
Fix keyboard scrolling in rustbook
artemshitov Aug 26, 2015
b392016
Remove redundant overflowing rule
artemshitov Aug 26, 2015
933eb3e
path: the if-else block looked unusual
tshepang Aug 26, 2015
a7313a0
core: Implement IntoIterator for Option and Result references
birkenfeld Aug 27, 2015
fbbd874
Comment out unused error codes in librustc_typeck/diagnostics.rs
GuillaumeGomez Aug 27, 2015
21f209a
remove calls to deprecated `iter::order` functions
apasel422 Aug 27, 2015
59653c1
Some extra examples for the unimplemented! macro
steveklabnik Aug 27, 2015
886ea16
Rollup merge of #28010 - GuillaumeGomez:patch-2, r=Manishearth
Manishearth Aug 27, 2015
bf517fd
Rollup merge of #28013 - artemshitov:rustbook-scrolling, r=steveklabnik
Manishearth Aug 27, 2015
4d975c9
Rollup merge of #28029 - tshepang:unusual, r=steveklabnik
Manishearth Aug 27, 2015
51cc430
Rollup merge of #28039 - birkenfeld:option_result_ref_intoiter, r=ale…
Manishearth Aug 27, 2015
4b1967c
Rollup merge of #28045 - apasel422:iter, r=sfackler
Manishearth Aug 27, 2015
fe7a8a4
Rollup merge of #28048 - steveklabnik:doc_unimplemented, r=alexcrichton
Manishearth Aug 27, 2015
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
45 changes: 45 additions & 0 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,51 @@ macro_rules! unreachable {

/// A standardised placeholder for marking unfinished code. It panics with the
/// message `"not yet implemented"` when executed.
///
/// This can be useful if you are prototyping and are just looking to have your
/// code typecheck, or if you're implementing a trait that requires multiple
/// methods, and you're only planning on using one of them.
///
/// # Examples
///
/// Here's an example of some in-progress code. We have a trait `Foo`:
///
/// ```
/// trait Foo {
/// fn bar(&self);
/// fn baz(&self);
/// }
/// ```
///
/// We want to implement `Foo` on one of our types, but we also want to work on
/// just `bar()` first. In order for our code to compile, we need to implement
/// `baz()`, so we can use `unimplemented!`:
///
/// ```
/// # trait Foo {
/// # fn foo(&self);
/// # fn bar(&self);
/// # }
/// struct MyStruct;
///
/// impl Foo for MyStruct {
/// fn foo(&self) {
/// // implementation goes here
/// }
///
/// fn bar(&self) {
/// // let's not worry about implementing bar() for now
/// unimplemented!();
/// }
/// }
///
/// fn main() {
/// let s = MyStruct;
/// s.foo();
///
/// // we aren't even using bar() yet, so this is fine.
/// }
/// ```
#[macro_export]
#[unstable(feature = "core",
reason = "relationship with panic is unclear")]
Expand Down
20 changes: 20 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,26 @@ impl<T> IntoIterator for Option<T> {
}
}

#[stable(since = "1.4.0", feature = "option_iter")]
impl<'a, T> IntoIterator for &'a Option<T> {
type Item = &'a T;
type IntoIter = Iter<'a, T>;

fn into_iter(self) -> Iter<'a, T> {
self.iter()
}
}

#[stable(since = "1.4.0", feature = "option_iter")]
impl<'a, T> IntoIterator for &'a mut Option<T> {
type Item = &'a mut T;
type IntoIter = IterMut<'a, T>;

fn into_iter(mut self) -> IterMut<'a, T> {
self.iter_mut()
}
}

/////////////////////////////////////////////////////////////////////////////
// The Option Iterators
/////////////////////////////////////////////////////////////////////////////
Expand Down
20 changes: 20 additions & 0 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,26 @@ impl<T, E> IntoIterator for Result<T, E> {
}
}

#[stable(since = "1.4.0", feature = "result_iter")]
impl<'a, T, E> IntoIterator for &'a Result<T, E> {
type Item = &'a T;
type IntoIter = Iter<'a, T>;

fn into_iter(self) -> Iter<'a, T> {
self.iter()
}
}

#[stable(since = "1.4.0", feature = "result_iter")]
impl<'a, T, E> IntoIterator for &'a mut Result<T, E> {
type Item = &'a mut T;
type IntoIter = IterMut<'a, T>;

fn into_iter(mut self) -> IterMut<'a, T> {
self.iter_mut()
}
}

/////////////////////////////////////////////////////////////////////////////
// The Result Iterators
/////////////////////////////////////////////////////////////////////////////
Expand Down
53 changes: 26 additions & 27 deletions src/libcoretest/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

use core::iter::*;
use core::iter::order::*;
use core::{i8, i16, isize};
use core::usize;

Expand All @@ -21,51 +20,51 @@ fn test_lt() {
let xs = [1,2,3];
let ys = [1,2,0];

assert!(!lt(xs.iter(), ys.iter()));
assert!(!le(xs.iter(), ys.iter()));
assert!( gt(xs.iter(), ys.iter()));
assert!( ge(xs.iter(), ys.iter()));
assert!(!xs.iter().lt(ys.iter()));
assert!(!xs.iter().le(ys.iter()));
assert!( xs.iter().gt(ys.iter()));
assert!( xs.iter().ge(ys.iter()));

assert!( lt(ys.iter(), xs.iter()));
assert!( le(ys.iter(), xs.iter()));
assert!(!gt(ys.iter(), xs.iter()));
assert!(!ge(ys.iter(), xs.iter()));
assert!( ys.iter().lt(xs.iter()));
assert!( ys.iter().le(xs.iter()));
assert!(!ys.iter().gt(xs.iter()));
assert!(!ys.iter().ge(xs.iter()));

assert!( lt(empty.iter(), xs.iter()));
assert!( le(empty.iter(), xs.iter()));
assert!(!gt(empty.iter(), xs.iter()));
assert!(!ge(empty.iter(), xs.iter()));
assert!( empty.iter().lt(xs.iter()));
assert!( empty.iter().le(xs.iter()));
assert!(!empty.iter().gt(xs.iter()));
assert!(!empty.iter().ge(xs.iter()));

// Sequence with NaN
let u = [1.0f64, 2.0];
let v = [0.0f64/0.0, 3.0];

assert!(!lt(u.iter(), v.iter()));
assert!(!le(u.iter(), v.iter()));
assert!(!gt(u.iter(), v.iter()));
assert!(!ge(u.iter(), v.iter()));
assert!(!u.iter().lt(v.iter()));
assert!(!u.iter().le(v.iter()));
assert!(!u.iter().gt(v.iter()));
assert!(!u.iter().ge(v.iter()));

let a = [0.0f64/0.0];
let b = [1.0f64];
let c = [2.0f64];

assert!(lt(a.iter(), b.iter()) == (a[0] < b[0]));
assert!(le(a.iter(), b.iter()) == (a[0] <= b[0]));
assert!(gt(a.iter(), b.iter()) == (a[0] > b[0]));
assert!(ge(a.iter(), b.iter()) == (a[0] >= b[0]));
assert!(a.iter().lt(b.iter()) == (a[0] < b[0]));
assert!(a.iter().le(b.iter()) == (a[0] <= b[0]));
assert!(a.iter().gt(b.iter()) == (a[0] > b[0]));
assert!(a.iter().ge(b.iter()) == (a[0] >= b[0]));

assert!(lt(c.iter(), b.iter()) == (c[0] < b[0]));
assert!(le(c.iter(), b.iter()) == (c[0] <= b[0]));
assert!(gt(c.iter(), b.iter()) == (c[0] > b[0]));
assert!(ge(c.iter(), b.iter()) == (c[0] >= b[0]));
assert!(c.iter().lt(b.iter()) == (c[0] < b[0]));
assert!(c.iter().le(b.iter()) == (c[0] <= b[0]));
assert!(c.iter().gt(b.iter()) == (c[0] > b[0]));
assert!(c.iter().ge(b.iter()) == (c[0] >= b[0]));
}

#[test]
fn test_multi_iter() {
let xs = [1,2,3,4];
let ys = [4,3,2,1];
assert!(eq(xs.iter(), ys.iter().rev()));
assert!(lt(xs.iter(), xs.iter().skip(2)));
assert!(xs.iter().eq(ys.iter().rev()));
assert!(xs.iter().lt(xs.iter().skip(2)));
}

#[test]
Expand Down
9 changes: 8 additions & 1 deletion src/libcoretest/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,14 @@ fn test_iter() {
assert_eq!(it.next(), Some(&val));
assert_eq!(it.size_hint(), (0, Some(0)));
assert!(it.next().is_none());

let mut it = (&x).into_iter();
assert_eq!(it.next(), Some(&val));
}

#[test]
fn test_mut_iter() {
let val = 5;
let mut val = 5;
let new_val = 11;

let mut x = Some(val);
Expand All @@ -205,6 +208,10 @@ fn test_mut_iter() {
assert!(it.next().is_none());
}
assert_eq!(x, Some(new_val));

let mut y = Some(val);
let mut it = (&mut y).into_iter();
assert_eq!(it.next(), Some(&mut val));
}

#[test]
Expand Down
33 changes: 33 additions & 0 deletions src/libcoretest/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,36 @@ pub fn test_expect_err() {
let err: Result<isize, &'static str> = Err("All good");
err.expect("Got expected error");
}

#[test]
pub fn test_iter() {
let ok: Result<isize, &'static str> = Ok(100);
let mut it = ok.iter();
assert_eq!(it.size_hint(), (1, Some(1)));
assert_eq!(it.next(), Some(&100));
assert_eq!(it.size_hint(), (0, Some(0)));
assert!(it.next().is_none());
assert_eq!((&ok).into_iter().next(), Some(&100));

let err: Result<isize, &'static str> = Err("error");
assert_eq!(err.iter().next(), None);
}

#[test]
pub fn test_iter_mut() {
let mut ok: Result<isize, &'static str> = Ok(100);
for loc in ok.iter_mut() {
*loc = 200;
}
assert_eq!(ok, Ok(200));
for loc in &mut ok {
*loc = 300;
}
assert_eq!(ok, Ok(300));

let mut err: Result<isize, &'static str> = Err("error");
for loc in err.iter_mut() {
*loc = 200;
}
assert_eq!(err, Err("error"));
}
Loading