Skip to content

Commit 0ca80aa

Browse files
committed
---
yaml --- r: 158652 b: refs/heads/master c: 223ca76 h: refs/heads/master v: v3
1 parent 90991d1 commit 0ca80aa

File tree

12 files changed

+148
-15
lines changed

12 files changed

+148
-15
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: d8ab2f87c1705bff4f212cfb6d00ee4770abc1e1
2+
refs/heads/master: 223ca7643976c89c76d78337a5f7a9b1677cc0f1
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 1b2ad7831f1745bf4a4709a1fa1772afb47c933c
55
refs/heads/try: f58aad6dce273570fb130b4df008ef9acd5a5be2

trunk/src/liballoc/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<T: Send + Sync + Clone> Arc<T> {
166166
// additional reference of either kind.
167167
if self.inner().strong.load(atomic::SeqCst) != 1 ||
168168
self.inner().weak.load(atomic::SeqCst) != 1 {
169-
*self = Arc::new(self.deref().clone())
169+
*self = Arc::new((**self).clone())
170170
}
171171
// This unsafety is ok because we're guaranteed that the pointer
172172
// returned is the *only* pointer that will ever be returned to T. Our

trunk/src/libcore/ops.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ shr_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64)
638638
* ```
639639
*/
640640
#[lang="index"]
641-
pub trait Index<Index, Sized? Result> {
641+
pub trait Index<Index, Sized? Result> for Sized? {
642642
/// The method for the indexing (`Foo[Bar]`) operation
643643
fn index<'a>(&'a self, index: &Index) -> &'a Result;
644644
}
@@ -669,7 +669,7 @@ pub trait Index<Index, Sized? Result> {
669669
* ```
670670
*/
671671
#[lang="index_mut"]
672-
pub trait IndexMut<Index, Result> {
672+
pub trait IndexMut<Index, Result> for Sized? {
673673
/// The method for the indexing (`Foo[Bar]`) operation
674674
fn index_mut<'a>(&'a mut self, index: &Index) -> &'a mut Result;
675675
}
@@ -805,6 +805,16 @@ pub trait Deref<Sized? Result> {
805805
fn deref<'a>(&'a self) -> &'a Result;
806806
}
807807

