Skip to content

Commit 233c613

Browse files
committed
---
yaml --- r: 118414 b: refs/heads/try c: c20aed0 h: refs/heads/master v: v3
1 parent 6fb92a9 commit 233c613

File tree

6 files changed

+43
-15
lines changed

6 files changed

+43
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3770c42a4959cbabc73da52abc7e3db96657974e
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: d6736a1440d42f6af967a8a20ab8d73522112b72
5-
refs/heads/try: c7426cf05a166fca8aa76a690bad17111ea0dea4
5+
refs/heads/try: c20aed09307d1b486c22e9b62156b02500ae1e6e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/doc/guide-lifetimes.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,10 @@ invalidate the pointer `owner_age`.
275275

276276
# Borrowing and enums
277277

278-
The previous example showed that the type system forbids any borrowing
279-
of owned boxes found in aliasable, mutable memory. This restriction
278+
The previous example showed that the type system forbids any mutations
279+
of owned boxed values while they are being borrowed. In general, the type
280+
system also forbids borrowing a value as mutable if it is already being
281+
borrowed - either as a mutable reference or an immutable one. This restriction
280282
prevents pointers from pointing into freed memory. There is one other
281283
case where the compiler must be very careful to ensure that pointers
282284
remain valid: pointers into the interior of an `enum`.

branches/try/src/libcore/cell.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ impl<'b, T> DerefMut<T> for RefMut<'b, T> {
385385
#[cfg(test)]
386386
mod test {
387387
use super::*;
388+
use mem::drop;
388389

389390
#[test]
390391
fn smoketest_cell() {
@@ -412,6 +413,22 @@ mod test {
412413
assert!(format!("{}", x).as_slice().contains(x.get()));
413414
}
414415

416+
#[test]
417+
fn ref_and_refmut_have_sensible_show() {
418+
use str::StrSlice;
419+
use realstd::str::Str;
420+
421+
let refcell = RefCell::new("foo");
422+
423+
let refcell_refmut = refcell.borrow_mut();
424+
assert!(format!("{}", refcell_refmut).as_slice().contains("foo"));
425+
drop(refcell_refmut);
426+
427+
let refcell_ref = refcell.borrow();
428+
assert!(format!("{}", refcell_ref).as_slice().contains("foo"));
429+
drop(refcell_ref);
430+
}
431+
415432
#[test]
416433
fn double_imm_borrow() {
417434
let x = RefCell::new(0);

branches/try/src/libcore/fmt/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
#![allow(unused_variable)]
1414

1515
use any;
16-
use cell::Cell;
16+
use cell::{Cell, Ref, RefMut};
1717
use char::Char;
1818
use collections::Collection;
1919
use iter::{Iterator, range};
2020
use kinds::Copy;
2121
use mem;
2222
use option::{Option, Some, None};
23+
use ops::Deref;
2324
use result::{Ok, Err};
2425
use result;
2526
use slice::{Vector, ImmutableVector};
@@ -840,5 +841,17 @@ impl<T: Copy + Show> Show for Cell<T> {
840841
}
841842
}
842843

844+
impl<'b, T: Show> Show for Ref<'b, T> {
845+
fn fmt(&self, f: &mut Formatter) -> Result {
846+
(**self).fmt(f)
847+
}
848+
}
849+
850+
impl<'b, T: Show> Show for RefMut<'b, T> {
851+
fn fmt(&self, f: &mut Formatter) -> Result {
852+
(*(self.deref())).fmt(f)
853+
}
854+
}
855+
843856
// If you expected tests to be here, look instead at the run-pass/ifmt.rs test,
844857
// it's a lot easier than creating all of the rt::Piece structures here.

branches/try/src/libstd/rand/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use std::rand;
6060
use std::rand::Rng;
6161
6262
let mut rng = rand::task_rng();
63-
if rng.gen() { // bool
63+
if rng.gen() { // random bool
6464
println!("int: {}, uint: {}", rng.gen::<int>(), rng.gen::<uint>())
6565
}
6666
```

branches/try/src/libsync/one.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,18 @@ use core::atomics;
2020

2121
use mutex::{StaticMutex, MUTEX_INIT};
2222

23-
/// A type which can be used to run a one-time global initialization. This type
24-
/// is *unsafe* to use because it is built on top of the `Mutex` in this module.
25-
/// It does not know whether the currently running task is in a green or native
26-
/// context, and a blocking mutex should *not* be used under normal
27-
/// circumstances on a green task.
28-
///
29-
/// Despite its unsafety, it is often useful to have a one-time initialization
30-
/// routine run for FFI bindings or related external functionality. This type
31-
/// can only be statically constructed with the `ONCE_INIT` value.
23+
/// A synchronization primitive which can be used to run a one-time global
24+
/// initialization. Useful for one-time initialization for FFI or related
25+
/// functionality. This type can only be constructed with the `ONCE_INIT`
26+
/// value.
3227
///
3328
/// # Example
3429
///
3530
/// ```rust
3631
/// use sync::one::{Once, ONCE_INIT};
3732
///
3833
/// static mut START: Once = ONCE_INIT;
34+
///
3935
/// unsafe {
4036
/// START.doit(|| {
4137
/// // run initialization here
@@ -60,7 +56,7 @@ impl Once {
6056
/// will be executed if this is the first time `doit` has been called, and
6157
/// otherwise the routine will *not* be invoked.
6258
///
63-
/// This method will block the calling *os thread* if another initialization
59+
/// This method will block the calling task if another initialization
6460
/// routine is currently running.
6561
///
6662
/// When this function returns, it is guaranteed that some initialization

0 commit comments

Comments
 (0)