Update rustfmt to 0.9.0.

This commit is contained in:
Dan Gohman
2017-08-31 10:44:59 -07:00
parent 46fb64cbb4
commit 2efdc0ed37
111 changed files with 4692 additions and 3379 deletions

View File

@@ -212,12 +212,13 @@ impl<T: EntityRef> ListPool<T> {
/// Reallocate a block to a different size class.
///
/// Copy `elems_to_copy` elements from the old to the new block.
fn realloc(&mut self,
block: usize,
from_sclass: SizeClass,
to_sclass: SizeClass,
elems_to_copy: usize)
-> usize {
fn realloc(
&mut self,
block: usize,
from_sclass: SizeClass,
to_sclass: SizeClass,
elems_to_copy: usize,
) -> usize {
assert!(elems_to_copy <= sclass_size(from_sclass));
assert!(elems_to_copy <= sclass_size(to_sclass));
let new_block = self.alloc(to_sclass);
@@ -384,7 +385,8 @@ impl<T: EntityRef> EntityList<T> {
/// Appends multiple elements to the back of the list.
pub fn extend<I>(&mut self, elements: I, pool: &mut ListPool<T>)
where I: IntoIterator<Item = T>
where
I: IntoIterator<Item = T>,
{
// TODO: use `size_hint()` to reduce reallocations.
for x in elements {
@@ -597,8 +599,10 @@ mod tests {
list.extend([i1, i1, i2, i2, i3, i3, i4, i4].iter().cloned(), pool);
assert_eq!(list.len(pool), 12);
assert_eq!(list.as_slice(pool),
&[i1, i2, i3, i4, i1, i1, i2, i2, i3, i3, i4, i4]);
assert_eq!(
list.as_slice(pool),
&[i1, i2, i3, i4, i1, i1, i2, i2, i3, i3, i4, i4]
);
}
#[test]

View File

@@ -14,8 +14,9 @@ use std::ops::{Index, IndexMut};
/// all keys have a default entry from the beginning.
#[derive(Debug, Clone)]
pub struct EntityMap<K, V>
where K: EntityRef,
V: Clone
where
K: EntityRef,
V: Clone,
{
elems: Vec<V>,
default: V,
@@ -24,12 +25,14 @@ pub struct EntityMap<K, V>
/// Shared `EntityMap` implementation for all value types.
impl<K, V> EntityMap<K, V>
where K: EntityRef,
V: Clone
where
K: EntityRef,
V: Clone,
{
/// Create a new empty map.
pub fn new() -> Self
where V: Default
where
V: Default,
{
EntityMap {
elems: Vec::new(),
@@ -68,8 +71,9 @@ impl<K, V> EntityMap<K, V>
///
/// All keys are permitted. Untouched entries have the default value.
impl<K, V> Index<K> for EntityMap<K, V>
where K: EntityRef,
V: Clone
where
K: EntityRef,
V: Clone,
{
type Output = V;
@@ -82,8 +86,9 @@ impl<K, V> Index<K> for EntityMap<K, V>
///
/// The map grows as needed to accommodate new keys.
impl<K, V> IndexMut<K> for EntityMap<K, V>
where K: EntityRef,
V: Clone
where
K: EntityRef,
V: Clone,
{
fn index_mut(&mut self, k: K) -> &mut V {
let i = k.index();

View File

@@ -14,14 +14,16 @@ use std::ops::{Index, IndexMut};
/// conflicting references will be created. Using unknown keys for indexing will cause a panic.
#[derive(Debug, Clone)]
pub struct PrimaryMap<K, V>
where K: EntityRef
where
K: EntityRef,
{
elems: Vec<V>,
unused: PhantomData<K>,
}
impl<K, V> PrimaryMap<K, V>
where K: EntityRef
where
K: EntityRef,
{
/// Create a new empty map.
pub fn new() -> Self {
@@ -77,7 +79,8 @@ impl<K, V> PrimaryMap<K, V>
/// Immutable indexing into an `PrimaryMap`.
/// The indexed value must be in the map.
impl<K, V> Index<K> for PrimaryMap<K, V>
where K: EntityRef
where
K: EntityRef,
{
type Output = V;
@@ -88,7 +91,8 @@ impl<K, V> Index<K> for PrimaryMap<K, V>
/// Mutable indexing into an `PrimaryMap`.
impl<K, V> IndexMut<K> for PrimaryMap<K, V>
where K: EntityRef
where
K: EntityRef,
{
fn index_mut(&mut self, k: K) -> &mut V {
&mut self.elems[k.index()]

View File

@@ -51,16 +51,18 @@ pub trait SparseMapValue<K> {
/// - `SparseMap` requires the values to implement `SparseMapValue<K>` which means that they must
/// contain their own key.
pub struct SparseMap<K, V>
where K: EntityRef,
V: SparseMapValue<K>
where
K: EntityRef,
V: SparseMapValue<K>,
{
sparse: EntityMap<K, u32>,
dense: Vec<V>,
}
impl<K, V> SparseMap<K, V>
where K: EntityRef,
V: SparseMapValue<K>
where
K: EntityRef,
V: SparseMapValue<K>,
{
/// Create a new empty mapping.
pub fn new() -> Self {
@@ -191,8 +193,9 @@ impl<K, V> SparseMap<K, V>
/// Iterating over the elements of a set.
impl<'a, K, V> IntoIterator for &'a SparseMap<K, V>
where K: EntityRef,
V: SparseMapValue<K>
where
K: EntityRef,
V: SparseMapValue<K>,
{
type Item = &'a V;
type IntoIter = slice::Iter<'a, V>;
@@ -204,7 +207,8 @@ impl<'a, K, V> IntoIterator for &'a SparseMap<K, V>
/// Any `EntityRef` can be used as a sparse map value representing itself.
impl<T> SparseMapValue<T> for T
where T: EntityRef
where
T: EntityRef,
{
fn key(&self) -> T {
*self
@@ -290,8 +294,10 @@ mod tests {
assert_eq!(map.insert(Obj(i0, "baz")), None);
// Iteration order = insertion order when nothing has been removed yet.
assert_eq!(map.values().map(|obj| obj.1).collect::<Vec<_>>(),
["foo", "bar", "baz"]);
assert_eq!(
map.values().map(|obj| obj.1).collect::<Vec<_>>(),
["foo", "bar", "baz"]
);
assert_eq!(map.len(), 3);
assert_eq!(map.get(i0), Some(&Obj(i0, "baz")));