Skip to content

Commit 9b0481f

Browse files
committed
---
yaml --- r: 130155 b: refs/heads/master c: 00ff5aa h: refs/heads/master i: 130153: 00b5ae8 130151: d8bb0ee v: v3
1 parent 969ae6d commit 9b0481f

Some content is hidden

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

62 files changed

+276
-946
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 8a8986776d16c16ef4685aa38c3f6a2c0efa7884
2+
refs/heads/master: 00ff5aac4ef48615321610b73f30da825700fb78
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 67b97ab6d2b7de9b69fd97dc171fcf8feec932ff
55
refs/heads/try: 28d5878c1f0465c11c8e7a3085008b0c592d48d0

trunk/src/doc/complement-lang-faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ We want to maintain the option to parametrize at runtime. We may eventually chan
8383

8484
## Why aren't values type-parametric? Why only items?
8585

86-
Doing so would make type inference much more complex, and require the implementation strategy of runtime parameterization.
86+
Doing so would make type inference much more complex, and require the implementation strategy of runtime parametrization.
8787

8888
## Why are enumerations nominal and closed?
8989

trunk/src/doc/guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ our code in this file. We'll talk about multiple-file projects later on in the
18081808
guide.
18091809

18101810
Before we move on, let me show you one more Cargo command: `run`. `cargo run`
1811-
is kind of like `cargo build`, but it also then runs the produced executable.
1811+
is kind of like `cargo build`, but it also then runs the produced exectuable.
18121812
Try it out:
18131813

18141814
```{notrust,ignore}

trunk/src/doc/rust.md

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ On `struct`s:
19541954

19551955
- `repr` - specifies the representation to use for this struct. Takes a list
19561956
of options. The currently accepted ones are `C` and `packed`, which may be
1957-
combined. `C` will use a C ABI compatible struct layout, and `packed` will
1957+
combined. `C` will use a C ABI comptible struct layout, and `packed` will
19581958
remove any padding between fields (note that this is very fragile and may
19591959
break platforms which require aligned access).
19601960

@@ -2367,7 +2367,7 @@ One can indicate the stability of an API using the following attributes:
23672367
These levels are directly inspired by
23682368
[Node.js' "stability index"](http://nodejs.org/api/documentation.html).
23692369

2370-
Stability levels are inherited, so an item's stability attribute is the
2370+
Stability levels are inherited, so an items's stability attribute is the
23712371
default stability for everything nested underneath it.
23722372

23732373
There are lints for disallowing items marked with certain levels: `deprecated`,
@@ -2444,7 +2444,7 @@ The currently implemented features of the reference compiler are:
24442444

24452445
* `concat_idents` - Allows use of the `concat_idents` macro, which is in many
24462446
ways insufficient for concatenating identifiers, and may
2447-
be removed entirely for something more wholesome.
2447+
be removed entirely for something more wholsome.
24482448

24492449
* `default_type_params` - Allows use of default type parameters. The future of
24502450
this feature is uncertain.
@@ -3604,7 +3604,7 @@ of the type.[^structtype]
36043604

36053605
New instances of a `struct` can be constructed with a [struct expression](#structure-expressions).
36063606

3607-
The memory layout of a `struct` is undefined by default to allow for compiler optimizations like
3607+
The memory layout of a `struct` is undefined by default to allow for compiler optimziations like
36083608
field reordering, but it can be fixed with the `#[repr(...)]` attribute.
36093609
In either case, fields may be given in any order in a corresponding struct *expression*;
36103610
the resulting `struct` value will always have the same memory layout.
@@ -3668,17 +3668,32 @@ let a: List<int> = Cons(7, box Cons(13, box Nil));
36683668

36693669
All pointers in Rust are explicit first-class values.
36703670
They can be copied, stored into data structures, and returned from functions.
3671-
There are two varieties of pointer in Rust:
3671+
There are four varieties of pointer in Rust:
3672+
3673+
* Owning pointers (`Box`)
3674+
: These point to owned heap allocations (or "boxes") in the shared, inter-task heap.
3675+
Each owned box has a single owning pointer; pointer and pointee retain a 1:1 relationship at all times.
3676+
Owning pointers are written `Box<content>`,
3677+
for example `Box<int>` means an owning pointer to an owned box containing an integer.
3678+
Copying an owned box is a "deep" operation:
3679+
it involves allocating a new owned box and copying the contents of the old box into the new box.
3680+
Releasing an owning pointer immediately releases its corresponding owned box.
36723681

