Skip to content

Commit 97f786f

Browse files
committed
---
yaml --- r: 160857 b: refs/heads/auto c: 48ca6d1 h: refs/heads/master i: 160855: 4485fa2 v: v3
1 parent 6291fb3 commit 97f786f

File tree

27 files changed

+301
-79
lines changed

27 files changed

+301
-79
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: de94f0affb6e8f700ce1e9c67a9572c9f262a5fa
13+
refs/heads/auto: 48ca6d1840818e4a8977d00ed62cf0e8e0e5d193
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/reference.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,20 @@ methods in such an implementation can only be used as direct calls on the
16891689
values of the type that the implementation targets. In such an implementation,
16901690
the trait type and `for` after `impl` are omitted. Such implementations are
16911691
limited to nominal types (enums, structs), and the implementation must appear
1692-
in the same module or a sub-module as the `self` type.
1692+
in the same module or a sub-module as the `self` type:
1693+
1694+
```
1695+
struct Point {x: int, y: int}
1696+
1697+
impl Point {
1698+
fn log(&self) {
1699+
println!("Point is at ({}, {})", self.x, self.y);
1700+
}
1701+
}
1702+
1703+
let my_point = Point {x: 10, y:11};
1704+
my_point.log();
1705+
```
16931706

16941707
When a trait _is_ specified in an `impl`, all methods declared as part of the
16951708
trait must be implemented, with matching types and type parameter counts.

branches/auto/src/etc/emacs/rust-mode.el

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
(modify-syntax-entry ?\" "\"" table)
3232
(modify-syntax-entry ?\\ "\\" table)
3333

