Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8a64cf7
Fix suggestion span error with a line containing non-ASCIIs
sinkuu Feb 25, 2017
53d3c89
Dont bug! on user error
bjorn3 Feb 28, 2017
54a1c8b
Fix indentation in region infer docs
bjorn3 Feb 28, 2017
2a40918
Syntax highlighting in region infer docs
bjorn3 Feb 28, 2017
be49671
Improve a bit more
bjorn3 Feb 28, 2017
90e94d9
Syntax highlight and note about current rust in infer docs
bjorn3 Feb 28, 2017
234753a
Fix missing backtick typo
Nashenas88 Mar 8, 2017
3198904
Disallow subtyping between T and U in T: Unsize<U>.
eddyb Mar 7, 2017
79a7ee8
fix UB in repr(packed) tests
TimNN Mar 8, 2017
74bc7fd
Overhaul coercion to use the lazy InferOk obligations passing.
eddyb Mar 8, 2017
4eeede3
fix emscripten test detection
TimNN Mar 4, 2017
da6e7c8
Distinguish the ways `CStr::from_bytes_with_nul` can fail
tbu- Mar 9, 2017
57c989c
Fix botched member variable rename
shepmaster Mar 4, 2017
3e2390f
Restore creating the channel-rust-$channel-date.txt files
shepmaster Mar 3, 2017
8062cfb
Implement placement-in protocol for and `VecDeque`
Mar 9, 2017
84d1f6a
Do not bother creating StorageLive for TyNever
nagisa Mar 8, 2017
4078b25
Clean up rustdoc css
GuillaumeGomez Mar 9, 2017
cfb41ae
Use subtyping on the target of unsizing coercions.
eddyb Mar 9, 2017
b95b5db
update gdbr tests
TimNN Mar 9, 2017
7f19f1f
fix #40294 obligation cause.body_id is not always a NodeExpr
Mar 9, 2017
889337d
move related tests to type-check ui test directory
Mar 10, 2017
a8cacd3
travis: Attempt to debug sccache failures
alexcrichton Mar 7, 2017
7688222
Don't put Cargo into the rustc workspace
alexcrichton Mar 6, 2017
ac2bc7c
Point to enclosing block/fn on nested unsafe
estebank Jan 20, 2017
a07c9a2
Export attributes in save-analysis data
jonasbb Feb 14, 2017
203d227
Store attributes as strings
jonasbb Feb 23, 2017
db35604
Move remove_docs_from_attrs into lowering step
jonasbb Mar 2, 2017
2b5f1b2
rustbuild: Build documentation for `proc_macro`
alexcrichton Mar 1, 2017
4ca9c97
Remove ability for plugins to register a MIR pass
nagisa Mar 3, 2017
7b0dd7b
Fix incorrect span label formatting
estebank Mar 6, 2017
993eae1
rustc: Support auto-retry linking on a segfault
alexcrichton Mar 10, 2017
83814fd
OsString::shrink_to_fit.
Mar 10, 2017
384ee48
Clarify docs in `VecDeque::resize`
DirkyJerky Mar 10, 2017
038ec50
emit !align attributes on stores of operand pairs
arielb1 Mar 9, 2017
d722bc8
Rollup merge of #39202 - estebank:nested-unsafe, r=jonathandturner
Mar 10, 2017
70bb61b
Rollup merge of #39820 - jonasbb:export-attributes, r=nrc
Mar 10, 2017
2866703
Rollup merge of #40092 - sinkuu:fix_suggestion_index, r=pnkfelix
Mar 10, 2017
fed96da
Rollup merge of #40146 - bjorn3:few-infer-changes, r=pnkfelix
Mar 10, 2017
a6b900d
Rollup merge of #40199 - alexcrichton:doc-proc-macro, r=brson
Mar 10, 2017
00f2281
Rollup merge of #40225 - shepmaster:restore-build-date-file, r=alexcr…
Mar 10, 2017
8a59355
Rollup merge of #40239 - nagisa:death-to-plugins, r=nikomatsakis
Mar 10, 2017
8f3c1d2
Rollup merge of #40259 - TimNN:fix-emscripten-tests, r=alexcrichton
Mar 10, 2017
57c5b54
Rollup merge of #40278 - GuillaumeGomez:css-cleanup, r=frewsxcv
Mar 10, 2017
57a9863
Rollup merge of #40287 - estebank:label-overlap, r=nrc
Mar 10, 2017
699ec59
Rollup merge of #40297 - alexcrichton:fix-submodules, r=brson
Mar 10, 2017
34261e2
Rollup merge of #40319 - eddyb:it's-"unsize"-not-"unsound", r=nikomat…
Mar 10, 2017
17f06df
Rollup merge of #40324 - alexcrichton:sccache-errors, r=aturon
Mar 10, 2017
bdbb229
Rollup merge of #40345 - Nashenas88:patch-1, r=estebank
Mar 10, 2017
bb8c054
Rollup merge of #40372 - nagisa:never-drop, r=eddyb
Mar 10, 2017
f9ed95a
Rollup merge of #40373 - TimNN:test-ub-packed, r=arielb1
Mar 10, 2017
41bd4ad
Rollup merge of #40385 - arielb1:packed-again, r=eddyb
Mar 10, 2017
f1cd2f2
Rollup merge of #40386 - tbu-:pr_display_frombyteswithnulerror, r=ale…
Mar 10, 2017
1b81660
Rollup merge of #40389 - F001:placementVecDeque, r=nagisa
Mar 10, 2017
af60d7c
Rollup merge of #40400 - TimNN:gdbr-updates, r=alexcrichton
Mar 10, 2017
7983978
Rollup merge of #40404 - cengizIO:master, r=nikomatsakis
Mar 10, 2017
1ba54a7
Rollup merge of #40410 - clarcharr:os_string_shrink_to_fit, r=alexcri…
Mar 10, 2017
4e60835
Rollup merge of #40422 - alexcrichton:retry-linker-segfault, r=arielb1
Mar 10, 2017
10e12ea
Rollup merge of #40423 - DirkyJerky:patch-2, r=BurntSushi
Mar 10, 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
185 changes: 160 additions & 25 deletions src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use core::cmp::Ordering;
use core::fmt;
use core::iter::{repeat, FromIterator, FusedIterator};
use core::mem;
use core::ops::{Index, IndexMut};
use core::ops::{Index, IndexMut, Place, Placer, InPlace};
use core::ptr;
use core::ptr::Shared;
use core::slice;
Expand Down Expand Up @@ -1087,14 +1087,7 @@ impl<T> VecDeque<T> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_front(&mut self, value: T) {
if self.is_full() {
let old_cap = self.cap();
self.buf.double();
unsafe {
self.handle_cap_increase(old_cap);
}
debug_assert!(!self.is_full());
}
self.grow_if_necessary();

self.tail = self.wrap_sub(self.tail, 1);
let tail = self.tail;
Expand All @@ -1117,14 +1110,7 @@ impl<T> VecDeque<T> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_back(&mut self, value: T) {
if self.is_full() {
let old_cap = self.cap();
self.buf.double();
unsafe {
self.handle_cap_increase(old_cap);
}
debug_assert!(!self.is_full());
}
self.grow_if_necessary();

let head = self.head;
self.head = self.wrap_add(self.head, 1);
Expand Down Expand Up @@ -1257,14 +1243,7 @@ impl<T> VecDeque<T> {
#[stable(feature = "deque_extras_15", since = "1.5.0")]
pub fn insert(&mut self, index: usize, value: T) {
assert!(index <= self.len(), "index out of bounds");
if self.is_full() {
let old_cap = self.cap();
self.buf.double();
unsafe {
self.handle_cap_increase(old_cap);
}
debug_assert!(!self.is_full());
}
self.grow_if_necessary();

// Move the least number of elements in the ring buffer and insert
// the given object
Expand Down Expand Up @@ -1762,6 +1741,69 @@ impl<T> VecDeque<T> {
self.truncate(len - del);
}
}

// This may panic or abort
#[inline]
fn grow_if_necessary(&mut self) {
if self.is_full() {
let old_cap = self.cap();
self.buf.double();
unsafe {
self.handle_cap_increase(old_cap);
}
debug_assert!(!self.is_full());
}
}

/// Returns a place for insertion at the back of the `VecDeque`.
///
/// Using this method with placement syntax is equivalent to [`push_back`](#method.push_back),
/// but may be more efficient.
///
/// # Examples
///
/// ```
/// #![feature(collection_placement)]
/// #![feature(placement_in_syntax)]
///
/// use std::collections::VecDeque;
///
/// let mut buf = VecDeque::new();
/// buf.place_back() <- 3;
/// buf.place_back() <- 4;
/// assert_eq!(&buf, &[3, 4]);
/// ```
#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
pub fn place_back(&mut self) -> PlaceBack<T> {
PlaceBack { vec_deque: self }
}

/// Returns a place for insertion at the front of the `VecDeque`.
///
/// Using this method with placement syntax is equivalent to [`push_front`](#method.push_front),
/// but may be more efficient.
///
/// # Examples
///
/// ```
/// #![feature(collection_placement)]
/// #![feature(placement_in_syntax)]
///
/// use std::collections::VecDeque;
///
/// let mut buf = VecDeque::new();
/// buf.place_front() <- 3;
/// buf.place_front() <- 4;
/// assert_eq!(&buf, &[4, 3]);
/// ```
#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
pub fn place_front(&mut self) -> PlaceFront<T> {
PlaceFront { vec_deque: self }
}
}

impl<T: Clone> VecDeque<T> {
Expand Down Expand Up @@ -2442,6 +2484,98 @@ impl<T> From<VecDeque<T>> for Vec<T> {
}
}

/// A place for insertion at the back of a `VecDeque`.
///
/// See [`VecDeque::place_back`](struct.VecDeque.html#method.place_back) for details.
#[must_use = "places do nothing unless written to with `<-` syntax"]
#[unstable(feature = "collection_placement",
reason = "struct name and placement protocol are subject to change",
issue = "30172")]
#[derive(Debug)]
pub struct PlaceBack<'a, T: 'a> {
vec_deque: &'a mut VecDeque<T>,
}

