Skip to content

Commit dbff0fd

Browse files
committed
---
yaml --- r: 275114 b: refs/heads/stable c: f93a62b h: refs/heads/master
1 parent 93a507f commit dbff0fd

File tree

15 files changed

+344
-19
lines changed

15 files changed

+344
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: c0221c8897db309a79990367476177b1230bb264
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 8ade08041294446fd44978a9a068cb3b30ca4001
32+
refs/heads/stable: f93a62b68def853ee86dec4e27fbc4068c25dd32
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
url = https://github.com/rust-lang/rust-installer.git
1717
[submodule "src/liblibc"]
1818
path = src/liblibc
19-
url = https://github.com/rust-lang-nursery/libc.git
19+
url = https://github.com/rust-lang/libc.git

branches/stable/mk/dist.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ PKG_FILES := \
4848
$(S)configure $(S)Makefile.in \
4949
$(S)man \
5050
$(addprefix $(S)src/, \
51+
bootstrap \
52+
build_helper \
5153
compiletest \
5254
doc \
5355
driver \
@@ -60,6 +62,7 @@ PKG_FILES := \
6062
rt \
6163
rtstartup \
6264
rustllvm \
65+
rustc \
6366
snapshots.txt \
6467
rust-installer \
6568
rustbook \

branches/stable/src/doc/book/guessing-game.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ done:
258258
io::stdin().read_line(&mut guess).expect("failed to read line");
259259
```
260260

261-
But that gets hard to read. So we’ve split it up, three lines for three method
261+
But that gets hard to read. So we’ve split it up, two lines for two method
262262
calls. We already talked about `read_line()`, but what about `expect()`? Well,
263263
we already mentioned that `read_line()` puts what the user types into the `&mut
264264
String` we pass it. But it also returns a value: in this case, an
@@ -644,7 +644,7 @@ So far, that hasn’t mattered, and so Rust defaults to an `i32`. However, here,
644644
Rust doesn’t know how to compare the `guess` and the `secret_number`. They
645645
need to be the same type. Ultimately, we want to convert the `String` we
646646
read as input into a real number type, for comparison. We can do that
647-
with three more lines. Here’s our new program:
647+
with two more lines. Here’s our new program:
648648
649649
```rust,ignore
650650
extern crate rand;

branches/stable/src/libcore/ptr.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,54 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
161161
intrinsics::move_val_init(&mut *dst, src)
162162
}
163163