34-
;; _ is a word-char
35-
(modify-syntax-entry ?_ "w" table)
36-
3734
;; Comments
3835
(modify-syntax-entry ?/ ". 124b" table)
3936
(modify-syntax-entry ?* ". 23" table)
@@ -397,7 +394,7 @@ This is written mainly to be used as `beginning-of-defun-function' for Rust.
397394
Don't move to the beginning of the line. `beginning-of-defun',
398395
which calls this, does that afterwards."
399396
(interactive "p")
400-
(re-search-backward (concat "^\\(" rust-top-item-beg-re "\\)\\b")
397+
(re-search-backward (concat "^\\(" rust-top-item-beg-re "\\)\\_>")
401398
nil 'move (or arg 1)))
402399

403400
(defun rust-end-of-defun ()

branches/auto/src/libcollections/vec.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,14 +1248,18 @@ pub struct MoveItems<T> {
12481248
impl<T> MoveItems<T> {
12491249
#[inline]
12501250
/// Drops all items that have not yet been moved and returns the empty vector.
1251-
pub fn unwrap(mut self) -> Vec<T> {
1251+
pub fn into_inner(mut self) -> Vec<T> {
12521252
unsafe {
12531253
for _x in self { }
12541254
let MoveItems { allocation, cap, ptr: _ptr, end: _end } = self;
12551255
mem::forget(self);
12561256
Vec { ptr: allocation, cap: cap, len: 0 }
12571257
}
12581258
}
1259+
1260+
/// Deprecated, use into_inner() instead
1261+
#[deprecated = "renamed to into_inner()"]
1262+
pub fn unwrap(self) -> Vec<T> { self.into_inner() }
12591263
}
12601264

12611265
impl<T> Iterator<T> for MoveItems<T> {

branches/auto/src/libcore/cell.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,19 @@ impl<T> RefCell<T> {
256256
}
257257

258258
/// Consumes the `RefCell`, returning the wrapped value.
259-
#[unstable = "may be renamed, depending on global conventions"]
260-
pub fn unwrap(self) -> T {
259+
#[unstable = "recently renamed per RFC 430"]
260+
pub fn into_inner(self) -> T {
261261
// Since this function takes `self` (the `RefCell`) by value, the
262262
// compiler statically verifies that it is not currently borrowed.
263263
// Therefore the following assertion is just a `debug_assert!`.
264264
debug_assert!(self.borrow.get() == UNUSED);
265-
unsafe{self.value.unwrap()}
265+
unsafe { self.value.into_inner() }
266266
}
267267

268+
/// Deprecated, use into_inner() instead
269+
#[deprecated = "renamed to into_inner()"]
270+
pub fn unwrap(self) -> T { self.into_inner() }
271+
268272
/// Attempts to immutably borrow the wrapped value.
269273
///
270274
/// The borrow lasts until the returned `Ref` exits scope. Multiple
@@ -518,5 +522,9 @@ impl<T> UnsafeCell<T> {
518522
#[inline]
519523
#[unstable = "conventions around the name `unwrap` are still under \
520524
development"]
521-
pub unsafe fn unwrap(self) -> T { self.value }
525+
pub unsafe fn into_inner(self) -> T { self.value }
526+
527+
/// Deprecated, use into_inner() instead
528+
#[deprecated = "renamed to into_inner()"]
529+
pub unsafe fn unwrap(self) -> T { self.into_inner() }
522530
}

branches/auto/src/libcore/slice.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,21 @@ macro_rules! iterator {
11041104
}
11051105
}
11061106

1107+
macro_rules! make_slice {
1108+
($t: ty -> $result: ty: $start: expr, $end: expr) => {{
1109+
let diff = $end as uint - $start as uint;
1110+
let len = if mem::size_of::<T>() == 0 {
1111+
diff
1112+
} else {
1113+
diff / mem::size_of::<$t>()
1114+
};
1115+
unsafe {
1116+
transmute::<_, $result>(RawSlice { data: $start as *const T, len: len })
1117+
}
1118+
}}
1119+
}
1120+
1121+
11071122
/// Immutable slice iterator
11081123
#[experimental = "needs review"]
11091124
pub struct Items<'a, T: 'a> {
@@ -1112,6 +1127,36 @@ pub struct Items<'a, T: 'a> {
11121127
marker: marker::ContravariantLifetime<'a>
11131128
}
11141129

1130+
#[experimental]
1131+
impl<'a, T> ops::Slice<uint, [T]> for Items<'a, T> {
1132+
fn as_slice_(&self) -> &[T] {
1133+
self.as_slice()
1134+
}
1135+
fn slice_from_or_fail<'b>(&'b self, from: &uint) -> &'b [T] {
1136+
use ops::Slice;
1137+
self.as_slice().slice_from_or_fail(from)
1138+
}
1139+
fn slice_to_or_fail<'b>(&'b self, to: &uint) -> &'b [T] {
1140+
use ops::Slice;
1141+
self.as_slice().slice_to_or_fail(to)
1142+
}
1143+
fn slice_or_fail<'b>(&'b self, from: &uint, to: &uint) -> &'b [T] {
1144+
use ops::Slice;
1145+
self.as_slice().slice_or_fail(from, to)
1146+
}
1147+
}
1148+
1149+
impl<'a, T> Items<'a, T> {
1150+
/// View the underlying data as a subslice of the original data.
1151+
///
1152+
/// This has the same lifetime as the original slice, and so the
1153+
/// iterator can continue to be used while this exists.
1154+
#[experimental]
1155+
pub fn as_slice(&self) -> &'a [T] {
1156+
make_slice!(T -> &'a [T]: self.ptr, self.end)
1157+
}
1158+
}
1159+
11151160
iterator!{struct Items -> *const T, &'a T}
11161161

11171162
#[experimental = "needs review"]
@@ -1156,6 +1201,57 @@ pub struct MutItems<'a, T: 'a> {
11561201
marker2: marker::NoCopy
11571202
}
11581203

1204+
#[experimental]
1205+
impl<'a, T> ops::Slice<uint, [T]> for MutItems<'a, T> {
1206+
fn as_slice_<'b>(&'b self) -> &'b [T] {
1207+
make_slice!(T -> &'b [T]: self.ptr, self.end)
1208+
}
1209+
fn slice_from_or_fail<'b>(&'b self, from: &uint) -> &'b [T] {
1210+
use ops::Slice;
1211+
self.as_slice_().slice_from_or_fail(from)
1212+
}
1213+
fn slice_to_or_fail<'b>(&'b self, to: &uint) -> &'b [T] {
1214+
use ops::Slice;
1215+
self.as_slice_().slice_to_or_fail(to)
1216+
}
1217+
fn slice_or_fail<'b>(&'b self, from: &uint, to: &uint) -> &'b [T] {
1218+
use ops::Slice;
1219+
self.as_slice_().slice_or_fail(from, to)
1220+
}
1221+
}
1222+
1223+
#[experimental]
1224+
impl<'a, T> ops::SliceMut<uint, [T]> for MutItems<'a, T> {
1225+
fn as_mut_slice_<'b>(&'b mut self) -> &'b mut [T] {
1226+
make_slice!(T -> &'b mut [T]: self.ptr, self.end)
1227+
}
1228+
fn slice_from_or_fail_mut<'b>(&'b mut self, from: &uint) -> &'b mut [T] {
1229+
use ops::SliceMut;
1230+
self.as_mut_slice_().slice_from_or_fail_mut(from)
1231+
}
1232+
fn slice_to_or_fail_mut<'b>(&'b mut self, to: &uint) -> &'b mut [T] {
1233+
use ops::SliceMut;
1234+
self.as_mut_slice_().slice_to_or_fail_mut(to)
1235+
}
1236+
fn slice_or_fail_mut<'b>(&'b mut self, from: &uint, to: &uint) -> &'b mut [T] {
1237+
use ops::SliceMut;
1238+
self.as_mut_slice_().slice_or_fail_mut(from, to)
1239+
}
1240+
}
1241+
1242+
impl<'a, T> MutItems<'a, T> {
1243+
/// View the underlying data as a subslice of the original data.
1244+
///
1245+
/// To avoid creating `&mut` references that alias, this is forced
1246+
/// to consume the iterator. Consider using the `Slice` and
1247+
/// `SliceMut` implementations for obtaining slices with more
1248+
/// restricted lifetimes that do not consume the iterator.
1249+
#[experimental]
1250+
pub fn into_slice(self) -> &'a mut [T] {
1251+
make_slice!(T -> &'a mut [T]: self.ptr, self.end)
1252+
}
1253+
}
1254+
11591255
iterator!{struct MutItems -> *mut T, &'a mut T}
11601256

11611257
#[experimental = "needs review"]

branches/auto/src/libcore/str.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,14 +1277,19 @@ pub mod traits {
12771277
}
12781278

12791279
/// Any string that can be represented as a slice
1280-
pub trait Str {
1280+
pub trait Str for Sized? {
12811281
/// Work with `self` as a slice.
12821282
fn as_slice<'a>(&'a self) -> &'a str;
12831283
}
12841284

1285-
impl<'a> Str for &'a str {
1285+
impl Str for str {
12861286
#[inline]
1287-
fn as_slice<'a>(&'a self) -> &'a str { *self }
1287+
fn as_slice<'a>(&'a self) -> &'a str { self }
1288+
}
1289+
1290+
impl<'a, Sized? S> Str for &'a S where S: Str {
1291+
#[inline]
1292+
fn as_slice(&self) -> &str { Str::as_slice(*self) }
12881293
}
12891294

