Skip to content

Rolling up PRs in the queue #21919

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

Merged
merged 31 commits into from
Feb 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b2297fd
std: Add some missing stability attributes
alexcrichton Feb 2, 2015
3449751
iOS: fixed build
vhbit Feb 3, 2015
88449a8
add naivest entry API to VecMap
Gankra Feb 3, 2015
9a17f62
Optimize rposition
dotdash Feb 3, 2015
c9e1c44
Allow closure arguments types to unify even if we can't fully resolve
nikomatsakis Feb 2, 2015
498595a
Teach project to unify the return type even if a precise match is not
nikomatsakis Feb 3, 2015
47f1865
Update compile-fail tests to use the expected type to force the
nikomatsakis Feb 3, 2015
0431134
Remove the explicit closure kind syntax from the parser and AST;
nikomatsakis Feb 3, 2015
68ad694
Correct one case where the inference was detecting a looser result th…
nikomatsakis Feb 3, 2015
8ddcb06
Update for new snapshot after rebasing.
nikomatsakis Feb 3, 2015
0b9e227
Move stability pass after privacy pass
Manishearth Feb 3, 2015
d30f225
std: Remove `iter::ByRef` and generalize impls
alexcrichton Feb 3, 2015
5cf9905
std: Add `io` module again
alexcrichton Feb 1, 2015
6ec5a0f
Error when #![staged_api] crates are missing stability markers
Manishearth Feb 3, 2015
c6aaea6
Fix some missing stability attrs
Manishearth Feb 3, 2015
4aa661a
Add test for missing stability checker
Manishearth Feb 3, 2015
b64572c
Add unmarked_api feature (fixes #21884)
Manishearth Feb 3, 2015
d02d4c3
Add staged_api and unmarked_api features to reference.md
Manishearth Feb 3, 2015
f5e5bdb
Fix test
Manishearth Feb 3, 2015
2258f90
Don't check stability for tests
Manishearth Feb 3, 2015
a5ddacf
More test fixes
Manishearth Feb 3, 2015
8550bf7
rollup merge of #21759: aturon/new-path
alexcrichton Feb 3, 2015
b53695b
rollup merge of #21835: alexcrichton/iov2
alexcrichton Feb 3, 2015
087e847
rollup merge of #21870: alexcrichton/missing-stability
alexcrichton Feb 3, 2015
5a35ad7
rollup merge of #21882: Gankro/vec_entry
alexcrichton Feb 3, 2015
61b2f3a
rollup merge of #21893: vhbit/ios-build-fix
alexcrichton Feb 3, 2015
1d921f5
rollup merge of #21897: dotdash/rposition
alexcrichton Feb 3, 2015
74f7e06
rollup merge of #21899: nikomatsakis/closure-unify-anyhow
alexcrichton Feb 3, 2015
9db593c
rollup merge of #21907: alexcrichton/iter-by-ref
alexcrichton Feb 3, 2015
d0029a4
rollup merge of #21910: Manishearth/missing_stability
alexcrichton Feb 3, 2015
70ecd8e
Test fixes and rebase conflicts
alexcrichton Feb 4, 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
7 changes: 7 additions & 0 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,8 @@ The currently implemented features of the reference compiler are:
* `simd` - Allows use of the `#[simd]` attribute, which is overly simple and
not the SIMD interface we want to expose in the long term.

* `staged_api` - Allows usage of stability markers and `#![staged_api]` in a crate

* `struct_inherit` - Allows using struct inheritance, which is barely
implemented and will probably be removed. Don't use this.

Expand Down Expand Up @@ -2459,6 +2461,11 @@ The currently implemented features of the reference compiler are:
which is considered wildly unsafe and will be
obsoleted by language improvements.

* `unmarked_api` - Allows use of items within a `#![staged_api]` crate
which have not been marked with a stability marker.
Such items should not be allowed by the compiler to exist,
so if you need this there probably is a compiler bug.

* `associated_types` - Allows type aliases in traits. Experimental.

If a feature is promoted to a language feature, then all existing programs will
Expand Down
32 changes: 15 additions & 17 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,18 @@

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

use core::prelude::*;

use core::any::Any;
use core::clone::Clone;
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
use core::cmp::Ordering;
use core::default::Default;
use core::error::{Error, FromError};
use core::fmt;
use core::hash::{self, Hash};
use core::iter::Iterator;
use core::marker::Sized;
use core::mem;
use core::ops::{Deref, DerefMut};
use core::option::Option;
use core::ptr::Unique;
use core::raw::TraitObject;
use core::result::Result::{Ok, Err};
use core::result::Result;

/// A value that represents the heap. This is the default place that the `box` keyword allocates
/// into when no place is supplied.
Expand Down Expand Up @@ -296,18 +292,20 @@ impl<T: ?Sized> DerefMut for Box<T> {
fn deref_mut(&mut self) -> &mut T { &mut **self }
}

impl<'a, T> Iterator for Box<Iterator<Item=T> + 'a> {
type Item = T;

fn next(&mut self) -> Option<T> {
(**self).next()
}

fn size_hint(&self) -> (usize, Option<usize>) {
(**self).size_hint()
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<I: Iterator + ?Sized> Iterator for Box<I> {
type Item = I::Item;
fn next(&mut self) -> Option<I::Item> { (**self).next() }
fn size_hint(&self) -> (usize, Option<usize>) { (**self).size_hint() }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for Box<I> {
fn next_back(&mut self) -> Option<I::Item> { (**self).next_back() }
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, E: Error + 'a> FromError<E> for Box<Error + 'a> {
fn from_error(err: E) -> Box<Error + 'a> {
Box::new(err)
Expand Down
194 changes: 193 additions & 1 deletion src/libcollections/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#![allow(missing_docs)]

pub use self::Entry::*;

use core::prelude::*;

use core::cmp::Ordering;
Expand Down Expand Up @@ -66,6 +68,32 @@ pub struct VecMap<V> {
v: Vec<Option<V>>,
}

/// A view into a single entry in a map, which may either be vacant or occupied.
#[unstable(feature = "collections",
reason = "precise API still under development")]
pub enum Entry<'a, V:'a> {
/// A vacant Entry
Vacant(VacantEntry<'a, V>),
/// An occupied Entry
Occupied(OccupiedEntry<'a, V>),
}

/// A vacant Entry.
#[unstable(feature = "collections",
reason = "precise API still under development")]
pub struct VacantEntry<'a, V:'a> {
map: &'a mut VecMap<V>,
index: usize,
}

/// An occupied Entry.
#[unstable(feature = "collections",
reason = "precise API still under development")]
pub struct OccupiedEntry<'a, V:'a> {
map: &'a mut VecMap<V>,
index: usize,
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<V> Default for VecMap<V> {
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -485,6 +513,119 @@ impl<V> VecMap<V> {
let result = &mut self.v[*key];
result.take()
}

/// Gets the given key's corresponding entry in the map for in-place manipulation.
///
/// # Examples
///
/// ```
/// use std::collections::VecMap;
/// use std::collections::vec_map::Entry;
///
/// let mut count: VecMap<u32> = VecMap::new();
///
/// // count the number of occurrences of numbers in the vec
/// for x in vec![1, 2, 1, 2, 3, 4, 1, 2, 4].iter() {
/// match count.entry(*x) {
/// Entry::Vacant(view) => {
/// view.insert(1);
/// },
/// Entry::Occupied(mut view) => {
/// let v = view.get_mut();
/// *v += 1;
/// },
/// }
/// }
///
/// assert_eq!(count[1], 3);
/// ```
#[unstable(feature = "collections",
reason = "precise API still under development")]
pub fn entry(&mut self, key: usize) -> Entry<V> {
// FIXME(Gankro): this is basically the dumbest implementation of
// entry possible, because weird non-lexical borrows issues make it
// completely insane to do any other way. That said, Entry is a border-line
// useless construct on VecMap, so it's hardly a big loss.
if self.contains_key(&key) {
Occupied(OccupiedEntry {
map: self,
index: key,
})
} else {
Vacant(VacantEntry {
map: self,
index: key,
})
}
}
}


impl<'a, V> Entry<'a, V> {
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, V>> {
match self {
Occupied(entry) => Ok(entry.into_mut()),
Vacant(entry) => Err(entry),
}
}
}

impl<'a, V> VacantEntry<'a, V> {
/// Sets the value of the entry with the VacantEntry's key,
/// and returns a mutable reference to it.
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn insert(self, value: V) -> &'a mut V {
let index = self.index;
self.map.insert(index, value);
&mut self.map[index]
}
}