164+
/// Performs a volatile read of the value from `src` without moving it. This
165+
/// leaves the memory in `src` unchanged.
166+
///
167+
/// Volatile operations are intended to act on I/O memory, and are guaranteed
168+
/// to not be elided or reordered by the compiler across other volatile
169+
/// operations. See the LLVM documentation on [[volatile]].
170+
///
171+
/// [volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses
172+
///
173+
/// # Safety
174+
///
175+
/// Beyond accepting a raw pointer, this is unsafe because it semantically
176+
/// moves the value out of `src` without preventing further usage of `src`.
177+
/// If `T` is not `Copy`, then care must be taken to ensure that the value at
178+
/// `src` is not used before the data is overwritten again (e.g. with `write`,
179+
/// `zero_memory`, or `copy_memory`). Note that `*src = foo` counts as a use
180+
/// because it will attempt to drop the value previously at `*src`.
181+
#[inline]
182+
#[unstable(feature = "volatile", reason = "recently added", issue = "31756")]
183+
pub unsafe fn read_volatile<T>(src: *const T) -> T {
184+
intrinsics::volatile_load(src)
185+
}
186+
187+
/// Performs a volatile write of a memory location with the given value without
188+
/// reading or dropping the old value.
189+
///
190+
/// Volatile operations are intended to act on I/O memory, and are guaranteed
191+
/// to not be elided or reordered by the compiler across other volatile
192+
/// operations. See the LLVM documentation on [[volatile]].
193+
///
194+
/// [volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses
195+
///
196+
/// # Safety
197+
///
198+
/// This operation is marked unsafe because it accepts a raw pointer.
199+
///
200+
/// It does not drop the contents of `dst`. This is safe, but it could leak
201+
/// allocations or resources, so care must be taken not to overwrite an object
202+
/// that should be dropped.
203+
///
204+
/// This is appropriate for initializing uninitialized memory, or overwriting
205+
/// memory that has previously been `read` from.
206+
#[inline]
207+
#[unstable(feature = "volatile", reason = "recently added", issue = "31756")]
208+
pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
209+
intrinsics::volatile_store(dst, src);
210+
}
211+
164212
#[lang = "const_ptr"]
165213
impl<T: ?Sized> *const T {
166214
/// Returns true if the pointer is null.

branches/stable/src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ declare_lint! {
132132

133133
declare_lint! {
134134
pub MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
135-
Warn,
135+
Deny,
136136
"unit struct or enum variant erroneously allowed to match via path::ident(..)"
137137
}
138138

branches/stable/src/libstd/ffi/os_str.rs

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,58 @@ impl OsString {
102102
pub fn push<T: AsRef<OsStr>>(&mut self, s: T) {
103103
self.inner.push_slice(&s.as_ref().inner)
104104
}
105+
106+
/// Creates a new `OsString` with the given capacity. The string will be
107+
/// able to hold exactly `capacity` bytes without reallocating. If
108+
/// `capacity` is 0, the string will not allocate.
109+
///
110+
/// See main `OsString` documentation information about encoding.
111+
#[unstable(feature = "osstring_simple_functions",
112+
reason = "recently added", issue = "29453")]
113+
pub fn with_capacity(capacity: usize) -> OsString {
114+
OsString {
115+
inner: Buf::with_capacity(capacity)
116+
}
117+
}
118+
119+
/// Truncates the `OsString` to zero length.
120+
#[unstable(feature = "osstring_simple_functions",
121+
reason = "recently added", issue = "29453")]
122+
pub fn clear(&mut self) {
123+
self.inner.clear()
124+
}
125+
126+
/// Returns the number of bytes this `OsString` can hold without
127+
/// reallocating.
128+
///
129+
/// See `OsString` introduction for information about encoding.
130+
#[unstable(feature = "osstring_simple_functions",
131+
reason = "recently added", issue = "29453")]
132+
pub fn capacity(&self) -> usize {
133+
self.inner.capacity()
134+
}
135+
136+
/// Reserves capacity for at least `additional` more bytes to be inserted
137+
/// in the given `OsString`. The collection may reserve more space to avoid
138+
/// frequent reallocations.
139+
#[unstable(feature = "osstring_simple_functions",
140+
reason = "recently added", issue = "29453")]
141+
pub fn reserve(&mut self, additional: usize) {
142+
self.inner.reserve(additional)
143+
}
144+
145+
/// Reserves the minimum capacity for exactly `additional` more bytes to be
146+
/// inserted in the given `OsString`. Does nothing if the capacity is
147+
/// already sufficient.
148+
///
149+
/// Note that the allocator may give the collection more space than it
150+
/// requests. Therefore capacity can not be relied upon to be precisely
151+
/// minimal. Prefer reserve if future insertions are expected.
152+
#[unstable(feature = "osstring_simple_functions",
153+
reason = "recently added", issue = "29453")]
154+
pub fn reserve_exact(&mut self, additional: usize) {
155+
self.inner.reserve_exact(additional)
156+
}
105157
}
106158

107159
#[stable(feature = "rust1", since = "1.0.0")]
@@ -277,6 +329,22 @@ impl OsStr {
277329
self.to_bytes().and_then(|b| CString::new(b).ok())
278330
}
279331

