Skip to content

Commit 88506b4

Browse files
committed
---
yaml --- r: 152481 b: refs/heads/try2 c: c20aed0 h: refs/heads/master i: 152479: 1d3ab9d v: v3
1 parent f10dcc0 commit 88506b4

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: c7426cf05a166fca8aa76a690bad17111ea0dea4
8+
refs/heads/try2: c20aed09307d1b486c22e9b62156b02500ae1e6e
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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/try2/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/try2/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/try2/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/try2/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)