impl<'a, V> OccupiedEntry<'a, V> {
/// Gets a reference to the value in the entry.
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn get(&self) -> &V {
let index = self.index;
&self.map[index]
}

/// Gets a mutable reference to the value in the entry.
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn get_mut(&mut self) -> &mut V {
let index = self.index;
&mut self.map[index]
}

/// Converts the entry into a mutable reference to its value.
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn into_mut(self) -> &'a mut V {
let index = self.index;
&mut self.map[index]
}

/// Sets the value of the entry with the OccupiedEntry's key,
/// and returns the entry's old value.
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn insert(&mut self, value: V) -> V {
let index = self.index;
self.map.insert(index, value).unwrap()
}

/// Takes the value of the entry out of the map, and returns it.
#[unstable(feature = "collections",
reason = "matches collection reform v2 specification, waiting for dust to settle")]
pub fn remove(self) -> V {
let index = self.index;
self.map.remove(&index).unwrap()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -783,7 +924,7 @@ mod test_map {
use prelude::*;
use core::hash::{hash, SipHasher};

use super::VecMap;
use super::{VecMap, Occupied, Vacant};

#[test]
fn test_get_mut() {
Expand Down Expand Up @@ -1135,6 +1276,57 @@ mod test_map {

map[4];
}

#[test]
fn test_entry(){
let xs = [(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)];

let mut map: VecMap<i32> = xs.iter().map(|&x| x).collect();

// Existing key (insert)
match map.entry(1) {
Vacant(_) => unreachable!(),
Occupied(mut view) => {
assert_eq!(view.get(), &10);
assert_eq!(view.insert(100), 10);
}
}
assert_eq!(map.get(&1).unwrap(), &100);
assert_eq!(map.len(), 6);


// Existing key (update)
match map.entry(2) {
Vacant(_) => unreachable!(),
Occupied(mut view) => {
let v = view.get_mut();
*v *= 10;
}
}
assert_eq!(map.get(&2).unwrap(), &200);
assert_eq!(map.len(), 6);

// Existing key (take)
match map.entry(3) {
Vacant(_) => unreachable!(),
Occupied(view) => {
assert_eq!(view.remove(), 30);
}
}
assert_eq!(map.get(&3), None);
assert_eq!(map.len(), 5);


// Inexistent key (insert)
match map.entry(10) {
Occupied(_) => unreachable!(),
Vacant(view) => {
assert_eq!(*view.insert(1000), 1000);
}
}
assert_eq!(map.get(&10).unwrap(), &1000);
assert_eq!(map.len(), 6);
}
}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ pub trait Show {
#[lang = "debug_trait"]
pub trait Debug {
/// Formats the value using the given formatter.
#[stable(feature = "rust1", since = "1.0.0")]
fn fmt(&self, &mut Formatter) -> Result;
}

Expand All @@ -290,6 +291,7 @@ pub trait String {
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Display {
/// Formats the value using the given formatter.
#[stable(feature = "rust1", since = "1.0.0")]
fn fmt(&self, &mut Formatter) -> Result;
}

Expand Down
Loading