Skip to content

Commit 43e2bbc

Browse files
committed
---
yaml --- r: 125567 b: refs/heads/auto c: ff3d902 h: refs/heads/master i: 125565: c43f156 125563: c0e155b 125559: dcbfee3 125551: ca834c3 125535: 88eef84 125503: 68aa7a4 125439: 9aaee73 v: v3
1 parent e8798a3 commit 43e2bbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1259
-1739
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: f2153465e47ac280a260e9a30466acbcfaf6832d
16+
refs/heads/auto: ff3d902fcbcdddc885e03ffe3f84bc9dcb003cec
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/mk/crates.mk

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
TARGET_CRATES := libc std green rustuv native flate arena glob term semver \
5353
uuid serialize sync getopts collections num test time rand \
54-
url log regex graphviz core rbml rlibc alloc debug rustrt \
54+
url log regex graphviz core rlibc alloc debug rustrt \
5555
unicode
5656
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros \
5757
rustc_llvm rustc_back
@@ -71,7 +71,7 @@ DEPS_green := std native:context_switch
7171
DEPS_rustuv := std native:uv native:uv_support
7272
DEPS_native := std
7373
DEPS_syntax := std term serialize log fmt_macros debug
74-
DEPS_rustc := syntax flate arena serialize getopts rbml \
74+
DEPS_rustc := syntax flate arena serialize getopts \
7575
time log graphviz debug rustc_llvm rustc_back
7676
DEPS_rustc_llvm := native:rustllvm libc std
7777
DEPS_rustc_back := std syntax rustc_llvm flate log libc
@@ -82,7 +82,6 @@ DEPS_arena := std
8282
DEPS_graphviz := std
8383
DEPS_glob := std
8484
DEPS_serialize := std log
85-
DEPS_rbml := std log serialize
8685
DEPS_term := std log
8786
DEPS_semver := std
8887
DEPS_uuid := std serialize
@@ -92,7 +91,7 @@ DEPS_collections := core alloc unicode
9291
DEPS_fourcc := rustc syntax std
9392
DEPS_hexfloat := rustc syntax std
9493
DEPS_num := std
95-
DEPS_test := std getopts serialize rbml term time regex native:rust_test_helpers
94+
DEPS_test := std getopts serialize term time regex native:rust_test_helpers
9695
DEPS_time := std serialize
9796
DEPS_rand := core
9897
DEPS_url := std

branches/auto/src/doc/complement-lang-faq.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
% Language FAQ
22

3+
34
## Are there any big programs written in it yet? I want to read big samples.
45

