Skip to content

Commit d00e783

Browse files
committed
---
yaml --- r: 206343 b: refs/heads/beta c: 715605f h: refs/heads/master i: 206341: 1472b8f 206339: 36bf916 206335: 43d6830 v: v3
1 parent dc8a011 commit d00e783

File tree

13 files changed

+200
-204
lines changed

13 files changed

+200
-204
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3030
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3131
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32-
refs/heads/beta: 1a60dc4fc4b66760b71f1700cdb8b151cb8a67d9
32+
refs/heads/beta: 715605faf9d32988bc7b2135a711c08e42a1871e
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3535
refs/heads/tmp: 579e31929feff51dcaf8d444648eff8de735f91a

branches/beta/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-
bench_benchmarks: true,
272+
run_benchmarks: true,
273273
nocapture: env::var("RUST_TEST_NOCAPTURE").is_ok(),
274274
color: test::AutoColor,
275275
}

branches/beta/src/doc/trpl/patterns.md

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

7171
# Bindings
7272

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

7576
```rust
7677
let x = 1;
@@ -81,36 +82,7 @@ match x {
8182
}
8283
```
8384

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-
```
85+
This prints `got a range element 1`.
11486

11587
# Ignoring variants
11688

branches/beta/src/libcollections/slice.rs

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

branches/beta/src/libcore/cell.rs

Lines changed: 27 additions & 32 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, Sized};
147+
use marker::{Copy, Send, Sync};
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: ?Sized> {
270-
borrow: Cell<BorrowFlag>,
269+
pub struct RefCell<T> {
271270
value: UnsafeCell<T>,
271+
borrow: Cell<BorrowFlag>,
272272
}
273273

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

333-
impl<T: ?Sized> RefCell<T> {
334332
/// Query the current state of this `RefCell`
335333
///
336334
/// The returned value can be dispatched on to determine if a call to
@@ -451,7 +449,7 @@ impl<T: ?Sized> RefCell<T> {
451449
}
452450

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

456454
#[stable(feature = "rust1", since = "1.0.0")]
457455
impl<T: Clone> Clone for RefCell<T> {
@@ -471,7 +469,7 @@ impl<T:Default> Default for RefCell<T> {
471469
}
472470

473471
#[stable(feature = "rust1", since = "1.0.0")]
474-
impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
472+
impl<T: PartialEq> PartialEq for RefCell<T> {
475473
#[inline]
476474
fn eq(&self, other: &RefCell<T>) -> bool {
477475
*self.borrow() == *other.borrow()
@@ -521,15 +519,15 @@ impl<'b> Clone for BorrowRef<'b> {
521519
///
522520
/// See the [module-level documentation](index.html) for more.
523521
#[stable(feature = "rust1", since = "1.0.0")]
524-
pub struct Ref<'b, T: ?Sized + 'b> {
522+
pub struct Ref<'b, T:'b> {
525523
// FIXME #12808: strange name to try to avoid interfering with
526524
// field accesses of the contained type via Deref
527525
_value: &'b T,
528526
_borrow: BorrowRef<'b>,
529527
}
530528

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

535533
#[inline]
@@ -584,15 +582,15 @@ impl<'b> BorrowRefMut<'b> {
584582
///
585583
/// See the [module-level documentation](index.html) for more.
586584
#[stable(feature = "rust1", since = "1.0.0")]
587-
pub struct RefMut<'b, T: ?Sized + 'b> {
585+
pub struct RefMut<'b, T:'b> {
588586
// FIXME #12808: strange name to try to avoid interfering with
589587
// field accesses of the contained type via Deref
590588
_value: &'b mut T,
591589
_borrow: BorrowRefMut<'b>,
592590
}
593591

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

598596
#[inline]
@@ -602,7 +600,7 @@ impl<'b, T: ?Sized> Deref for RefMut<'b, T> {
602600
}
603601

604602
#[stable(feature = "rust1", since = "1.0.0")]
605-
impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> {
603+
impl<'b, T> DerefMut for RefMut<'b, T> {
606604
#[inline]
607605
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
608606
self._value
@@ -635,7 +633,7 @@ impl<'b, T: ?Sized> DerefMut for RefMut<'b, T> {
635633
/// recommended to access its fields directly, `get` should be used instead.
636634
#[lang="unsafe_cell"]
637635
#[stable(feature = "rust1", since = "1.0.0")]
638-
pub struct UnsafeCell<T: ?Sized> {
636+
pub struct UnsafeCell<T> {
639637
/// Wrapped value
640638
///
641639
/// This field should not be accessed directly, it is made public for static
@@ -644,7 +642,7 @@ pub struct UnsafeCell<T: ?Sized> {
644642
pub value: T,
645643
}
646644

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

649647
impl<T> UnsafeCell<T> {
650648
/// Constructs a new instance of `UnsafeCell` which will wrap the specified
@@ -666,12 +664,7 @@ impl<T> UnsafeCell<T> {
666664
UnsafeCell { value: value }
667665
}
668666

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.
667+
/// Gets a mutable pointer to the wrapped value.
675668
///
676669
/// # Examples
677670
///
@@ -680,15 +673,22 @@ impl<T> UnsafeCell<T> {
680673
///
681674
/// let uc = UnsafeCell::new(5);
682675
///
683-
/// let five = unsafe { uc.into_inner() };
676+
/// let five = uc.get();
684677
/// ```
685678
#[inline]
686679
#[stable(feature = "rust1", since = "1.0.0")]
687-
pub unsafe fn into_inner(self) -> T { self.value }
688-
}
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+
}
689685

