Skip to content

Commit c1acd50

Browse files
committed
---
yaml --- r: 225357 b: refs/heads/stable c: 25fc917 h: refs/heads/master i: 225355: 161391c v: v3
1 parent 8cadcb8 commit c1acd50

File tree

6 files changed

+331
-35
lines changed

6 files changed

+331
-35
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ refs/heads/tmp: e5d90d98402475b6e154ce216f9efcb80da1a747
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: 1fe32ca12c51afcd761d9962f51a74ff0d07a591
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: d0afa6ede3ce5fd6b35c8f1fd5fc89336ec2dc96
32+
refs/heads/stable: 25fc917c65f7c51fafdab0f023772171f84c7f0a
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b

branches/stable/CONTRIBUTING.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ feature. We use the 'fork and pull' model described there.
8484
Please make pull requests against the `master` branch.
8585

8686
All pull requests are reviewed by another person. We have a bot,
87-
@rust-highfive, that will automatically assign a random person to review your request.
87+
@rust-highfive, that will automatically assign a random person to review your
88+
request.
8889

8990
If you want to request that a specific person reviews your pull request,
9091
you can add an `r?` to the message. For example, Steve usually reviews
@@ -124,6 +125,10 @@ To save @bors some work, and to get small changes through more quickly, when
124125
the other rollup-eligible patches too, and they'll get tested and merged at
125126
the same time.
126127

128+
To find documentation-related issues, sort by the [A-docs label][adocs].
129+
130+
[adocs]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AA-docs
131+
127132
## Issue Triage
128133

129134
Sometimes, an issue will stay open, even though the bug has been fixed. And
@@ -132,8 +137,40 @@ meantime.
132137

133138
It can be helpful to go through older bug reports and make sure that they are
134139
still valid. Load up an older issue, double check that it's still true, and
135-
leave a comment letting us know if it is or is not. The [least recently updated sort][lru] is good for finding issues like this.
140+
leave a comment letting us know if it is or is not. The [least recently
141+
updated sort][lru] is good for finding issues like this.
142+
143+
Contributors with sufficient permissions on the Rust repo can help by adding
144+
labels to triage issues:
145+
146+
* Yellow, **A**-prefixed labels state which **area** of the project an issue
147+
relates to.
148+
149+
* Magenta, **B**-prefixed labels identify bugs which **belong** elsewhere.
150+
151+
* Green, **E**-prefixed labels explain the level of **experience** necessary
152+
to fix the issue.
153+
154+
* Red, **I**-prefixed labels indicate the **importance** of the issue. The
155+
[I-nominated][inom] label indicates that an issue has been nominated for
156+
prioritizing at the next triage meeting.
157+
158+
* Orange, **P**-prefixed labels indicate a bug's **priority**. These labels
159+
are only assigned during triage meetings, and replace the [I-nominated][inom]
160+
label.
161+
162+
* Blue, **T**-prefixed bugs denote which **team** the issue belongs to.
163+
164+
* Dark blue, **beta-** labels track changes which need to be backported into
165+
the beta branches.
166+
167+
* The purple **metabug** label marks lists of bugs collected by other
168+
categories.
169+
170+
If you're looking for somewhere to start, check out the [E-easy][eeasy] tag.
136171

172+
[inom]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AI-nominated
173+
[eeasy]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy
137174
[lru]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc
138175

139176
## Out-of-tree Contributions

branches/stable/src/libcollections/binary_heap.rs

Lines changed: 88 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
use core::prelude::*;
154154

155155
use core::iter::{FromIterator};
156-
use core::mem::{zeroed, replace, swap};
156+
use core::mem::swap;
157157
use core::ptr;
158158