#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
impl<'a, T> Placer<T> for PlaceBack<'a, T> {
type Place = PlaceBack<'a, T>;

fn make_place(self) -> Self {
self.vec_deque.grow_if_necessary();
self
}
}

#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
impl<'a, T> Place<T> for PlaceBack<'a, T> {
fn pointer(&mut self) -> *mut T {
unsafe { self.vec_deque.ptr().offset(self.vec_deque.head as isize) }
}
}

#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
impl<'a, T> InPlace<T> for PlaceBack<'a, T> {
type Owner = &'a mut T;

unsafe fn finalize(mut self) -> &'a mut T {
let head = self.vec_deque.head;
self.vec_deque.head = self.vec_deque.wrap_add(head, 1);
&mut *(self.vec_deque.ptr().offset(head as isize))
}
}

/// A place for insertion at the front of a `VecDeque`.
///
/// See [`VecDeque::place_front`](struct.VecDeque.html#method.place_front) for details.
#[must_use = "places do nothing unless written to with `<-` syntax"]
#[unstable(feature = "collection_placement",
reason = "struct name and placement protocol are subject to change",
issue = "30172")]
#[derive(Debug)]
pub struct PlaceFront<'a, T: 'a> {
vec_deque: &'a mut VecDeque<T>,
}

#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
impl<'a, T> Placer<T> for PlaceFront<'a, T> {
type Place = PlaceFront<'a, T>;

fn make_place(self) -> Self {
self.vec_deque.grow_if_necessary();
self
}
}

