Skip to content

Commit 4f3062c

Browse files
committed
Auto merge of #43603 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests - Successful merges: #43389, #43423, #43581, #43585, #43597, #43598 - Failed merges:
2 parents f5f58d0 + 368f1a8 commit 4f3062c

File tree

8 files changed

+89
-31
lines changed

8 files changed

+89
-31
lines changed

src/libcore/cell.rs

+28
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,34 @@ use ptr;
188188

189189
/// A mutable memory location.
190190
///
191+
/// # Examples
192+
///
193+
/// Here you can see how using `Cell<T>` allows to use mutable field inside
194+
/// immutable struct (which is also called 'interior mutability').
195+
///
196+
/// ```
197+
/// use std::cell::Cell;
198+
///
199+
/// struct SomeStruct {
200+
/// regular_field: u8,
201+
/// special_field: Cell<u8>,
202+
/// }
203+
///
204+
/// let my_struct = SomeStruct {
205+
/// regular_field: 0,
206+
/// special_field: Cell::new(1),
207+
/// };
208+
///
209+
/// let new_value = 100;
210+
///
211+
/// // ERROR, because my_struct is immutable
212+
/// // my_struct.regular_field = new_value;
213+
///
214+
/// // WORKS, although `my_struct` is immutable, field `special_field` is mutable because it is Cell
215+
/// my_struct.special_field.set(new_value);
216+
/// assert_eq!(my_struct.special_field.get(), new_value);
217+
/// ```
218+
///
191219
/// See the [module-level documentation](index.html) for more.
192220
#[stable(feature = "rust1", since = "1.0.0")]
193221
pub struct Cell<T> {

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pub struct AssociatedItem {
174174
pub method_has_self_argument: bool,
175175
}
176176

177-
#[derive(Copy, Clone, PartialEq, Eq, Debug, RustcEncodable, RustcDecodable)]
177+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, RustcEncodable, RustcDecodable)]
178178
pub enum AssociatedKind {
179179
Const,
180180
Method,

src/librustc_data_structures/bitslice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ pub trait BitwiseOperator {
134134

135135
pub struct Union;
136136
impl BitwiseOperator for Union {
137+
#[inline]
137138
fn join(&self, a: usize, b: usize) -> usize { a | b }
138139
}
139140
pub struct Subtract;
140141
impl BitwiseOperator for Subtract {
142+
#[inline]
141143
fn join(&self, a: usize, b: usize) -> usize { a & !b }
142144
}

src/librustc_llvm/archive_ro.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ impl ArchiveRO {
3939
///
4040
/// If this archive is used with a mutable method, then an error will be
4141
/// raised.
42-
pub fn open(dst: &Path) -> Option<ArchiveRO> {
42+
pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
4343
return unsafe {
4444
let s = path2cstr(dst);
4545
let ar = ::LLVMRustOpenArchive(s.as_ptr());
4646
if ar.is_null() {
47-
None
47+
Err(::last_error().unwrap_or("failed to open archive".to_string()))
4848
} else {
49-
Some(ArchiveRO { ptr: ar })
49+
Ok(ArchiveRO { ptr: ar })
5050
}
5151
};
5252

src/librustc_trans/back/archive.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a> ArchiveBuilder<'a> {
126126
Some(ref src) => src,
127127
None => return None,
128128
};
129-
self.src_archive = Some(ArchiveRO::open(src));
129+
self.src_archive = Some(ArchiveRO::open(src).ok());
130130
self.src_archive.as_ref().unwrap().as_ref()
131131
}
132132

@@ -186,9 +186,8 @@ impl<'a> ArchiveBuilder<'a> {
186186
where F: FnMut(&str) -> bool + 'static
187187
{
188188
let archive = match ArchiveRO::open(archive) {
189-
Some(ar) => ar,
190-
None => return Err(io::Error::new(io::ErrorKind::Other,
191-
"failed to open archive")),
189+
Ok(ar) => ar,
190+
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)),
192191
};
193192
self.additions.push(Addition::Archive {
194193
archive: archive,

src/librustc_trans/metadata.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ impl MetadataLoader for LlvmMetadataLoader {
3131
// just keeping the archive along while the metadata is in use.
3232
let archive = ArchiveRO::open(filename)
3333
.map(|ar| OwningRef::new(box ar))
34-
.ok_or_else(|| {
35-
debug!("llvm didn't like `{}`", filename.display());
36-
format!("failed to read rlib metadata: '{}'", filename.display())
37-
})?;
34+
.map_err(|e| {
35+
debug!("llvm didn't like `{}`: {}", filename.display(), e);
36+
format!("failed to read rlib metadata in '{}': {}", filename.display(), e)
37+
})?;
3838
let buf: OwningRef<_, [u8]> = archive
3939
.try_map(|ar| {
4040
ar.iter()
4141
.filter_map(|s| s.ok())
4242
.find(|sect| sect.name() == Some(METADATA_FILENAME))
4343
.map(|s| s.data())
4444
.ok_or_else(|| {
45-
debug!("didn't find '{}' in the archive", METADATA_FILENAME);
46-
format!("failed to read rlib metadata: '{}'",
47-
filename.display())
48-
})
45+
debug!("didn't find '{}' in the archive", METADATA_FILENAME);
46+
format!("failed to read rlib metadata: '{}'",
47+
filename.display())
48+
})
4949
})?;
5050
Ok(buf.erase_owner())
5151
}

src/libstd/collections/hash/set.rs

+43-14
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ pub struct HashSet<T, S = RandomState> {
123123
}
124124

125125
impl<T: Hash + Eq> HashSet<T, RandomState> {
126-
/// Creates an empty HashSet.
126+
/// Creates an empty `HashSet`.
127127
///
128128
/// # Examples
129129
///
130130
/// ```
131131
/// use std::collections::HashSet;
132-
/// let mut set: HashSet<i32> = HashSet::new();
132+
/// let set: HashSet<i32> = HashSet::new();
133133
/// ```
134134
#[inline]
135135
#[stable(feature = "rust1", since = "1.0.0")]
@@ -146,7 +146,8 @@ impl<T: Hash + Eq> HashSet<T, RandomState> {
146146
///
147147
/// ```
148148
/// use std::collections::HashSet;
149-
/// let mut set: HashSet<i32> = HashSet::with_capacity(10);
149+
/// let set: HashSet<i32> = HashSet::with_capacity(10);
150+
/// assert!(set.capacity() >= 10);
150151
/// ```
151152
#[inline]
152153
#[stable(feature = "rust1", since = "1.0.0")]
@@ -215,6 +216,17 @@ impl<T, S> HashSet<T, S>
215216
/// Returns a reference to the set's [`BuildHasher`].
216217
///
217218
/// [`BuildHasher`]: ../../std/hash/trait.BuildHasher.html
219+
///
220+
/// # Examples
221+
///
222+
/// ```
223+
/// use std::collections::HashSet;
224+
/// use std::collections::hash_map::RandomState;
225+
///
226+
/// let hasher = RandomState::new();
227+
/// let set: HashSet<i32> = HashSet::with_hasher(hasher);
228+
/// let hasher: &RandomState = set.hasher();
229+
/// ```
218230
#[stable(feature = "hashmap_public_hasher", since = "1.9.0")]
219231
pub fn hasher(&self) -> &S {
220232
self.map.hasher()
@@ -249,6 +261,7 @@ impl<T, S> HashSet<T, S>
249261
/// use std::collections::HashSet;
250262
/// let mut set: HashSet<i32> = HashSet::new();
251263
/// set.reserve(10);
264+
/// assert!(set.capacity() >= 10);
252265
/// ```
253266
#[stable(feature = "rust1", since = "1.0.0")]
254267
pub fn reserve(&mut self, additional: usize) {
@@ -312,13 +325,13 @@ impl<T, S> HashSet<T, S>
312325
/// println!("{}", x); // Print 1
313326
/// }
314327
///
315-
/// let diff: HashSet<_> = a.difference(&b).cloned().collect();
316-
/// assert_eq!(diff, [1].iter().cloned().collect());
328+
/// let diff: HashSet<_> = a.difference(&b).collect();
329+
/// assert_eq!(diff, [1].iter().collect());
317330
///
318331
/// // Note that difference is not symmetric,
319332
/// // and `b - a` means something else:
320-
/// let diff: HashSet<_> = b.difference(&a).cloned().collect();
321-
/// assert_eq!(diff, [4].iter().cloned().collect());
333+
/// let diff: HashSet<_> = b.difference(&a).collect();
334+
/// assert_eq!(diff, [4].iter().collect());
322335
/// ```
323336
#[stable(feature = "rust1", since = "1.0.0")]
324337
pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S> {
@@ -343,11 +356,11 @@ impl<T, S> HashSet<T, S>
343356
/// println!("{}", x);
344357
/// }
345358
///
346-
/// let diff1: HashSet<_> = a.symmetric_difference(&b).cloned().collect();
347-
/// let diff2: HashSet<_> = b.symmetric_difference(&a).cloned().collect();
359+
/// let diff1: HashSet<_> = a.symmetric_difference(&b).collect();
360+
/// let diff2: HashSet<_> = b.symmetric_difference(&a).collect();
348361
///
349362
/// assert_eq!(diff1, diff2);
350-
/// assert_eq!(diff1, [1, 4].iter().cloned().collect());
363+
/// assert_eq!(diff1, [1, 4].iter().collect());
351364
/// ```
352365
#[stable(feature = "rust1", since = "1.0.0")]
353366
pub fn symmetric_difference<'a>(&'a self,
@@ -371,8 +384,8 @@ impl<T, S> HashSet<T, S>
371384
/// println!("{}", x);
372385
/// }
373386
///
374-
/// let intersection: HashSet<_> = a.intersection(&b).cloned().collect();
375-
/// assert_eq!(intersection, [2, 3].iter().cloned().collect());
387+
/// let intersection: HashSet<_> = a.intersection(&b).collect();
388+
/// assert_eq!(intersection, [2, 3].iter().collect());
376389
/// ```
377390
#[stable(feature = "rust1", since = "1.0.0")]
378391
pub fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S> {
@@ -397,8 +410,8 @@ impl<T, S> HashSet<T, S>
397410
/// println!("{}", x);
398411
/// }
399412
///
400-
/// let union: HashSet<_> = a.union(&b).cloned().collect();
401-
/// assert_eq!(union, [1, 2, 3, 4].iter().cloned().collect());
413+
/// let union: HashSet<_> = a.union(&b).collect();
414+
/// assert_eq!(union, [1, 2, 3, 4].iter().collect());
402415
/// ```
403416
#[stable(feature = "rust1", since = "1.0.0")]
404417
pub fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S> {
@@ -440,6 +453,22 @@ impl<T, S> HashSet<T, S>
440453
}
441454

442455
/// Clears the set, returning all elements in an iterator.
456+
///
457+
/// # Examples
458+
///
459+
/// ```
460+
/// use std::collections::HashSet;
461+
///
462+
/// let mut set: HashSet<_> = [1, 2, 3].iter().cloned().collect();
463+
/// assert!(!set.is_empty());
464+
///
465+
/// // print 1, 2, 3 in an arbitrary order
466+
/// for i in set.drain() {
467+
/// println!("{}", i);
468+
/// }
469+
///
470+
/// assert!(set.is_empty());
471+
/// ```
443472
#[inline]
444473
#[stable(feature = "drain", since = "1.6.0")]
445474
pub fn drain(&mut self) -> Drain<T> {

src/libstd/os/solaris/raw.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use os::unix::raw::{uid_t, gid_t};
3232
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
3333

3434
#[stable(feature = "pthread_t", since = "1.8.0")]
35-
pub type pthread_t = usize;
35+
pub type pthread_t = u32;
3636

3737
#[repr(C)]
3838
#[derive(Clone)]

0 commit comments

Comments
 (0)