690-
impl<T: ?Sized> UnsafeCell<T> {
691-
/// Gets a mutable pointer to the wrapped value.
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.
692692
///
693693
/// # Examples
694694
///
@@ -697,14 +697,9 @@ impl<T: ?Sized> UnsafeCell<T> {
697697
///
698698
/// let uc = UnsafeCell::new(5);
699699
///
700-
/// let five = uc.get();
700+
/// let five = unsafe { uc.into_inner() };
701701
/// ```
702702
#[inline]
703703
#[stable(feature = "rust1", since = "1.0.0")]
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-
704+
pub unsafe fn into_inner(self) -> T { self.value }
710705
}

branches/beta/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: ?Sized + Debug> Debug for RefCell<T> {
1065+
impl<T: 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: ?Sized + Debug> Debug for RefCell<T> {
10741074
}
10751075

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

branches/beta/src/libcoretest/cell.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -159,27 +159,3 @@ 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-
}

branches/beta/src/librustc_trans/trans/_match.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ use trans::consts;
210210
use trans::datum::*;
211211
use trans::debuginfo::{self, DebugLoc, ToDebugLoc};
212212
use trans::expr::{self, Dest};
213+
use trans::monomorphize;
213214
use trans::tvec;
214215
use trans::type_of;
215216
use middle::ty::{self, Ty};
@@ -1076,9 +1077,39 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
10761077
let adt_vals = if any_irrefutable_adt_pat(bcx.tcx(), m, col) {
10771078
let repr = adt::represent_type(bcx.ccx(), left_ty);
10781079
let arg_count = adt::num_args(&*repr, 0);
1079-
let field_vals: Vec<ValueRef> = (0..arg_count).map(|ix|
1080-
adt::trans_field_ptr(bcx, &*repr, val, 0, ix)
1080+
let (arg_count, struct_val) = if type_is_sized(bcx.tcx(), left_ty) {
1081+
(arg_count, val)
1082+
} else {
1083+
// For an unsized ADT (i.e. DST struct), we need to treat
1084+
// the last field specially: instead of simply passing a
1085+
// ValueRef pointing to that field, as with all the others,
1086+
// we skip it and instead construct a 'fat ptr' below.
1087+
(arg_count - 1, Load(bcx, expr::get_dataptr(bcx, val)))
1088+
};
1089+
let mut field_vals: Vec<ValueRef> = (0..arg_count).map(|ix|
1090+
adt::trans_field_ptr(bcx, &*repr, struct_val, 0, ix)
10811091
).collect();
1092+
1093+
match left_ty.sty {
1094+
ty::ty_struct(def_id, substs) if !type_is_sized(bcx.tcx(), left_ty) => {
1095+
// The last field is technically unsized but
1096+
// since we can only ever match that field behind
1097+
// a reference we construct a fat ptr here.
1098+
let fields = ty::lookup_struct_fields(bcx.tcx(), def_id);
1099+
let unsized_ty = fields.iter().last().map(|field| {
1100+
let fty = ty::lookup_field_type(bcx.tcx(), def_id, field.id, substs);
1101+
monomorphize::normalize_associated_type(bcx.tcx(), &fty)
1102+
}).unwrap();
1103+
let llty = type_of::type_of(bcx.ccx(), unsized_ty);
1104+
let scratch = alloca_no_lifetime(bcx, llty, "__struct_field_fat_ptr");
1105+
let data = adt::trans_field_ptr(bcx, &*repr, struct_val, 0, arg_count);
1106+
let len = Load(bcx, expr::get_len(bcx, val));
1107+
Store(bcx, data, expr::get_dataptr(bcx, scratch));
1108+
Store(bcx, len, expr::get_len(bcx, scratch));
1109+
field_vals.push(scratch);
1110+
}
1111+
_ => {}
1112+
}
10821113
Some(field_vals)
10831114
} else if any_uniq_pat(m, col) || any_region_pat(m, col) {
10841115
Some(vec!(Load(bcx, val)))

0 commit comments

Comments
 (0)