12901295
/// Methods for string slices

branches/auto/src/libcoretest/slice.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,52 @@ fn binary_search_not_found() {
3333
let b = [1i, 2, 4, 5, 6, 8];
3434
assert!(b.binary_search(|v| v.cmp(&9)) == NotFound(6));
3535
}
36+
37+
#[test]
38+
fn iterator_to_slice() {
39+
macro_rules! test {
40+
($data: expr) => {{
41+
let data: &mut [_] = &mut $data;
42+
let other_data: &mut [_] = &mut $data;
43+
44+
{
45+
let mut iter = data.iter();
46+
assert_eq!(iter[], other_data[]);
47+
48+
iter.next();
49+
assert_eq!(iter[], other_data[1..]);
50+
51+
iter.next_back();
52+
assert_eq!(iter[], other_data[1..2]);
53+
54+
let s = iter.as_slice();
55+
iter.next();
56+
assert_eq!(s, other_data[1..2]);
57+
}
58+
{
59+
let mut iter = data.iter_mut();
60+
assert_eq!(iter[], other_data[]);
61+
// mutability:
62+
assert!(iter[mut] == other_data);
63+
64+
iter.next();
65+
assert_eq!(iter[], other_data[1..]);
66+
assert!(iter[mut] == other_data[mut 1..]);
67+
68+
iter.next_back();
69+
70+
assert_eq!(iter[], other_data[1..2]);
71+
assert!(iter[mut] == other_data[mut 1..2]);
72+
73+
let s = iter.into_slice();
74+
assert!(s == other_data[mut 1..2]);
75+
}
76+
}}
77+
}
78+
79+
// try types of a variety of sizes
80+
test!([(1u64, 1u64, 1u8), (2, 2, 2), (3, 3, 3)]);
81+
test!([1u64,2,3]);
82+
test!([1u8,2,3]);
83+
test!([(),(),()]);
84+
}