808+
#[cfg(not(stage0))]
809+
impl<'a, Sized? T> Deref<T> for &'a T {
810+
fn deref(&self) -> &T { *self }
811+
}
812+
813+
#[cfg(not(stage0))]
814+
impl<'a, Sized? T> Deref<T> for &'a mut T {
815+
fn deref(&self) -> &T { *self }
816+
}
817+
808818
/**
809819
*
810820
* The `DerefMut` trait is used to specify the functionality of dereferencing
@@ -845,6 +855,11 @@ pub trait DerefMut<Sized? Result>: Deref<Result> {
845855
fn deref_mut<'a>(&'a mut self) -> &'a mut Result;
846856
}
847857

858+
#[cfg(not(stage0))]
859+
impl<'a, Sized? T> DerefMut<T> for &'a mut T {
860+
fn deref_mut(&mut self) -> &mut T { *self }
861+
}
862+
848863
/// A version of the call operator that takes an immutable receiver.
849864
#[lang="fn"]
850865
pub trait Fn<Args,Result> {

trunk/src/libcore/slice.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ pub trait SlicePrelude<T> for Sized? {
256256
#[inline]
257257
#[experimental = "not triaged yet"]
258258
fn is_empty(&self) -> bool { self.len() == 0 }
259-
260259
/// Returns a mutable reference to the element at the given index,
261260
/// or `None` if the index is out of bounds
262261
#[unstable = "waiting on final error conventions"]
@@ -698,6 +697,22 @@ impl<T> SlicePrelude<T> for [T] {
698697
}
699698
}
700699

700+
impl<T> ops::Index<uint, T> for [T] {
701+
fn index(&self, &index: &uint) -> &T {
702+
assert!(index < self.len());
703+
704+
unsafe { mem::transmute(self.repr().data.offset(index as int)) }
705+
}
706+
}
707+
708+
impl<T> ops::IndexMut<uint, T> for [T] {
709+
fn index_mut(&mut self, &index: &uint) -> &mut T {
710+
assert!(index < self.len());
711+
712+
unsafe { mem::transmute(self.repr().data.offset(index as int)) }
713+
}
714+
}
715+
701716
impl<T> ops::Slice<uint, [T]> for [T] {
702717
#[inline]
703718
fn as_slice_<'a>(&'a self) -> &'a [T] {

trunk/src/librustc/middle/cfg/construct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
448448
}
449449

450450
ast::ExprStruct(_, ref fields, ref base) => {
451-
let base_exit = self.opt_expr(base, pred);
452-
self.straightline(expr, base_exit, fields.iter().map(|f| &*f.expr))
451+
let field_cfg = self.straightline(expr, pred, fields.iter().map(|f| &*f.expr));
452+
self.opt_expr(base, field_cfg)
453453
}
454454

455455
ast::ExprRepeat(ref elem, ref count) => {

trunk/src/librustc/middle/expr_use_visitor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,10 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> {
672672
}
673673
}
674674

675+
// walk the with expression so that complex expressions
676+
// are properly handled.
677+
self.walk_expr(with_expr);
678+
675679
fn contains_field_named(field: &ty::field,
676680
fields: &Vec<ast::Field>)
677681
-> bool

trunk/src/librustc/middle/typeck/check/method.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,13 +1702,18 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
17021702
PreferMutLvalue);
17031703
}
17041704
ast::ExprUnary(ast::UnDeref, ref base_expr) => {
1705-
check::try_overloaded_deref(
1706-
self.fcx,
1707-
expr.span,
1708-
Some(MethodCall::expr(expr.id)),
1709-
Some(&**base_expr),
1710-
self.fcx.expr_ty(&**base_expr),
1711-
PreferMutLvalue);
1705+
// if this is an overloaded deref, then re-evaluate with
1706+
// a preference for mut
1707+
let method_call = MethodCall::expr(expr.id);
1708+
if self.fcx.inh.method_map.borrow().contains_key(&method_call) {
1709+
check::try_overloaded_deref(
1710+
self.fcx,
1711+
expr.span,
1712+
Some(method_call),
1713+
Some(&**base_expr),
1714+
self.fcx.expr_ty(&**base_expr),
1715+
PreferMutLvalue);
1716+
}
17121717
}
17131718
_ => {}
17141719
}

trunk/src/libstd/collections/hash/table.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,22 @@ impl<K, V> RawBucket<K, V> {
166166
}
167167

168168
// For parameterizing over mutability.
169+
170+
#[cfg(stage0)]
169171
impl<'t, K, V> Deref<RawTable<K, V>> for &'t RawTable<K, V> {
170172
fn deref(&self) -> &RawTable<K, V> {
171173
&**self
172174
}
173175
}
174176

177+
#[cfg(stage0)]
175178
impl<'t, K, V> Deref<RawTable<K, V>> for &'t mut RawTable<K, V> {
176179
fn deref(&self) -> &RawTable<K,V> {
177180
&**self
178181
}
179182
}
180183

184+
#[cfg(stage0)]
181185
impl<'t, K, V> DerefMut<RawTable<K, V>> for &'t mut RawTable<K, V> {
182186
fn deref_mut(&mut self) -> &mut RawTable<K,V> {
183187
&mut **self

trunk/src/libstd/num/strconv.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ pub fn from_str_radix_float<T: Float>(src: &str, radix: uint) -> Option<T> {
451451
};
452452

453453
// The significand to accumulate
454-
let mut sig = if is_positive { _0 } else { -_1 };
454+
let mut sig = if is_positive { _0 } else { -_0 };
455455
// Necessary to detect overflow
456456
let mut prev_sig = sig;
457457
let mut cs = src.chars().enumerate();
@@ -647,6 +647,22 @@ mod test {
647647
let fe : Option<f32> = from_str_radix_float("1e40", 10);
648648
assert_eq!(fe, Some(Float::infinity()))
649649
}
650+
651+
#[test]
652+
fn test_from_str_radix_float() {
653+
let x1 : Option<f64> = from_str_radix_float("-123.456", 10);
654+
assert_eq!(x1, Some(-123.456));
655+
let x2 : Option<f32> = from_str_radix_float("123.456", 10);
656+
assert_eq!(x2, Some(123.456));
657+
let x3 : Option<f32> = from_str_radix_float("-0.0", 10);
658+
assert_eq!(x3, Some(-0.0));
659+
let x4 : Option<f32> = from_str_radix_float("0.0", 10);
660+
assert_eq!(x4, Some(0.0));
661+
let x4 : Option<f32> = from_str_radix_float("1.0", 10);
662+
assert_eq!(x4, Some(1.0));
663+
let x5 : Option<f32> = from_str_radix_float("-1.0", 10);
664+
assert_eq!(x5, Some(-1.0));
665+
}
650666
}
651667

652668
#[cfg(test)]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Mine{
12+
test: String,
13+
other_val: int
14+
}
15+
16+
impl Mine{
17+
fn make_string_bar(mut self) -> Mine{
18+
self.test = "Bar".to_string();
19+
self
20+
}
21+
}
22+
23+
fn main(){
24+
let start = Mine{test:"Foo".to_string(), other_val:0};
25+
let end = Mine{other_val:1, ..start.make_string_bar()};
26+
println!("{}", start.test); //~ ERROR use of moved value: `start.test`
27+
}
28+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that `&mut T` implements `DerefMut<T>`
12+
13+
fn inc<T:DerefMut<int>>(mut t: T) {
14+
*t += 1;
15+
}
16+
17+
fn main() {
18+
let mut x: int = 5;
19+
inc(&mut x);
20+
assert_eq!(x, 6);
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that `&T` and `&mut T` implement `Deref<T>`
12+
13+
fn deref<U:Copy,T:Deref<U>>(t: T) -> U {
14+
*t
15+
}
16+
17+
fn main() {
18+
let x: int = 3;
19+
let y = deref(&x);
20+
assert_eq!(y, 3);
21+
22+
let mut x: int = 4;
23+
let y = deref(&mut x);
24+
assert_eq!(y, 4);
25+
}

0 commit comments

Comments
 (0)