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

Cherry-picking beta-nominated in to beta #24708

Merged
merged 25 commits into from
Apr 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f702218
Check for shadowing between lifetimes and loop labels in function bod…
pnkfelix Apr 3, 2015
b2ac06f
Tests for shadowing between lifetimes and loop labels within function…
pnkfelix Apr 8, 2015
f1585ab
add notes clarifying introduction of warnings for a pair of run-pass …
pnkfelix Apr 21, 2015
dd90a5b
typeck: Do high-level structural/signature checks before function bod…
pnkfelix Apr 14, 2015
727b72c
Regression tests for issues that led me to revise typeck.
pnkfelix Apr 14, 2015
399b4cc
Fallout from this change.
pnkfelix Apr 14, 2015
dca9882
factor out useful helper.
pnkfelix Apr 15, 2015
c343896
Add conditional overflow-checking to signed negate operator.
pnkfelix Apr 15, 2015
378fbcd
side-step potentially panic'ing negate in `fn abs`.
pnkfelix Apr 15, 2015
e99cc02
Workaround deliberate overflowing negation in serialize::json.
pnkfelix Apr 16, 2015
be49cb6
unit test for checked overflow during signed negation.
pnkfelix Apr 17, 2015
6d4647b
std: Add Default/IntoIterator/ToOwned to the prelude
alexcrichton Apr 17, 2015
c0d2553
unstabilize Words struct
kwantam Apr 21, 2015
53dd775
std: Remove deprecated AsOsStr/Str/AsSlice traits
alexcrichton Apr 17, 2015
fd685ce
std: Remove deprecated AsPath trait
alexcrichton Apr 17, 2015
0372484
std: Remove deprecated/unstable num functionality
alexcrichton Apr 17, 2015
d8b6335
test: Fix fallout in tests
alexcrichton Apr 18, 2015
1c9aa36
std: Bring back f32::from_str_radix as an unstable API
alexcrichton Apr 18, 2015
95d02a2
Make stability attributes an error. #22830
brson Apr 21, 2015
fc74ba2
Test fixes and rebase conflicts, round 1
alexcrichton Apr 21, 2015
8b5482e
Add `Sync` to the bounds in `io::Error`
lilyball Apr 6, 2015
c4dae05
Create a struct to represent early-bound regions
nikomatsakis Apr 15, 2015
a4d37bc
Augment the constrainted parameter check to ensure that all regions
nikomatsakis Apr 15, 2015
96d927a
Rewrite constrained type params code to operate generically over
nikomatsakis Apr 15, 2015
9b1573c
Fix some missing cases
nikomatsakis Apr 17, 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
75 changes: 0 additions & 75 deletions src/doc/trpl/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,81 +389,6 @@ This shows off the additional feature of `where` clauses: they allow bounds
where the left-hand side is an arbitrary type (`i32` in this case), not just a
plain type parameter (like `T`).

## Our `inverse` Example

Back in [Generics](generics.html), we were trying to write code like this:

```{rust,ignore}
fn inverse<T>(x: T) -> Result<T, String> {
if x == 0.0 { return Err("x cannot be zero!".to_string()); }

Ok(1.0 / x)
}
```

If we try to compile it, we get this error:

```text
error: binary operation `==` cannot be applied to type `T`
```

This is because `T` is too generic: we don't know if a random `T` can be
compared. For that, we can use trait bounds. It doesn't quite work, but try
this:

```{rust,ignore}
fn inverse<T: PartialEq>(x: T) -> Result<T, String> {
if x == 0.0 { return Err("x cannot be zero!".to_string()); }

Ok(1.0 / x)
}
```

You should get this error:

```text
error: mismatched types:
expected `T`,
found `_`
(expected type parameter,
found floating-point variable)
```

So this won't work. While our `T` is `PartialEq`, we expected to have another `T`,
but instead, we found a floating-point variable. We need a different bound. `Float`
to the rescue:

```
# #![feature(std_misc)]
use std::num::Float;

fn inverse<T: Float>(x: T) -> Result<T, String> {
if x == Float::zero() { return Err("x cannot be zero!".to_string()) }

let one: T = Float::one();
Ok(one / x)
}
```

We've had to replace our generic `0.0` and `1.0` with the appropriate methods
from the `Float` trait. Both `f32` and `f64` implement `Float`, so our function
works just fine:

```
# #![feature(std_misc)]
# use std::num::Float;
# fn inverse<T: Float>(x: T) -> Result<T, String> {
# if x == Float::zero() { return Err("x cannot be zero!".to_string()) }
# let one: T = Float::one();
# Ok(one / x)
# }
println!("the inverse of {} is {:?}", 2.0f32, inverse(2.0f32));
println!("the inverse of {} is {:?}", 2.0f64, inverse(2.0f64));

println!("the inverse of {} is {:?}", 0.0f32, inverse(0.0f32));
println!("the inverse of {} is {:?}", 0.0f64, inverse(0.0f64));
```

## Default methods

There's one last feature of traits we should cover: default methods. It's
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ use core::atomic;
use core::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};
use core::fmt;
use core::cmp::Ordering;
use core::default::Default;
use core::mem::{min_align_of, size_of};
use core::mem;
use core::nonzero::NonZero;
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ use core::prelude::*;

use core::any::Any;
use core::cmp::Ordering;
use core::default::Default;
use core::fmt;
use core::hash::{self, Hash};
use core::mem;
Expand Down
44 changes: 19 additions & 25 deletions src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@

use core::prelude::*;

use core::default::Default;
use core::iter::{FromIterator, IntoIterator};
use core::iter::{FromIterator};
use core::mem::{zeroed, replace, swap};
use core::ptr;

Expand Down Expand Up @@ -250,28 +249,6 @@ impl<T: Ord> BinaryHeap<T> {
Iter { iter: self.data.iter() }
}

/// Creates a consuming iterator, that is, one that moves each value out of
/// the binary heap in arbitrary order. The binary heap cannot be used
/// after calling this.
///
/// # Examples
///
/// ```
/// # #![feature(collections)]
/// use std::collections::BinaryHeap;
/// let heap = BinaryHeap::from_vec(vec![1, 2, 3, 4]);
///
/// // Print 1, 2, 3, 4 in arbitrary order
/// for x in heap.into_iter() {
/// // x has type i32, not &i32
/// println!("{}", x);
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<T> {
IntoIter { iter: self.data.into_iter() }
}

/// Returns the greatest item in the binary heap, or `None` if it is empty.
///
/// # Examples
Expand Down Expand Up @@ -675,8 +652,25 @@ impl<T: Ord> IntoIterator for BinaryHeap<T> {
type Item = T;
type IntoIter = IntoIter<T>;

/// Creates a consuming iterator, that is, one that moves each value out of
/// the binary heap in arbitrary order. The binary heap cannot be used
/// after calling this.
///
/// # Examples
///
/// ```
/// # #![feature(collections)]
/// use std::collections::BinaryHeap;
/// let heap = BinaryHeap::from_vec(vec![1, 2, 3, 4]);
///
/// // Print 1, 2, 3, 4 in arbitrary order
/// for x in heap.into_iter() {
/// // x has type i32, not &i32
/// println!("{}", x);
/// }
/// ```
fn into_iter(self) -> IntoIter<T> {
self.into_iter()
IntoIter { iter: self.data.into_iter() }
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
//! ```
//! # #![feature(collections, core, step_by)]
//! use std::collections::{BitSet, BitVec};
//! use std::num::Float;
//! use std::iter;
//!
//! let max_prime = 10000;
Expand Down Expand Up @@ -85,12 +84,11 @@ use core::prelude::*;

use core::cmp::Ordering;
use core::cmp;
use core::default::Default;
use core::fmt;
use core::hash;
use core::iter::RandomAccessIterator;
use core::iter::{Chain, Enumerate, Repeat, Skip, Take, repeat, Cloned};
use core::iter::{self, FromIterator, IntoIterator};
use core::iter::{self, FromIterator};
use core::ops::Index;
use core::slice;
use core::{u8, u32, usize};
Expand Down
58 changes: 26 additions & 32 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ use self::Entry::*;
use core::prelude::*;

use core::cmp::Ordering;
use core::default::Default;
use core::fmt::Debug;
use core::hash::{Hash, Hasher};
use core::iter::{Map, FromIterator, IntoIterator};
use core::iter::{Map, FromIterator};
use core::ops::Index;
use core::{iter, fmt, mem, usize};
use Bound::{self, Included, Excluded, Unbounded};
Expand Down Expand Up @@ -472,8 +471,32 @@ impl<K, V> IntoIterator for BTreeMap<K, V> {
type Item = (K, V);
type IntoIter = IntoIter<K, V>;

/// Gets an owning iterator over the entries of the map.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// map.insert(1, "a");
/// map.insert(2, "b");
/// map.insert(3, "c");
///
/// for (key, value) in map.into_iter() {
/// println!("{}: {}", key, value);
/// }
/// ```
fn into_iter(self) -> IntoIter<K, V> {
self.into_iter()
let len = self.len();
let mut lca = VecDeque::new();
lca.push_back(Traverse::traverse(self.root));
IntoIter {
inner: AbsIter {
traversals: lca,
size: len,
}
}
}
}

Expand Down Expand Up @@ -1264,35 +1287,6 @@ impl<K, V> BTreeMap<K, V> {
}
}

/// Gets an owning iterator over the entries of the map.
///
/// # Examples
///
/// ```
/// use std::collections::BTreeMap;
///
/// let mut map = BTreeMap::new();
/// map.insert(1, "a");
/// map.insert(2, "b");
/// map.insert(3, "c");
///
/// for (key, value) in map.into_iter() {
/// println!("{}: {}", key, value);
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<K, V> {
let len = self.len();
let mut lca = VecDeque::new();
lca.push_back(Traverse::traverse(self.root));
IntoIter {
inner: AbsIter {
traversals: lca,
size: len,
}
}
}

/// Gets an iterator over the keys of the map.
///
/// # Examples
Expand Down
42 changes: 18 additions & 24 deletions src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
use core::prelude::*;

use core::cmp::Ordering::{self, Less, Greater, Equal};
use core::default::Default;
use core::fmt::Debug;
use core::fmt;
use core::iter::{Peekable, Map, FromIterator, IntoIterator};
use core::iter::{Peekable, Map, FromIterator};
use core::ops::{BitOr, BitAnd, BitXor, Sub};

use borrow::Borrow;
Expand Down Expand Up @@ -132,27 +131,6 @@ impl<T> BTreeSet<T> {
pub fn iter(&self) -> Iter<T> {
Iter { iter: self.map.keys() }
}

/// Gets an iterator for moving out the BtreeSet's contents.
///
/// # Examples
///
/// ```
/// # #![feature(core)]
/// use std::collections::BTreeSet;
///
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().cloned().collect();
///
/// let v: Vec<usize> = set.into_iter().collect();
/// assert_eq!(v, [1, 2, 3, 4]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_iter(self) -> IntoIter<T> {
fn first<A, B>((a, _): (A, B)) -> A { a }
let first: fn((T, ())) -> T = first; // coerce to fn pointer

IntoIter { iter: self.map.into_iter().map(first) }
}
}