#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
impl<'a, T> Place<T> for PlaceFront<'a, T> {
fn pointer(&mut self) -> *mut T {
let tail = self.vec_deque.wrap_sub(self.vec_deque.tail, 1);
unsafe { self.vec_deque.ptr().offset(tail as isize) }
}
}

#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
impl<'a, T> InPlace<T> for PlaceFront<'a, T> {
type Owner = &'a mut T;

unsafe fn finalize(mut self) -> &'a mut T {
self.vec_deque.tail = self.vec_deque.wrap_sub(self.vec_deque.tail, 1);
&mut *(self.vec_deque.ptr().offset(self.vec_deque.tail as isize))
}
}

#[cfg(test)]
mod tests {
use test;
Expand Down Expand Up @@ -2797,4 +2931,5 @@ mod tests {
}
}
}

}
1 change: 1 addition & 0 deletions src/libcollectionstest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
extern crate collections;
extern crate test;
extern crate std_unicode;
extern crate core;

use std::hash::{Hash, Hasher};
use std::collections::hash_map::DefaultHasher;
Expand Down
24 changes: 23 additions & 1 deletion src/libcollectionstest/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use std::collections::VecDeque;
use std::fmt::Debug;
use std::collections::vec_deque::Drain;
use std::collections::vec_deque::{Drain};

use self::Taggy::*;
use self::Taggypar::*;
Expand Down Expand Up @@ -1000,3 +1000,25 @@ fn test_is_empty() {
assert!(v.iter_mut().is_empty());
assert!(v.into_iter().is_empty());
}

#[test]
fn test_placement_in() {
let mut buf: VecDeque<isize> = VecDeque::new();
buf.place_back() <- 1;
buf.place_back() <- 2;
assert_eq!(buf, [1,2]);

buf.place_front() <- 3;
buf.place_front() <- 4;
assert_eq!(buf, [4,3,1,2]);

{
let ptr_head = buf.place_front() <- 5;
assert_eq!(*ptr_head, 5);
}
{
let ptr_tail = buf.place_back() <- 6;
assert_eq!(*ptr_tail, 6);
}
assert_eq!(buf, [5,4,3,1,2,6]);
}