Skip to content

Rollup of 6 pull requests #43603

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 23 commits into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
81eea9e
Thread through the original error when opening archives
alexcrichton Jul 21, 2017
236b748
Add simple docs example for struct Cell
Jul 23, 2017
bb65d32
add prose
Jul 24, 2017
3c53595
review fixes
Jul 24, 2017
8286075
ci fix?
Jul 24, 2017
beb072a
empty lines
Jul 24, 2017
d429a4e
s/immutable/my_struct
Jul 24, 2017
dd371a2
rustc: Inline bitwise modification operators
alexcrichton Aug 1, 2017
bdb53e5
Fix the Solaris pthread_t raw type in std to match what's in libc
Aug 1, 2017
1b831cf
Derive `Hash` on `AssociatedKind`.
ibabushkin Aug 1, 2017
8810627
Add doc example for HashSet::hasher.
frewsxcv Aug 1, 2017
9e19260
Show that the capacity changed in HashSet::reserve doc example.
frewsxcv Aug 1, 2017
070eb3c
Indicate HashSet is code-like in docs.
frewsxcv Aug 1, 2017
9e2b0c6
Remove unnecessary 'mut' bindings.
frewsxcv Aug 1, 2017
1599fad
Show the capacity in HashSet::with_capacity doc example.
frewsxcv Aug 1, 2017
34c1bfb
Remove unnecessary clones in doc examples.
frewsxcv Aug 1, 2017
d9df296
Add doc example for HashSet::drain.
frewsxcv Aug 1, 2017
ab3fb95
Rollup merge of #43389 - alexcrichton:thread-error, r=michaelwoerister
frewsxcv Aug 2, 2017
2d9893f
Rollup merge of #43423 - xliiv:cell-example, r=steveklabnik
frewsxcv Aug 2, 2017
c96ce40
Rollup merge of #43581 - alexcrichton:inline-more, r=michaelwoerister
frewsxcv Aug 2, 2017
08c0bbd
Rollup merge of #43585 - frewsxcv:frewsxcv-hashset-docs, r=steveklabn…
frewsxcv Aug 2, 2017
1c91c78
Rollup merge of #43597 - dhduvall:master, r=alexcrichton
frewsxcv Aug 2, 2017
368f1a8
Rollup merge of #43598 - ibabushkin:master, r=eddyb
frewsxcv Aug 2, 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
28 changes: 28 additions & 0 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,34 @@ use ptr;

