Skip to content

Commit 35f7533

Browse files
committed
---
yaml --- r: 207946 b: refs/heads/snap-stage3 c: 6b3d66b h: refs/heads/master v: v3
1 parent e710968 commit 35f7533

File tree

11 files changed

+202
-97
lines changed

11 files changed

+202
-97
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 38a97becdf3e6a6157f6f7ec2d98ade8d8edc193
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 715605faf9d32988bc7b2135a711c08e42a1871e
4+
refs/heads/snap-stage3: 6b3d66b04f9ade6b3a46db4eb188e7397b44117a
55
refs/heads/try: 7b4ef47b7805a402d756fb8157101f64880a522f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/compiletest/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
269269
run_ignored: config.run_ignored,
270270
logfile: config.logfile.clone(),
271271
run_tests: true,
272-
run_benchmarks: true,
272+
bench_benchmarks: true,
273273
nocapture: env::var("RUST_TEST_NOCAPTURE").is_ok(),
274274
color: test::AutoColor,
275275
}

branches/snap-stage3/src/doc/trpl/patterns.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ This prints `something else`
7070

7171
# Bindings
7272

73-
If you’re matching multiple things, via a `|` or a `...`, you can bind
74-
the value to a name with `@`:
73+
You can bind values to names with `@`:
7574

7675
```rust
7776
let x = 1;
@@ -82,7 +81,36 @@ match x {
8281
}
8382
```
8483

85-
This prints `got a range element 1`.
84+
This prints `got a range element 1`. This is useful when you want to
85+
do a complicated match of part of a data structure:
86+
87+
```rust
88+
#[derive(Debug)]
89+
struct Person {
90+
name: Option<String>,
91+
}
92+
93+
let name = "Steve".to_string();
94+
let mut x: Option<Person> = Some(Person { name: Some(name) });
95+
match x {
96+
Some(Person { name: ref a @ Some(_), .. }) => println!("{:?}", a),
97+
_ => {}
98+
}
99+
```
100+
101+
This prints `Some("Steve")`: We’ve bound the inner `name` to `a`.
102+
103+
If you use `@` with `|`, you need to make sure the name is bound in each part
104+
of the pattern:
105+
106+
```rust
107+
let x = 5;
108+
109+
match x {
110+
e @ 1 ... 5 | e @ 8 ... 10 => println!("got a range element {}", e),
111+
_ => println!("anything"),
112+
}
113+
```
86114

87115
# Ignoring variants
88116