36733682
* References (`&`)
36743683
: These point to memory _owned by some other value_.
3675-
A reference type is written `&type` for some lifetime-variable `f`,
3676-
or just `&'a type` when you need an explicit lifetime.
3684+
References arise by (automatic) conversion from owning pointers, managed pointers,
3685+
or by applying the borrowing operator `&` to some other value,
3686+
including [lvalues, rvalues or temporaries](#lvalues,-rvalues-and-temporaries).
3687+
A borrow expression is written `&content`.
3688+
3689+
A reference type is written `&'f type` for some lifetime-variable `f`,
3690+
or just `&type` when the lifetime can be elided;
3691+
for example `&int` means a reference to an integer.
36773692
Copying a reference is a "shallow" operation:
36783693
it involves only copying the pointer itself.
36793694
Releasing a reference typically has no effect on the value it points to,
3680-
with the exception of temporary values, which are released when the last
3681-
reference to them is released.
3695+
with the exception of temporary values,
3696+
which are released when the last reference to them is released.
36823697

36833698
* Raw pointers (`*`)
36843699
: Raw pointers are pointers without safety or liveness guarantees.
@@ -3691,9 +3706,6 @@ There are two varieties of pointer in Rust:
36913706
they exist to support interoperability with foreign code,
36923707
and writing performance-critical or low-level functions.
36933708

3694-
The standard library contains addtional 'smart pointer' types beyond references
3695-
and raw pointers.
3696-
36973709
### Function types
36983710

36993711
The function type constructor `fn` forms new function types.
@@ -4202,7 +4214,7 @@ be ignored in favor of only building the artifacts specified by command line.
42024214
purpose of this output type is to create a static library containing all of
42034215
the local crate's code along with all upstream dependencies. The static
42044216
library is actually a `*.a` archive on linux and osx and a `*.lib` file on
4205-
windows. This format is recommended for use in situations such as linking
4217+
windows. This format is recommended for use in situtations such as linking
42064218
Rust code into an existing non-Rust application because it will not have
42074219
dynamic dependencies on other Rust code.
42084220

trunk/src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<T> Rawlink<T> {
9090
/// Convert the `Rawlink` into an Option value
9191
fn resolve_immut<'a>(&self) -> Option<&'a T> {
9292
unsafe {
93-
mem::transmute(self.p.to_option())
93+
self.p.as_ref()
9494
}
9595
}
9696

trunk/src/libcore/failure.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ fn fail_bounds_check(file_line: &(&'static str, uint),
5555
unsafe { intrinsics::abort() }
5656
}
5757

58-
#[cold] #[inline(never)]
59-
pub fn begin_unwind_string(msg: &str, file: &(&'static str, uint)) -> ! {
60-
format_args!(|fmt| begin_unwind(fmt, file), "{}", msg)
61-
}
62-
6358
#[cold] #[inline(never)]
6459
pub fn begin_unwind(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
6560
#[allow(ctypes)]

trunk/src/libcore/macros.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ macro_rules! fail(
1616
() => (
1717
fail!("{}", "explicit failure")
1818
);
19-
($msg:expr) => ({
20-
static _FILE_LINE: (&'static str, uint) = (file!(), line!());
21-
::core::failure::begin_unwind_string($msg, &_FILE_LINE)
22-
});
19+
($msg:expr) => (
20+
fail!("{}", $msg)
21+
);
2322
($fmt:expr, $($arg:tt)*) => ({
2423
// a closure can't have return type !, so we need a full
2524
// function to pass to format_args!, *and* we need the

trunk/src/libcore/ptr.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,27 +256,46 @@ pub unsafe fn position<T>(buf: *const T, f: |&T| -> bool) -> uint {
256256
pub trait RawPtr<T> {
257257
/// Returns the null pointer.
258258
fn null() -> Self;
259+
259260
/// Returns true if the pointer is equal to the null pointer.
260261
fn is_null(&self) -> bool;
262+
261263
/// Returns true if the pointer is not equal to the null pointer.
262264
fn is_not_null(&self) -> bool { !self.is_null() }
265+
263266
/// Returns the value of this pointer (ie, the address it points to)
264267
fn to_uint(&self) -> uint;
265-
/// Returns `None` if the pointer is null, or else returns the value wrapped
266-
/// in `Some`.
268+
269+
/// Returns `None` if the pointer is null, or else returns a reference to the
270+
/// value wrapped in `Some`.
267271
///
268272
/// # Safety Notes
269273
///
270-
/// While this method is useful for null-safety, it is important to note
271-
/// that this is still an unsafe operation because the returned value could
272-
/// be pointing to invalid memory.
273-
unsafe fn to_option(&self) -> Option<&T>;
274+
/// While this method and its mutable counterpart are useful for null-safety,
275+
/// it is important to note that this is still an unsafe operation because
276+
/// the returned value could be pointing to invalid memory.
277+
unsafe fn as_ref<'a>(&self) -> Option<&'a T>;
278+
279+
/// A synonym for `as_ref`, except with incorrect lifetime semantics
280+
#[deprecated="Use `as_ref` instead"]
281+
unsafe fn to_option<'a>(&'a self) -> Option<&'a T> {
282+
mem::transmute(self.as_ref())
283+
}
284+
274285
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
275286
/// the object, or one-byte-past-the-end. `count` is in units of T; e.g. a
276287
/// `count` of 3 represents a pointer offset of `3 * sizeof::<T>()` bytes.
277288
unsafe fn offset(self, count: int) -> Self;
278289
}
279290

291+
/// Methods on mutable raw pointers
292+
pub trait RawMutPtr<T>{
293+
/// Returns `None` if the pointer is null, or else returns a mutable reference
294+
/// to the value wrapped in `Some`. As with `as_ref`, this is unsafe because
295+
/// it cannot verify the validity of the returned pointer.
296+
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T>;
297+
}
298+
280299
impl<T> RawPtr<T> for *const T {
281300
#[inline]
282301
fn null() -> *const T { null() }
@@ -293,7 +312,7 @@ impl<T> RawPtr<T> for *const T {
293312
}
294313

295314
#[inline]
296-
unsafe fn to_option(&self) -> Option<&T> {
315+
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
297316
if self.is_null() {
298317
None
299318
} else {
@@ -318,7 +337,7 @@ impl<T> RawPtr<T> for *mut T {
318337
}
319338

320339
#[inline]
321-
unsafe fn to_option(&self) -> Option<&T> {
340+
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
322341
if self.is_null() {
323342
None
324343
} else {
@@ -327,6 +346,17 @@ impl<T> RawPtr<T> for *mut T {
327346
}
328347
}
329348

349+
impl<T> RawMutPtr<T> for *mut T {
350+
#[inline]
351+
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
352+
if self.is_null() {
353+
None
354+
} else {
355+
Some(&mut **self)
356+
}
357+
}
358+
}
359+
330360
// Equality for pointers
331361
impl<T> PartialEq for *const T {
332362
#[inline]

trunk/src/libcore/slice.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -996,15 +996,6 @@ impl<'a, T> Collection for &'a [T] {
996996
}
997997
}
998998

999-
#[experimental = "trait is experimental"]
1000-
impl<'a, T> Collection for &'a mut [T] {
1001-
/// Returns the length of a vector
1002-
#[inline]
1003-
fn len(&self) -> uint {
1004-
self.repr().len
1005-
}
1006-
}
1007-
1008999
#[unstable = "waiting for DST"]
10091000
impl<'a, T> Default for &'a [T] {
10101001
fn default() -> &'a [T] { &[] }

trunk/src/libcoretest/ptr.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,44 @@ fn test_is_null() {
102102
}
103103

104104
#[test]
105-
fn test_to_option() {
105+
fn test_as_ref() {
106106
unsafe {
107107
let p: *const int = null();
108-
assert_eq!(p.to_option(), None);
108+
assert_eq!(p.as_ref(), None);
109109

110110
let q: *const int = &2;
111-
assert_eq!(q.to_option().unwrap(), &2);
111+
assert_eq!(q.as_ref().unwrap(), &2);
112112

113113
let p: *mut int = mut_null();
114-
assert_eq!(p.to_option(), None);
114+
assert_eq!(p.as_ref(), None);
115115

116116
let q: *mut int = &mut 2;
117-
assert_eq!(q.to_option().unwrap(), &2);
117+
assert_eq!(q.as_ref().unwrap(), &2);
118+
119+
// Lifetime inference
120+
let u = 2i;
121+
{
122+
let p: *const int = &u as *const _;
123+
assert_eq!(p.as_ref().unwrap(), &2);
124+
}
125+
}
126+
}
127+
128+
#[test]
129+
fn test_as_mut() {
130+
unsafe {
131+
let p: *mut int = mut_null();
132+
assert!(p.as_mut() == None);
133+
134+
let q: *mut int = &mut 2;
135+
assert!(q.as_mut().unwrap() == &mut 2);
136+
137+
// Lifetime inference
138+
let mut u = 2i;
139+
{
140+
let p: *mut int = &mut u as *mut _;
141+
assert!(p.as_mut().unwrap() == &mut 2);
142+
}
118143
}
119144
}
120145

0 commit comments

Comments
 (0)