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 12 pull requests #40403

Closed
wants to merge 31 commits into from
Closed
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
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
9b31784
save-analysis: only index path references once
nrc Mar 8, 2017
0aceb99
save-analysis: index extern blocks
nrc Mar 8, 2017
c4275c2
rustc_trans: don't emit ZST allocas that are only assigned to.
eddyb Mar 8, 2017
df60044
rustc_trans: avoid a separate entry BB if START_BLOCK has no backedges.
eddyb Mar 8, 2017
2719b84
Give spans to individual path segments in AST
petrochenkov Mar 8, 2017
7cfe20c
resolve: Use path segment spans in smart_resolve_path
petrochenkov Mar 8, 2017
79a7ee8
fix UB in repr(packed) tests
TimNN Mar 8, 2017
c51a39d
Removed RustFMT changes
jdhorwitz Mar 8, 2017
edf5dc6
Box docs: no allocation is done for ZSTs.
clarfonthey Mar 9, 2017
14e9313
emit !align attributes on stores of operand pairs
arielb1 Mar 9, 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
26faee0
Rollup merge of #40092 - sinkuu:fix_suggestion_index, r=pnkfelix
Mar 9, 2017
270cde9
Rollup merge of #40146 - bjorn3:few-infer-changes, r=pnkfelix
Mar 9, 2017
55de547
Rollup merge of #40278 - GuillaumeGomez:css-cleanup, r=frewsxcv
Mar 9, 2017
cb1d4c9
Rollup merge of #40312 - jdhorwitz:papercut, r=steveklabnik
Mar 9, 2017
d042c51
Rollup merge of #40348 - nrc:save-extern-fn, r=eddyb
Mar 9, 2017
72fc6d4
Rollup merge of #40367 - eddyb:naked-cruft, r=nagisa
Mar 9, 2017
a1b148e
Rollup merge of #40369 - petrochenkov:segspan, r=eddyb
Mar 9, 2017
7e710c5
Rollup merge of #40372 - nagisa:never-drop, r=eddyb
Mar 9, 2017
b933fc6
Rollup merge of #40373 - TimNN:test-ub-packed, r=arielb1
Mar 9, 2017
e63f4a6
Rollup merge of #40379 - clarcharr:box_docs, r=brson
Mar 9, 2017
0f9c735
Rollup merge of #40385 - arielb1:packed-again, r=eddyb
Mar 9, 2017
cf2165a
Rollup merge of #40389 - F001:placementVecDeque, r=nagisa
Mar 9, 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
2 changes: 2 additions & 0 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ impl<T: ?Sized> Drop for IntermediateBox<T> {
impl<T> Box<T> {
/// Allocates memory on the heap and then places `x` into it.
///
/// This doesn't actually allocate if `T` is zero-sized.
///
/// # Examples
///
/// ```
Expand Down
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]);
}
4 changes: 3 additions & 1 deletion src/librustc/infer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ course, it depends on the program.

The main case which fails today that I would like to support is:

```text
```rust
fn foo<T>(x: T, y: T) { ... }

fn bar() {
Expand All @@ -168,6 +168,8 @@ because the type variable `T` is merged with the type variable for
`X`, and thus inherits its UB/LB of `@mut int`. This leaves no
flexibility for `T` to later adjust to accommodate `@int`.

Note: `@` and `@mut` are replaced with `Rc<T>` and `Rc<RefCell<T>>` in current Rust.

### What to do when not all bounds are present

In the prior discussion we assumed that A.ub was not top and B.lb was
Expand Down
Loading