159159
use slice;
@@ -484,46 +484,42 @@ impl<T: Ord> BinaryHeap<T> {
484484

485485
// The implementations of sift_up and sift_down use unsafe blocks in
486486
// order to move an element out of the vector (leaving behind a
487-
// zeroed element), shift along the others and move it back into the
488-
// vector over the junk element. This reduces the constant factor
489-
// compared to using swaps, which involves twice as many moves.
490-
fn sift_up(&mut self, start: usize, mut pos: usize) {
487+
// hole), shift along the others and move the removed element back into the
488+
// vector at the final location of the hole.
489+
// The `Hole` type is used to represent this, and make sure
490+
// the hole is filled back at the end of its scope, even on panic.
491+
// Using a hole reduces the constant factor compared to using swaps,
492+
// which involves twice as many moves.
493+
fn sift_up(&mut self, start: usize, pos: usize) {
491494
unsafe {
492-
let new = replace(&mut self.data[pos], zeroed());
495+
// Take out the value at `pos` and create a hole.
496+
let mut hole = Hole::new(&mut self.data, pos);
493497

494-
while pos > start {
495-
let parent = (pos - 1) >> 1;
496-
497-
if new <= self.data[parent] { break; }
498-
499-
let x = replace(&mut self.data[parent], zeroed());
500-
ptr::write(&mut self.data[pos], x);
501-
pos = parent;
498+
while hole.pos() > start {
499+
let parent = (hole.pos() - 1) / 2;
500+
if hole.removed() <= hole.get(parent) { break }
501+
hole.move_to(parent);
502502
}
503-
ptr::write(&mut self.data[pos], new);
504503
}
505504
}
506505

507506
fn sift_down_range(&mut self, mut pos: usize, end: usize) {
507+
let start = pos;
508508
unsafe {
509-
let start = pos;
510-
let new = replace(&mut self.data[pos], zeroed());
511-
509+
let mut hole = Hole::new(&mut self.data, pos);
512510
let mut child = 2 * pos + 1;
513511
while child < end {
514512
let right = child + 1;
515-
if right < end && !(self.data[child] > self.data[right]) {
513+
if right < end && !(hole.get(child) > hole.get(right)) {
516514
child = right;
517515
}
518-
let x = replace(&mut self.data[child], zeroed());
519-
ptr::write(&mut self.data[pos], x);
520-
pos = child;
521-
child = 2 * pos + 1;
516+
hole.move_to(child);
517+
child = 2 * hole.pos() + 1;
522518
}
523519

524-
ptr::write(&mut self.data[pos], new);
525-
self.sift_up(start, pos);
520+
pos = hole.pos;
526521
}
522+
self.sift_up(start, pos);
527523
}
528524

529525
fn sift_down(&mut self, pos: usize) {
@@ -554,6 +550,73 @@ impl<T: Ord> BinaryHeap<T> {
554550
pub fn clear(&mut self) { self.drain(); }
555551
}
556552

553+
/// Hole represents a hole in a slice i.e. an index without valid value
554+
/// (because it was moved from or duplicated).
555+
/// In drop, `Hole` will restore the slice by filling the hole
556+
/// position with the value that was originally removed.
557+
struct Hole<'a, T: 'a> {
558+
data: &'a mut [T],
559+
/// `elt` is always `Some` from new until drop.
560+
elt: Option<T>,
561+
pos: usize,
562+
}
563+
564+
impl<'a, T> Hole<'a, T> {
565+
/// Create a new Hole at index `pos`.
566+
fn new(data: &'a mut [T], pos: usize) -> Self {
567+
unsafe {
568+
let elt = ptr::read(&data[pos]);
569+
Hole {
570+
data: data,
571+
elt: Some(elt),
572+
pos: pos,
573+
}
574+
}
575+
}
576+
577+
#[inline(always)]
578+
fn pos(&self) -> usize { self.pos }
579+
580+
/// Return a reference to the element removed
581+
#[inline(always)]
582+
fn removed(&self) -> &T {
583+
self.elt.as_ref().unwrap()
584+
}
585+
586+
/// Return a reference to the element at `index`.
587+
///
588+
/// Panics if the index is out of bounds.
589+
///
590+
/// Unsafe because index must not equal pos.
591+
#[inline(always)]
592+
unsafe fn get(&self, index: usize) -> &T {
593+
debug_assert!(index != self.pos);
594+
&self.data[index]
595+
}
596+
597+
/// Move hole to new location
598+
///
599+
/// Unsafe because index must not equal pos.
600+
#[inline(always)]
601+
unsafe fn move_to(&mut self, index: usize) {
602+
debug_assert!(index != self.pos);
603+
let index_ptr: *const _ = &self.data[index];
604+
let hole_ptr = &mut self.data[self.pos];
605+
ptr::copy_nonoverlapping(index_ptr, hole_ptr, 1);
606+
self.pos = index;
607+
}
608+
}
609+
610+
impl<'a, T> Drop for Hole<'a, T> {
611+
fn drop(&mut self) {
612+
// fill the hole again
613+
unsafe {
614+
let pos = self.pos;
615+
ptr::write(&mut self.data[pos], self.elt.take().unwrap());
616+
}
617+
}
618+
}
619+
557620
/// `BinaryHeap` iterator.
558621
#[stable(feature = "rust1", since = "1.0.0")]
559622
pub struct Iter <'a, T: 'a> {

branches/stable/src/libcore/cell.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
#![stable(feature = "rust1", since = "1.0.0")]
144144

145145
use clone::Clone;
146-
use cmp::PartialEq;
146+
use cmp::{PartialEq, Eq};
147147
use default::Default;
148148
use marker::{Copy, Send, Sync, Sized};
149149
use ops::{Deref, DerefMut, Drop, FnOnce};
@@ -263,6 +263,9 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
263263
}
264264
}
265265

266+
#[stable(feature = "cell_eq", since = "1.2.0")]
267+
impl<T:Eq + Copy> Eq for Cell<T> {}
268+
266269
/// A mutable memory location with dynamically checked borrow rules
267270
///
268271
/// See the [module-level documentation](index.html) for more.
@@ -273,7 +276,7 @@ pub struct RefCell<T: ?Sized> {
273276
}
274277

275278
/// An enumeration of values returned from the `state` method on a `RefCell<T>`.
276-
#[derive(Copy, Clone, PartialEq, Debug)]
279+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
277280
#[unstable(feature = "std_misc")]
278281
pub enum BorrowState {
279282
/// The cell is currently being read, there is at least one active `borrow`.
@@ -479,6 +482,9 @@ impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
479482
}
480483
}
481484

485+
#[stable(feature = "cell_eq", since = "1.2.0")]
486+
impl<T: ?Sized + Eq> Eq for RefCell<T> {}
487+
482488
struct BorrowRef<'b> {
483489
_borrow: &'b Cell<BorrowFlag>,
484490
}

branches/stable/src/libstd/io/error.rs

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ impl Error {
129129
///
130130
/// This function is used to generically create I/O errors which do not
131131
/// originate from the OS itself. The `error` argument is an arbitrary
132-
/// payload which will be contained in this `Error`. Accessors as well as
133-
/// downcasting will soon be added to this type as well to access the custom
134-
/// information.
132+
/// payload which will be contained in this `Error`.
135133
///
136134
/// # Examples
137135
///
@@ -174,8 +172,9 @@ impl Error {
174172

175173
/// Returns the OS error that this error represents (if any).
176174
///
177-
/// If this `Error` was constructed via `last_os_error` then this function
178-
/// will return `Some`, otherwise it will return `None`.
175+
/// If this `Error` was constructed via `last_os_error` or
176+
/// `from_raw_os_error`, then this function will return `Some`, otherwise
177+
/// it will return `None`.
179178
#[stable(feature = "rust1", since = "1.0.0")]
180179
pub fn raw_os_error(&self) -> Option<i32> {
181180
match self.repr {
@@ -184,6 +183,46 @@ impl Error {
184183
}
185184
}
186185

186+
/// Returns a reference to the inner error wrapped by this error (if any).
187+
///
188+
/// If this `Error` was constructed via `new` then this function will
189+
/// return `Some`, otherwise it will return `None`.
190+
#[unstable(feature = "io_error_inner",
191+
reason = "recently added and requires UFCS to downcast")]
192+
pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> {
193+
match self.repr {
194+
Repr::Os(..) => None,
195+
Repr::Custom(ref c) => Some(&*c.error),
196+
}
197+
}
198+
199+
/// Returns a mutable reference to the inner error wrapped by this error
200+
/// (if any).
201+
///
202+
/// If this `Error` was constructed via `new` then this function will
203+
/// return `Some`, otherwise it will return `None`.
204+
#[unstable(feature = "io_error_inner",
205+
reason = "recently added and requires UFCS to downcast")]
206+
pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> {
207+
match self.repr {
208+
Repr::Os(..) => None,
209+
Repr::Custom(ref mut c) => Some(&mut *c.error),
210+
}
211+
}
212+
213+
/// Consumes the `Error`, returning its inner error (if any).
214+
///
215+
/// If this `Error` was constructed via `new` then this function will
216+
/// return `Some`, otherwise it will return `None`.
217+
#[unstable(feature = "io_error_inner",
218+
reason = "recently added and requires UFCS to downcast")]
219+
pub fn into_inner(self) -> Option<Box<error::Error+Send+Sync>> {
220+
match self.repr {
221+
Repr::Os(..) => None,
222+
Repr::Custom(c) => Some(c.error)
223+
}
224+
}
225+
187226
/// Returns the corresponding `ErrorKind` for this error.
188227
#[stable(feature = "rust1", since = "1.0.0")]
189228
pub fn kind(&self) -> ErrorKind {
@@ -215,9 +254,52 @@ impl error::Error for Error {
215254
Repr::Custom(ref c) => c.error.description(),
216255
}
217256
}
257+
258+
fn cause(&self) -> Option<&error::Error> {
259+
match self.repr {
260+
Repr::Os(..) => None,
261+
Repr::Custom(ref c) => c.error.cause(),
262+
}
263+
}
218264
}
219265