branches/auto/src/librustc/lint/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,5 +827,5 @@ pub fn check_crate(tcx: &ty::ctxt,
827827
}
828828

829829
tcx.sess.abort_if_errors();
830-
*tcx.node_lint_levels.borrow_mut() = cx.node_levels.unwrap();
830+
*tcx.node_lint_levels.borrow_mut() = cx.node_levels.into_inner();
831831
}

branches/auto/src/librustc_llvm/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
21482148
pub fn build_string(f: |RustStringRef|) -> Option<String> {
21492149
let mut buf = RefCell::new(Vec::new());
21502150
f(&mut buf as RustStringRepr as RustStringRef);
2151-
String::from_utf8(buf.unwrap()).ok()
2151+
String::from_utf8(buf.into_inner()).ok()
21522152
}
21532153

21542154
pub unsafe fn twine_to_string(tr: TwineRef) -> String {

branches/auto/src/librustc_trans/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ fn run_work_multithreaded(sess: &Session,
899899

900900
let mut panicked = false;
901901
for future in futures.into_iter() {
902-
match future.unwrap() {
902+
match future.into_inner() {
903903
Ok(()) => {},
904904
Err(_) => {
905905
panicked = true;

branches/auto/src/librustc_trans/save/recorder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'a> FmtStrs<'a> {
171171

172172
let pairs = fields.iter().zip(values);
173173
let mut strs = pairs.map(|(f, v)| format!(",{},\"{}\"", f, escape(
174-
if *f == "qualname" {
174+
if *f == "qualname" && v.len() > 0 {
175175
let mut n = self.krate.clone();
176176
n.push_str("::");
177177
n.push_str(v);

branches/auto/src/librustc_trans/save/span_utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ impl<'a> SpanUtils<'a> {
293293
if ts.tok == token::Eof {
294294
return None
295295
} else {
296-
println!("found keyword: {} at {}", ts, ts.sp);
297296
return self.make_sub_span(span, Some(ts.sp));
298297
}
299298
}

branches/auto/src/librustrt/c_str.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,15 @@ impl CString {
254254
///
255255
/// Prefer `.as_ptr()` when just retrieving a pointer to the
256256
/// string data, as that does not relinquish ownership.
257-
pub unsafe fn unwrap(mut self) -> *const libc::c_char {
257+
pub unsafe fn into_inner(mut self) -> *const libc::c_char {
258258
self.owns_buffer_ = false;
259259
self.buf
260260
}
261261

262+
/// Deprecated, use into_inner() instead
263+
#[deprecated = "renamed to into_inner()"]
264+
pub unsafe fn unwrap(self) -> *const libc::c_char { self.into_inner() }
265+
262266
/// Return the number of bytes in the CString (not including the NUL
263267
/// terminator).
264268
#[inline]

branches/auto/src/libstd/c_vec.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,15 @@ impl<T> CVec<T> {
138138
/// Note that if you want to access the underlying pointer without
139139
/// cancelling the destructor, you can simply call `transmute` on the return
140140
/// value of `get(0)`.
141-
pub unsafe fn unwrap(mut self) -> *mut T {
141+
pub unsafe fn into_inner(mut self) -> *mut T {
142142
self.dtor = None;
143143
self.base
144144
}
145145

146+
/// Deprecated, use into_inner() instead
147+
#[deprecated = "renamed to into_inner()"]
148+
pub unsafe fn unwrap(self) -> *mut T { self.into_inner() }
149+
146150
/// Returns the number of items in this vector.
147151
pub fn len(&self) -> uint { self.len }
148152

0 commit comments

Comments
 (0)