332+
/// Checks whether the `OsStr` is empty.
333+
#[unstable(feature = "osstring_simple_functions",
334+
reason = "recently added", issue = "29453")]
335+
pub fn is_empty(&self) -> bool {
336+
self.inner.inner.is_empty()
337+
}
338+
339+
/// Returns the number of bytes in this `OsStr`.
340+
///
341+
/// See `OsStr` introduction for information about encoding.
342+
#[unstable(feature = "osstring_simple_functions",
343+
reason = "recently added", issue = "29453")]
344+
pub fn len(&self) -> usize {
345+
self.inner.inner.len()
346+
}
347+
280348
/// Gets the underlying byte representation.
281349
///
282350
/// Note: it is *crucial* that this API is private, to avoid
@@ -414,3 +482,113 @@ impl AsInner<Slice> for OsStr {
414482
&self.inner
415483
}
416484
}
485+
486+
#[cfg(test)]
487+
mod tests {
488+
use super::*;
489+
use sys_common::{AsInner, IntoInner};
490+
491+
#[test]
492+
fn test_os_string_with_capacity() {
493+
let os_string = OsString::with_capacity(0);
494+
assert_eq!(0, os_string.inner.into_inner().capacity());
495+
496+
let os_string = OsString::with_capacity(10);
497+
assert_eq!(10, os_string.inner.into_inner().capacity());
498+
499+
let mut os_string = OsString::with_capacity(0);
500+
os_string.push("abc");
501+
assert!(os_string.inner.into_inner().capacity() >= 3);
502+
}
503+
504+
#[test]
505+
fn test_os_string_clear() {
506+
let mut os_string = OsString::from("abc");
507+
assert_eq!(3, os_string.inner.as_inner().len());
508+
509+
os_string.clear();
510+
assert_eq!(&os_string, "");
511+
assert_eq!(0, os_string.inner.as_inner().len());
512+
}
513+
514+
#[test]
515+
fn test_os_string_capacity() {
516+
let os_string = OsString::with_capacity(0);
517+
assert_eq!(0, os_string.capacity());
518+
519+
let os_string = OsString::with_capacity(10);
520+
assert_eq!(10, os_string.capacity());
521+
522+
let mut os_string = OsString::with_capacity(0);
523+
os_string.push("abc");
524+
assert!(os_string.capacity() >= 3);
525+
}
526+
527+
#[test]
528+
fn test_os_string_reserve() {
529+
let mut os_string = OsString::new();
530+
assert_eq!(os_string.capacity(), 0);
531+
532+
os_string.reserve(2);
533+
assert!(os_string.capacity() >= 2);
534+
535+
for _ in 0..16 {
536+
os_string.push("a");
537+
}
538+
539+
assert!(os_string.capacity() >= 16);
540+
os_string.reserve(16);
541+
assert!(os_string.capacity() >= 32);
542+
543+
os_string.push("a");
544+
545+
os_string.reserve(16);
546+
assert!(os_string.capacity() >= 33)
547+
}
548+
549+
#[test]
550+
fn test_os_string_reserve_exact() {
551+
let mut os_string = OsString::new();
552+
assert_eq!(os_string.capacity(), 0);
553+
554+
os_string.reserve_exact(2);
555+
assert!(os_string.capacity() >= 2);
556+
557+
for _ in 0..16 {
558+
os_string.push("a");
559+
}
560+
561+
assert!(os_string.capacity() >= 16);
562+
os_string.reserve_exact(16);
563+
assert!(os_string.capacity() >= 32);
564+
565+
os_string.push("a");
566+
567+
os_string.reserve_exact(16);
568+
assert!(os_string.capacity() >= 33)
569+
}
570+
571+
#[test]
572+
fn test_os_str_is_empty() {
573+
let mut os_string = OsString::new();
574+
assert!(os_string.is_empty());
575+
576+
os_string.push("abc");
577+
assert!(!os_string.is_empty());
578+
579+
os_string.clear();
580+
assert!(os_string.is_empty());
581+
}
582+
583+
#[test]
584+
fn test_os_str_len() {
585+
let mut os_string = OsString::new();
586+
assert_eq!(0, os_string.len());
587+
588+
os_string.push("abc");
589+
assert_eq!(3, os_string.len());
590+
591+
os_string.clear();
592+
assert_eq!(0, os_string.len());
593+
}
594+
}

branches/stable/src/libstd/sys/common/wtf8.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ impl Wtf8Buf {
178178
Wtf8Buf { bytes: <[_]>::to_vec(str.as_bytes()) }
179179
}
180180

181+
pub fn clear(&mut self) {
182+
self.bytes.clear()
183+
}
184+
181185
/// Creates a WTF-8 string from a potentially ill-formed UTF-16 slice of 16-bit code units.
182186
///
183187
/// This is lossless: calling `.encode_wide()` on the resulting string
@@ -234,6 +238,11 @@ impl Wtf8Buf {
234238
self.bytes.reserve(additional)
235239
}
236240

241+
#[inline]
242+
pub fn reserve_exact(&mut self, additional: usize) {
243+
self.bytes.reserve_exact(additional)
244+
}
245+
237246
/// Returns the number of bytes that this string buffer can hold without reallocating.
238247
#[inline]
239248
pub fn capacity(&self) -> usize {
@@ -443,6 +452,11 @@ impl Wtf8 {
443452
self.bytes.len()
444453
}
445454

455+
#[inline]
456+
pub fn is_empty(&self) -> bool {
457+
self.bytes.is_empty()
458+
}
459+
446460
/// Returns the code point at `position` if it is in the ASCII range,
447461
/// or `b'\xFF' otherwise.
448462
///

0 commit comments

Comments
 (0)