/// A mutable memory location.
///
/// # Examples
///
/// Here you can see how using `Cell<T>` allows to use mutable field inside
/// immutable struct (which is also called 'interior mutability').
///
/// ```
/// use std::cell::Cell;
///
/// struct SomeStruct {
/// regular_field: u8,
/// special_field: Cell<u8>,
/// }
///
/// let my_struct = SomeStruct {
/// regular_field: 0,
/// special_field: Cell::new(1),
/// };
///
/// let new_value = 100;
///
/// // ERROR, because my_struct is immutable
/// // my_struct.regular_field = new_value;
///
/// // WORKS, although `my_struct` is immutable, field `special_field` is mutable because it is Cell
/// my_struct.special_field.set(new_value);
/// assert_eq!(my_struct.special_field.get(), new_value);
/// ```
///
/// See the [module-level documentation](index.html) for more.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Cell<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub struct AssociatedItem {
pub method_has_self_argument: bool,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug, RustcEncodable, RustcDecodable)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, RustcEncodable, RustcDecodable)]
pub enum AssociatedKind {
Const,
Method,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_data_structures/bitslice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ pub trait BitwiseOperator {

pub struct Union;
impl BitwiseOperator for Union {
#[inline]
fn join(&self, a: usize, b: usize) -> usize { a | b }
}
pub struct Subtract;
impl BitwiseOperator for Subtract {
#[inline]
fn join(&self, a: usize, b: usize) -> usize { a & !b }
}
6 changes: 3 additions & 3 deletions src/librustc_llvm/archive_ro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ impl ArchiveRO {
///
/// If this archive is used with a mutable method, then an error will be
/// raised.
pub fn open(dst: &Path) -> Option<ArchiveRO> {
pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
return unsafe {
let s = path2cstr(dst);
let ar = ::LLVMRustOpenArchive(s.as_ptr());
if ar.is_null() {
None
Err(::last_error().unwrap_or("failed to open archive".to_string()))
} else {
Some(ArchiveRO { ptr: ar })
Ok(ArchiveRO { ptr: ar })
}
};

Expand Down
7 changes: 3 additions & 4 deletions src/librustc_trans/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'a> ArchiveBuilder<'a> {
Some(ref src) => src,
None => return None,
};
self.src_archive = Some(ArchiveRO::open(src));
self.src_archive = Some(ArchiveRO::open(src).ok());
self.src_archive.as_ref().unwrap().as_ref()
}

Expand Down Expand Up @@ -186,9 +186,8 @@ impl<'a> ArchiveBuilder<'a> {
where F: FnMut(&str) -> bool + 'static
{
let archive = match ArchiveRO::open(archive) {
Some(ar) => ar,
None => return Err(io::Error::new(io::ErrorKind::Other,
"failed to open archive")),
Ok(ar) => ar,
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)),
};
self.additions.push(Addition::Archive {
archive: archive,
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_trans/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ impl MetadataLoader for LlvmMetadataLoader {
// just keeping the archive along while the metadata is in use.
let archive = ArchiveRO::open(filename)
.map(|ar| OwningRef::new(box ar))
.ok_or_else(|| {
debug!("llvm didn't like `{}`", filename.display());
format!("failed to read rlib metadata: '{}'", filename.display())
})?;
.map_err(|e| {
debug!("llvm didn't like `{}`: {}", filename.display(), e);
format!("failed to read rlib metadata in '{}': {}", filename.display(), e)
})?;
let buf: OwningRef<_, [u8]> = archive
.try_map(|ar| {
ar.iter()
.filter_map(|s| s.ok())
.find(|sect| sect.name() == Some(METADATA_FILENAME))
.map(|s| s.data())
.ok_or_else(|| {
debug!("didn't find '{}' in the archive", METADATA_FILENAME);
format!("failed to read rlib metadata: '{}'",
filename.display())
})
debug!("didn't find '{}' in the archive", METADATA_FILENAME);
format!("failed to read rlib metadata: '{}'",
filename.display())
})
})?;
Ok(buf.erase_owner())
}
Expand Down
57 changes: 43 additions & 14 deletions src/libstd/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ pub struct HashSet<T, S = RandomState> {
}

impl<T: Hash + Eq> HashSet<T, RandomState> {
/// Creates an empty HashSet.
/// Creates an empty `HashSet`.
///
/// # Examples
///
/// ```
/// use std::collections::HashSet;
/// let mut set: HashSet<i32> = HashSet::new();
/// let set: HashSet<i32> = HashSet::new();
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -146,7 +146,8 @@ impl<T: Hash + Eq> HashSet<T, RandomState> {
///
/// ```
/// use std::collections::HashSet;
/// let mut set: HashSet<i32> = HashSet::with_capacity(10);
/// let set: HashSet<i32> = HashSet::with_capacity(10);
/// assert!(set.capacity() >= 10);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -215,6 +216,17 @@ impl<T, S> HashSet<T, S>
/// Returns a reference to the set's [`BuildHasher`].
///
/// [`BuildHasher`]: ../../std/hash/trait.BuildHasher.html
///
/// # Examples
///
/// ```
/// use std::collections::HashSet;
/// use std::collections::hash_map::RandomState;
///
/// let hasher = RandomState::new();
/// let set: HashSet<i32> = HashSet::with_hasher(hasher);
/// let hasher: &RandomState = set.hasher();
/// ```
#[stable(feature = "hashmap_public_hasher", since = "1.9.0")]
pub fn hasher(&self) -> &S {
self.map.hasher()
Expand Down Expand Up @@ -249,6 +261,7 @@ impl<T, S> HashSet<T, S>
/// use std::collections::HashSet;
/// let mut set: HashSet<i32> = HashSet::new();
/// set.reserve(10);
/// assert!(set.capacity() >= 10);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn reserve(&mut self, additional: usize) {
Expand Down Expand Up @@ -312,13 +325,13 @@ impl<T, S> HashSet<T, S>
/// println!("{}", x); // Print 1
/// }
///
/// let diff: HashSet<_> = a.difference(&b).cloned().collect();
/// assert_eq!(diff, [1].iter().cloned().collect());
/// let diff: HashSet<_> = a.difference(&b).collect();
/// assert_eq!(diff, [1].iter().collect());
///
/// // Note that difference is not symmetric,
/// // and `b - a` means something else:
/// let diff: HashSet<_> = b.difference(&a).cloned().collect();
/// assert_eq!(diff, [4].iter().cloned().collect());
/// let diff: HashSet<_> = b.difference(&a).collect();
/// assert_eq!(diff, [4].iter().collect());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S> {
Expand All @@ -343,11 +356,11 @@ impl<T, S> HashSet<T, S>
/// println!("{}", x);
/// }
///
/// let diff1: HashSet<_> = a.symmetric_difference(&b).cloned().collect();
/// let diff2: HashSet<_> = b.symmetric_difference(&a).cloned().collect();
/// let diff1: HashSet<_> = a.symmetric_difference(&b).collect();
/// let diff2: HashSet<_> = b.symmetric_difference(&a).collect();
///
/// assert_eq!(diff1, diff2);
/// assert_eq!(diff1, [1, 4].iter().cloned().collect());
/// assert_eq!(diff1, [1, 4].iter().collect());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn symmetric_difference<'a>(&'a self,
Expand All @@ -371,8 +384,8 @@ impl<T, S> HashSet<T, S>
/// println!("{}", x);
/// }
///
/// let intersection: HashSet<_> = a.intersection(&b).cloned().collect();
/// assert_eq!(intersection, [2, 3].iter().cloned().collect());
/// let intersection: HashSet<_> = a.intersection(&b).collect();
/// assert_eq!(intersection, [2, 3].iter().collect());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S> {
Expand All @@ -397,8 +410,8 @@ impl<T, S> HashSet<T, S>
/// println!("{}", x);
/// }
///
/// let union: HashSet<_> = a.union(&b).cloned().collect();
/// assert_eq!(union, [1, 2, 3, 4].iter().cloned().collect());
/// let union: HashSet<_> = a.union(&b).collect();
/// assert_eq!(union, [1, 2, 3, 4].iter().collect());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> {
Expand Down Expand Up @@ -440,6 +453,22 @@ impl<T, S> HashSet<T, S>
}

/// Clears the set, returning all elements in an iterator.
///
/// # Examples
///
/// ```
/// use std::collections::HashSet;
///
/// let mut set: HashSet<_> = [1, 2, 3].iter().cloned().collect();
/// assert!(!set.is_empty());
///
/// // print 1, 2, 3 in an arbitrary order
/// for i in set.drain() {
/// println!("{}", i);
/// }
///
/// assert!(set.is_empty());
/// ```
#[inline]
#[stable(feature = "drain", since = "1.6.0")]
pub fn drain(&mut self) -> Drain<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/os/solaris/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use os::unix::raw::{uid_t, gid_t};
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;

#[stable(feature = "pthread_t", since = "1.8.0")]
pub type pthread_t = usize;
pub type pthread_t = u32;

#[repr(C)]
#[derive(Clone)]
Expand Down