impl<T: Ord> BTreeSet<T> {
Expand Down Expand Up @@ -500,8 +478,24 @@ impl<T> IntoIterator for BTreeSet<T> {
type Item = T;
type IntoIter = IntoIter<T>;

/// Gets an iterator for moving out the BtreeSet's contents.
///
/// # Examples
///
/// ```
/// # #![feature(core)]
/// use std::collections::BTreeSet;
///
/// let set: BTreeSet<usize> = [1, 2, 3, 4].iter().cloned().collect();
///
/// let v: Vec<usize> = set.into_iter().collect();
/// assert_eq!(v, [1, 2, 3, 4]);
/// ```
fn into_iter(self) -> IntoIter<T> {
self.into_iter()
fn first<A, B>((a, _): (A, B)) -> A { a }
let first: fn((T, ())) -> T = first; // coerce to fn pointer

IntoIter { iter: self.map.into_iter().map(first) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use core::prelude::*;
use core::marker;
use core::fmt;
use core::iter::{FromIterator, IntoIterator};
use core::iter::{FromIterator};
use core::ops::{Sub, BitOr, BitAnd, BitXor};

// FIXME(contentions): implement union family of methods? (general design may be wrong here)
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
//! # #![feature(core, std_misc)]
//! use std::fmt;
//! use std::f64;
//! use std::num::Float;
//!
//! #[derive(Debug)]
//! struct Vector2D {
Expand All @@ -202,10 +201,11 @@
//! let magnitude = magnitude.sqrt();
//!
//! // Respect the formatting flags by using the helper method
//! // `pad_integral` on the Formatter object. See the method documentation
//! // for details, and the function `pad` can be used to pad strings.
//! // `pad_integral` on the Formatter object. See the method
//! // documentation for details, and the function `pad` can be used
//! // to pad strings.
//! let decimals = f.precision().unwrap_or(3);
//! let string = f64::to_str_exact(magnitude, decimals);
//! let string = format!("{:.*}", decimals, magnitude);
//! f.pad_integral(true, "", &string)
//! }
//! }
Expand Down
1 change: 1 addition & 0 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#![feature(unsafe_no_drop_flag, filling_drop)]
#![feature(step_by)]
#![feature(str_char)]
#![feature(str_words)]
#![feature(slice_patterns)]
#![feature(debug_builders)]
#![feature(utf8_error)]
Expand Down
Loading