56
There aren't many large programs yet. The Rust [compiler][rustc], 60,000+ lines at the time of writing, is written in Rust. As the oldest body of Rust code it has gone through many iterations of the language, and some parts are nicer to look at than others. It may not be the best code to learn from, but [borrowck] and [resolve] were written recently.
@@ -28,18 +29,6 @@ You may also be interested in browsing [GitHub's Rust][github-rust] page.
2829

2930
[github-rust]: https://github.com/trending?l=rust
3031

31-
## Is anyone using Rust in production?
32-
33-
Currently, Rust is still pre-1.0, and so we don't recommend that you use Rust
34-
in production unless you know exactly what you're getting into.
35-
36-
That said, there are two production deployments of Rust that we're aware of:
37-
38-
* [OpenDNS](http://labs.opendns.com/2013/10/04/zeromq-helping-us-block-malicious-domains/)
39-
* [Skylight](http://skylight.io)
40-
41-
Let the fact that this is an easily countable number be a warning.
42-
4332
## Does it run on Windows?
4433

4534
Yes. All development happens in lock-step on all 3 target platforms. Using MinGW, not Cygwin. Note that the windows implementation currently has some limitations: in particular 64-bit build is [not fully supported yet][win64], and all executables created by rustc [depend on libgcc DLL at runtime][libgcc].

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,36 @@ In any case, whatever the lifetime of `r` is, the pointer produced by
431431
field of a struct is valid as long as the struct is valid. Therefore,
432432
the compiler accepts the function `get_x()`.
433433

434+
To emphasize this point, let’s look at a variation on the example, this
435+
time one that does not compile:
436+
437+
~~~ {.ignore}
438+
struct Point {x: f64, y: f64}
439+
fn get_x_sh(p: &Point) -> &f64 {
440+
&p.x // Error reported here
441+
}
442+
~~~
443+
444+
Here, the function `get_x_sh()` takes a reference as input and
445+
returns a reference. As before, the lifetime of the reference
446+
that will be returned is a parameter (specified by the
447+
caller). That means that `get_x_sh()` promises to return a reference
448+
that is valid for as long as the caller would like: this is
449+
subtly different from the first example, which promised to return a
450+
pointer that was valid for as long as its pointer argument was valid.
451+
452+
Within `get_x_sh()`, we see the expression `&p.x` which takes the
453+
address of a field of a Point. The presence of this expression
454+
implies that the compiler must guarantee that , so long as the
455+
resulting pointer is valid, the original Point won't be moved or changed.
456+
457+
But recall that `get_x_sh()` also promised to
458+
return a pointer that was valid for as long as the caller wanted it to
459+
be. Clearly, `get_x_sh()` is not in a position to make both of these
460+
guarantees; in fact, it cannot guarantee that the pointer will remain
461+
valid at all once it returns, as the parameter `p` may or may not be
462+
live in the caller. Therefore, the compiler will report an error here.
463+
434464
In general, if you borrow a struct or box to create a
435465
reference, it will only be valid within the function
436466
and cannot be returned. This is why the typical way to return references

branches/auto/src/doc/guide-pointers.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,12 @@ fn main() {
578578

579579
Notice we changed the signature of `add_one()` to request a mutable reference.
580580

581-
## Best practices
581+
# Best practices
582582

583583
Boxes are appropriate to use in two situations: Recursive data structures,
584584
and occasionally, when returning data.
585585

586-
### Recursive data structures
586+
## Recursive data structures
587587

588588
Sometimes, you need a recursive data structure. The simplest is known as a
589589
'cons list':
@@ -615,7 +615,7 @@ we don't know the size, and therefore, we need to heap allocate our list.
615615
Working with recursive or other unknown-sized data structures is the primary
616616
use-case for boxes.
617617

618-
### Returning data
618+
## Returning data
619619

620620
This is important enough to have its own section entirely. The TL;DR is this:
621621
you don't generally want to return pointers, even when you might in a language
@@ -733,15 +733,18 @@ This part is coming soon.
733733

734734
Here's a quick rundown of Rust's pointer types:
735735

736-
| Type | Name | Summary |
737-
|--------------|---------------------|---------------------------------------------------------------------|
738-
| `&T` | Reference | Allows one or more references to read `T` |
739-
| `&mut T` | Mutable Reference | Allows a single reference to read and write `T` |
740-
| `Box<T>` | Box | Heap allocated `T` with a single owner that may read and write `T`. |
741-
| `Rc<T>` | "arr cee" pointer | Heap allocated `T` with many readers |
742-
| `Arc<T>` | Arc pointer | Same as above, but safe sharing across threads |
743-
| `*const T` | Raw pointer | Unsafe read access to `T` |
744-
| `*mut T` | Mutable raw pointer | Unsafe read and write access to `T` |
736+
| Type | Name | Summary |
737+
|--------------|---------------------|-------------------------------------------|
738+
| `&T` | Reference | Allows one or more references to read `T` |
739+
| `&mut T` | Mutable Reference | Allows a single reference to |
740+
| | | read and write `T` |
741+
| `Box<T>` | Box | Heap allocated `T` with a single owner |
742+
| | | that may read and write `T`. |
743+
| `Rc<T>` | "arr cee" pointer | Heap allocated `T` with many readers |
744+
| `Arc<T>` | Arc pointer | Same as above, but safe sharing across |
745+
| | | threads |
746+
| `*const T` | Raw pointer | Unsafe read access to `T` |
747+
| `*mut T` | Mutable raw pointer | Unsafe read and write access to `T` |
745748

746749
# Related resources
747750

branches/auto/src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ reference. We also call this _borrowing_ the local variable
15031503
`on_the_stack`, because we are creating an alias: that is, another
15041504
route to the same data.
15051505

1506-
Likewise, in the case of `on_the_heap`,
1506+
Likewise, in the case of `owned_box`,
15071507
the `&` operator is used in conjunction with the `*` operator
15081508
to take a reference to the contents of the box.
15091509

branches/auto/src/liballoc/rc.rs

Lines changed: 14 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,18 @@ fn main() {
150150

151151
#![stable]
152152

153+
use core::mem::transmute;
153154
use core::cell::Cell;
154155
use core::clone::Clone;
155156
use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
156157
use core::default::Default;
157-
use core::fmt;
158158
use core::kinds::marker;
159-
use core::mem::{transmute, min_align_of, size_of, forget};
160159
use core::ops::{Deref, Drop};
161160
use core::option::{Option, Some, None};
162161
use core::ptr;
163162
use core::ptr::RawPtr;
164-
use core::result::{Result, Ok, Err};
163+
use core::mem::{min_align_of, size_of};
164+
use core::fmt;
165165

166166
use heap::deallocate;
167167

@@ -218,76 +218,6 @@ impl<T> Rc<T> {
218218
}
219219
}
220220

221-
/// Returns true if the `Rc` currently has unique ownership.
222-
///
223-
/// Unique ownership means that there are no other `Rc` or `Weak` values
224-
/// that share the same contents.
225-
#[inline]
226-
#[experimental]
227-
pub fn is_unique<T>(rc: &Rc<T>) -> bool {
228-
// note that we hold both a strong and a weak reference
229-
rc.strong() == 1 && rc.weak() == 1
230-
}
231-
232-
/// Unwraps the contained value if the `Rc` has unique ownership.
233-
///
234-
/// If the `Rc` does not have unique ownership, `Err` is returned with the
235-
/// same `Rc`.
236-
///
237-
/// # Example:
238-
///
239-
/// ```
240-
/// use std::rc::{mod, Rc};
241-
/// let x = Rc::new(3u);
242-
/// assert_eq!(rc::try_unwrap(x), Ok(3u));
243-
/// let x = Rc::new(4u);
244-
/// let _y = x.clone();
245-
/// assert_eq!(rc::try_unwrap(x), Err(Rc::new(4u)));
246-
/// ```
247-
#[inline]
248-
#[experimental]
249-
pub fn try_unwrap<T>(rc: Rc<T>) -> Result<T, Rc<T>> {
250-
if is_unique(&rc) {
251-
unsafe {
252-
let val = ptr::read(&*rc); // copy the contained object
253-
// destruct the box and skip our Drop
254-
// we can ignore the refcounts because we know we're unique
255-
deallocate(rc._ptr as *mut u8, size_of::<RcBox<T>>(),
256-
min_align_of::<RcBox<T>>());
257-
forget(rc);
258-
Ok(val)
259-
}
260-
} else {
261-
Err(rc)
262-
}
263-
}
264-
265-
/// Returns a mutable reference to the contained value if the `Rc` has
266-
/// unique ownership.
267-
///
268-
/// Returns `None` if the `Rc` does not have unique ownership.
269-
///
270-
/// # Example:
271-
///
272-
/// ```
273-
/// use std::rc::{mod, Rc};
274-
/// let mut x = Rc::new(3u);
275-
/// *rc::get_mut(&mut x).unwrap() = 4u;
276-
/// assert_eq!(*x, 4u);
277-
/// let _y = x.clone();
278-
/// assert!(rc::get_mut(&mut x).is_none());
279-
/// ```
280-
#[inline]
281-
#[experimental]
282-
pub fn get_mut<'a, T>(rc: &'a mut Rc<T>) -> Option<&'a mut T> {
283-
if is_unique(rc) {
284-
let inner = unsafe { &mut *rc._ptr };
285-
Some(&mut inner.value)
286-
} else {
287-
None
288-
}
289-
}
290-
291221
impl<T: Clone> Rc<T> {
292222
/// Acquires a mutable pointer to the inner contents by guaranteeing that
293223
/// the reference count is one (no sharing is possible).
@@ -296,9 +226,12 @@ impl<T: Clone> Rc<T> {
296226
/// data is cloned if the reference count is greater than one.
297227
#[inline]
298228
#[experimental]
299-
pub fn make_unique(&mut self) -> &mut T {
300-
if !is_unique(self) {
301-
*self = Rc::new((**self).clone())
229+
pub fn make_unique<'a>(&'a mut self) -> &'a mut T {
230+
// Note that we hold a strong reference, which also counts as
231+
// a weak reference, so we only clone if there is an
232+
// additional reference of either kind.
233+
if self.strong() != 1 || self.weak() != 1 {
234+
*self = Rc::new(self.deref().clone())
302235
}
303236
// This unsafety is ok because we're guaranteed that the pointer
304237
// returned is the *only* pointer that will ever be returned to T. Our
@@ -314,7 +247,7 @@ impl<T: Clone> Rc<T> {
314247
impl<T> Deref<T> for Rc<T> {
315248
/// Borrow the value contained in the reference-counted box
316249
#[inline(always)]
317-
fn deref(&self) -> &T {
250+
fn deref<'a>(&'a self) -> &'a T {
318251
&self.inner().value
319252
}
320253
}
@@ -327,7 +260,7 @@ impl<T> Drop for Rc<T> {
327260
if !self._ptr.is_null() {
328261
self.dec_strong();
329262
if self.strong() == 0 {
330-
ptr::read(&**self); // destroy the contained object
263+
ptr::read(self.deref()); // destroy the contained object
331264

332265
// remove the implicit "strong weak" pointer now
333266
// that we've destroyed the contents.
@@ -457,7 +390,7 @@ impl<T> Clone for Weak<T> {
457390

458391
#[doc(hidden)]
459392
trait RcBoxPtr<T> {
460-
fn inner(&self) -> &RcBox<T>;
393+
fn inner<'a>(&'a self) -> &'a RcBox<T>;
461394

462395
#[inline]
463396
fn strong(&self) -> uint { self.inner().strong.get() }
@@ -480,12 +413,12 @@ trait RcBoxPtr<T> {
480413

481414
impl<T> RcBoxPtr<T> for Rc<T> {
482415
#[inline(always)]
483-
fn inner(&self) -> &RcBox<T> { unsafe { &(*self._ptr) } }
416+
fn inner<'a>(&'a self) -> &'a RcBox<T> { unsafe { &(*self._ptr) } }
484417
}
485418

486419
impl<T> RcBoxPtr<T> for Weak<T> {
487420
#[inline(always)]
488-
fn inner(&self) -> &RcBox<T> { unsafe { &(*self._ptr) } }
421+
fn inner<'a>(&'a self) -> &'a RcBox<T> { unsafe { &(*self._ptr) } }
489422
}
490423

491424
#[cfg(test)]
@@ -494,7 +427,6 @@ mod tests {
494427
use super::{Rc, Weak};
495428
use std::cell::RefCell;
496429
use std::option::{Option, Some, None};
497-
use std::result::{Err, Ok};
498430
use std::mem::drop;
499431
use std::clone::Clone;
500432

@@ -562,45 +494,6 @@ mod tests {
562494
// hopefully we don't double-free (or leak)...
563495
}
564496

565-
#[test]
566-
fn is_unique() {
567-
let x = Rc::new(3u);
568-
assert!(super::is_unique(&x));
569-
let y = x.clone();
570-
assert!(!super::is_unique(&x));
571-
drop(y);
572-
assert!(super::is_unique(&x));
573-
let w = x.downgrade();
574-
assert!(!super::is_unique(&x));
575-
drop(w);
576-
assert!(super::is_unique(&x));
577-
}
578-
579-
#[test]
580-
fn try_unwrap() {
581-
let x = Rc::new(3u);
582-
assert_eq!(super::try_unwrap(x), Ok(3u));
583-
let x = Rc::new(4u);
584-
let _y = x.clone();
585-
assert_eq!(super::try_unwrap(x), Err(Rc::new(4u)));
586-
let x = Rc::new(5u);
587-
let _w = x.downgrade();
588-
assert_eq!(super::try_unwrap(x), Err(Rc::new(5u)));
589-
}
590-
591-
#[test]
592-
fn get_mut() {
593-
let mut x = Rc::new(3u);
594-
*super::get_mut(&mut x).unwrap() = 4u;
595-
assert_eq!(*x, 4u);
596-
let y = x.clone();
597-
assert!(super::get_mut(&mut x).is_none());
598-
drop(y);
599-
assert!(super::get_mut(&mut x).is_some());
600-
let _w = x.downgrade();
601-
assert!(super::get_mut(&mut x).is_none());
602-
}
603-
604497
#[test]
605498
fn test_cowrc_clone_make_unique() {
606499
let mut cow0 = Rc::new(75u);

0 commit comments

Comments
 (0)