branches/snap-stage3/src/libcollections/slice.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,11 +1004,7 @@ pub trait SliceConcatExt<T: ?Sized, U> {
10041004
/// # Examples
10051005
///
10061006
/// ```
1007-
/// let v = vec!["hello", "world"];
1008-
///
1009-
/// let s: String = v.concat();
1010-
///
1011-
/// println!("{}", s); // prints "helloworld"
1007+
/// assert_eq!(["hello", "world"].concat(), "helloworld");
10121008
/// ```
10131009
#[stable(feature = "rust1", since = "1.0.0")]
10141010
fn concat(&self) -> U;
@@ -1018,11 +1014,7 @@ pub trait SliceConcatExt<T: ?Sized, U> {
10181014
/// # Examples
10191015
///
10201016
/// ```
1021-
/// let v = vec!["hello", "world"];
1022-
///
1023-
/// let s: String = v.connect(" ");
1024-
///
1025-
/// println!("{}", s); // prints "hello world"
1017+
/// assert_eq!(["hello", "world"].connect(" "), "hello world");
10261018
/// ```
10271019
#[stable(feature = "rust1", since = "1.0.0")]
10281020
fn connect(&self, sep: &T) -> U;

branches/snap-stage3/src/libcore/cell.rs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
use clone::Clone;
145145
use cmp::PartialEq;
146146
use default::Default;
147-
use marker::{Copy, Send, Sync};
147+
use marker::{Copy, Send, Sync, Sized};
148148
use ops::{Deref, DerefMut, Drop};
149149
use option::Option;
150150
use option::Option::{None, Some};
@@ -266,9 +266,9 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
266266
///
267267
/// See the [module-level documentation](index.html) for more.
268268
#[stable(feature = "rust1", since = "1.0.0")]
269-
pub struct RefCell<T> {
270-
value: UnsafeCell<T>,
269+
pub struct RefCell<T: ?Sized> {
271270
borrow: Cell<BorrowFlag>,
271+
value: UnsafeCell<T>,
272272
}
273273

274274
/// An enumeration of values returned from the `state` method on a `RefCell<T>`.
@@ -328,7 +328,9 @@ impl<T> RefCell<T> {
328328
debug_assert!(self.borrow.get() == UNUSED);
329329
unsafe { self.value.into_inner() }
330330
}
331+
}
331332

333+
impl<T: ?Sized> RefCell<T> {
332334
/// Query the current state of this `RefCell`
333335
///
334336
/// The returned value can be dispatched on to determine if a call to
@@ -449,7 +451,7 @@ impl<T> RefCell<T> {
449451
}
450452

451453
#[stable(feature = "rust1", since = "1.0.0")]
452-
unsafe impl<T> Send for RefCell<T> where T: Send {}
454+
unsafe impl<T: ?Sized> Send for RefCell<T> where T: Send {}
453455

454456
#[stable(feature = "rust1", since = "1.0.0")]
455457
impl<T: Clone> Clone for RefCell<T> {
@@ -469,7 +471,7 @@ impl<T:Default> Default for RefCell<T> {
469471
}
470472

471473
#[stable(feature = "rust1", since = "1.0.0")]
472-
impl<T: PartialEq> PartialEq for RefCell<T> {
474+
impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
473475
#[inline]
474476
fn eq(&self, other: &RefCell<T>) -> bool {
475477
*self.borrow() == *other.borrow()
@@ -519,15 +521,15 @@ impl<'b> Clone for BorrowRef<'b> {
519521
///
520522
/// See the [module-level documentation](index.html) for more.
521523
#[stable(feature = "rust1", since = "1.0.0")]
522-
pub struct Ref<'b, T:'b> {
524+
pub struct Ref<'b, T: ?Sized + 'b> {
523525
// FIXME #12808: strange name to try to avoid interfering with
524526
// field accesses of the contained type via Deref
525527
_value: &'b T,
526528
_borrow: BorrowRef<'b>,
527529
}
528530

529531
#[stable(feature = "rust1", since = "1.0.0")]
530-
impl<'b, T> Deref for Ref<'b, T> {
532+
impl<'b, T: ?Sized> Deref for Ref<'b, T> {
531533
type Target = T;
532534

533535
#[inline]
@@ -582,15 +584,15 @@ impl<'b> BorrowRefMut<'b> {
582584
///
583585
/// See the [module-level documentation](index.html) for more.
584586
#[stable(feature = "rust1", since = "1.0.0")]
585-
pub struct RefMut<'b, T:'b> {
587+
pub struct RefMut<'b, T: ?Sized + 'b> {
586588
// FIXME #12808: strange name to try to avoid interfering with
587589
// field accesses of the contained type via Deref
588590
_value: &'b mut T,
589591
_borrow: BorrowRefMut<'b>,
590592
}
591593

592594
#[stable(feature = "rust1", since = "1.0.0")]
593-
impl<'b, T> Deref for RefMut<'b, T> {
595+
impl<'b, T: ?Sized> Deref for RefMut<'b, T> {
594596
type Target = T;
595597

596598
#[inline]
@@ -600,7 +602,7 @@ impl<'b, T> Deref for RefMut<'b, T> {
600602
}
601603

602604
#[stable(feature = "rust1", since = "1.0.0")]
603-
impl<'b, T> DerefMut for RefMut<'b, T> {
605+
impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> {
604606
#[inline]
605607
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
606608
self._value
@@ -633,7 +635,7 @@ impl<'b, T> DerefMut for RefMut<'b, T> {
633635
/// recommended to access its fields directly, `get` should be used instead.
634636
#[lang="unsafe_cell"]
635637
#[stable(feature = "rust1", since = "1.0.0")]
636-
pub struct UnsafeCell<T> {
638+
pub struct UnsafeCell<T: ?Sized> {
637639
/// Wrapped value
638640
///
639641
/// This field should not be accessed directly, it is made public for static
@@ -642,7 +644,7 @@ pub struct UnsafeCell<T> {
642644
pub value: T,
643645
}
644646

645-
impl<T> !Sync for UnsafeCell<T> {}
647+
impl<T: ?Sized> !Sync for UnsafeCell<T> {}
646648

647649
impl<T> UnsafeCell<T> {
648650
/// Constructs a new instance of `UnsafeCell` which will wrap the specified
@@ -664,7 +666,12 @@ impl<T> UnsafeCell<T> {
664666
UnsafeCell { value: value }
665667
}
666668

667-
/// Gets a mutable pointer to the wrapped value.
669+
/// Unwraps the value.
670+
///
671+
/// # Unsafety
672+
///
673+
/// This function is unsafe because there is no guarantee that this or other threads are
674+
/// currently inspecting the inner value.
668675
///
669676
/// # Examples
670677
///
@@ -673,22 +680,15 @@ impl<T> UnsafeCell<T> {
673680
///
674681
/// let uc = UnsafeCell::new(5);
675682
///
676-
/// let five = uc.get();
683+
/// let five = unsafe { uc.into_inner() };
677684
/// ```
678685
#[inline]
679686
#[stable(feature = "rust1", since = "1.0.0")]
680-
pub fn get(&self) -> *mut T {
681-
// FIXME(#23542) Replace with type ascription.
682-
#![allow(trivial_casts)]
683-
&self.value as *const T as *mut T
684-
}
687+
pub unsafe fn into_inner(self) -> T { self.value }
688+
}
685689

686-
/// Unwraps the value.
687-
///
688-
/// # Unsafety
689-
///
690-
/// This function is unsafe because there is no guarantee that this or other threads are
691-
/// currently inspecting the inner value.
690+
impl<T: ?Sized> UnsafeCell<T> {
691+
/// Gets a mutable pointer to the wrapped value.
692692
///
693693
/// # Examples
694694
///
@@ -697,9 +697,14 @@ impl<T> UnsafeCell<T> {
697697
///
698698
/// let uc = UnsafeCell::new(5);
699699
///
700-
/// let five = unsafe { uc.into_inner() };
700+
/// let five = uc.get();
701701
/// ```
702702
#[inline]
703703
#[stable(feature = "rust1", since = "1.0.0")]
704-
pub unsafe fn into_inner(self) -> T { self.value }
704+
pub fn get(&self) -> *mut T {
705+
// FIXME(#23542) Replace with type ascription.
706+
#![allow(trivial_casts)]
707+
&self.value as *const T as *mut T
708+
}
709+
705710
}

branches/snap-stage3/src/libcore/fmt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ impl<T: Copy + Debug> Debug for Cell<T> {
10621062
}
10631063

10641064
#[stable(feature = "rust1", since = "1.0.0")]
1065-
impl<T: Debug> Debug for RefCell<T> {
1065+
impl<T: ?Sized + Debug> Debug for RefCell<T> {
10661066
fn fmt(&self, f: &mut Formatter) -> Result {
10671067
match self.borrow_state() {
10681068
BorrowState::Unused | BorrowState::Reading => {
@@ -1074,14 +1074,14 @@ impl<T: Debug> Debug for RefCell<T> {
10741074
}
10751075

10761076
#[stable(feature = "rust1", since = "1.0.0")]
1077-
impl<'b, T: Debug> Debug for Ref<'b, T> {
1077+
impl<'b, T: ?Sized + Debug> Debug for Ref<'b, T> {
10781078
fn fmt(&self, f: &mut Formatter) -> Result {
10791079
Debug::fmt(&**self, f)
10801080
}
10811081
}
10821082

10831083
#[stable(feature = "rust1", since = "1.0.0")]
1084-
impl<'b, T: Debug> Debug for RefMut<'b, T> {
1084+
impl<'b, T: ?Sized + Debug> Debug for RefMut<'b, T> {
10851085
fn fmt(&self, f: &mut Formatter) -> Result {
10861086
Debug::fmt(&*(self.deref()), f)
10871087
}

branches/snap-stage3/src/libcoretest/cell.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,27 @@ fn refcell_default() {
159159
let cell: RefCell<u64> = Default::default();
160160
assert_eq!(0, *cell.borrow());
161161
}
162+
163+
#[test]
164+
fn unsafe_cell_unsized() {
165+
let cell: &UnsafeCell<[i32]> = &UnsafeCell::new([1, 2, 3]);
166+
{
167+
let val: &mut [i32] = unsafe { &mut *cell.get() };
168+
val[0] = 4;
169+
val[2] = 5;
170+
}
171+
let comp: &mut [i32] = &mut [4, 2, 5];
172+
assert_eq!(unsafe { &mut *cell.get() }, comp);
173+
}
174+
175+
#[test]
176+
fn refcell_unsized() {
177+
let cell: &RefCell<[i32]> = &RefCell::new([1, 2, 3]);
178+
{
179+
let b = &mut *cell.borrow_mut();
180+
b[0] = 4;
181+
b[2] = 5;
182+
}
183+
let comp: &mut [i32] = &mut [4, 2, 5];
184+
assert_eq!(&*cell.borrow(), comp);
185+
}

0 commit comments

Comments
 (0)