220266
fn _assert_error_is_sync_send() {
221267
fn _is_sync_send<T: Sync+Send>() {}
222268
_is_sync_send::<Error>();
223269
}
270+
271+
#[cfg(test)]
272+
mod test {
273+
use prelude::v1::*;
274+
use super::{Error, ErrorKind};
275+
use error;
276+
use error::Error as error_Error;
277+
use fmt;
278+
279+
#[test]
280+
fn test_downcasting() {
281+
#[derive(Debug)]
282+
struct TestError;
283+
284+
impl fmt::Display for TestError {
285+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
286+
Ok(())
287+
}
288+
}
289+
290+
impl error::Error for TestError {
291+
fn description(&self) -> &str {
292+
"asdf"
293+
}
294+
}
295+
296+
// we have to call all of these UFCS style right now since method
297+
// resolution won't implicitly drop the Send+Sync bounds
298+
let mut err = Error::new(ErrorKind::Other, TestError);
299+
assert!(error::Error::is::<TestError>(err.get_ref().unwrap()));
300+
assert_eq!("asdf", err.get_ref().unwrap().description());
301+
assert!(error::Error::is::<TestError>(err.get_mut().unwrap()));
302+
let extracted = err.into_inner().unwrap();
303+
error::Error::downcast::<TestError>(extracted).unwrap();
304+
}
305+
}

0 commit comments

Comments
 (0)