Skip to content

Commit 969ae6d

Browse files
committed
---
yaml --- r: 130154 b: refs/heads/master c: 8a89867 h: refs/heads/master v: v3
1 parent 00b5ae8 commit 969ae6d

26 files changed

+215
-63
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: 69a9d23d58cc0efff107d25e9a4f9f7a4239b004
2+
refs/heads/master: 8a8986776d16c16ef4685aa38c3f6a2c0efa7884
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 67b97ab6d2b7de9b69fd97dc171fcf8feec932ff
55
refs/heads/try: 28d5878c1f0465c11c8e7a3085008b0c592d48d0

trunk/src/libnum/complex.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
//! Complex numbers.
1313
1414
use std::fmt;
15-
use std::num::{Zero,One,ToStrRadix};
15+
use std::num::{Zero, One, ToStrRadix};
1616

1717
// FIXME #1284: handle complex NaN & infinity etc. This
1818
// probably doesn't map to C's _Complex correctly.
1919

2020
/// A complex number in Cartesian form.
21-
#[deriving(PartialEq,Clone)]
21+
#[deriving(PartialEq, Clone, Hash)]
2222
pub struct Complex<T> {
2323
/// Real portion of the complex number
2424
pub re: T,
@@ -36,10 +36,8 @@ impl<T: Clone + Num> Complex<T> {
3636
Complex { re: re, im: im }
3737
}
3838

39-
/**
40-
Returns the square of the norm (since `T` doesn't necessarily
41-
have a sqrt function), i.e. `re^2 + im^2`.
42-
*/
39+
/// Returns the square of the norm (since `T` doesn't necessarily
40+
/// have a sqrt function), i.e. `re^2 + im^2`.
4341
#[inline]
4442
pub fn norm_sqr(&self) -> T {
4543
self.re * self.re + self.im * self.im
@@ -193,7 +191,8 @@ mod test {
193191
#![allow(non_uppercase_statics)]
194192

195193
use super::{Complex64, Complex};
196-
use std::num::{Zero,One,Float};
194+
use std::num::{Zero, One, Float};
195+
use std::hash::hash;
197196

198197
pub static _0_0i : Complex64 = Complex { re: 0.0, im: 0.0 };
199198
pub static _1_0i : Complex64 = Complex { re: 1.0, im: 0.0 };
@@ -367,4 +366,14 @@ mod test {
367366
test(-_neg1_1i, "1-1i".to_string());
368367
test(_05_05i, "0.5+0.5i".to_string());
369368
}
369+
370+
#[test]
371+
fn test_hash() {
372+
let a = Complex::new(0i32, 0i32);
373+
let b = Complex::new(1i32, 0i32);
374+
let c = Complex::new(0i32, 1i32);
375+
assert!(hash(&a) != hash(&b));
376+
assert!(hash(&b) != hash(&c));
377+
assert!(hash(&c) != hash(&a));
378+
}
370379
}

trunk/src/libnum/rational.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::num::{Zero, One, ToStrRadix, FromStrRadix};
2121
use bigint::{BigInt, BigUint, Sign, Plus, Minus};
2222

2323
/// Represents the ratio between 2 numbers.
24-
#[deriving(Clone)]
24+
#[deriving(Clone, Hash)]
2525
#[allow(missing_doc)]
2626
pub struct Ratio<T> {
2727
numer: T,
@@ -380,6 +380,7 @@ mod test {
380380
use super::{Ratio, Rational, BigRational};
381381
use std::num::{Zero, One, FromStrRadix, FromPrimitive, ToStrRadix};
382382
use std::from_str::FromStr;
383+
use std::hash::hash;
383384
use std::num;
384385

385386
pub static _0 : Rational = Ratio { numer: 0, denom: 1};
@@ -751,4 +752,10 @@ mod test {
751752
assert!(! _neg1_2.is_positive());
752753
assert!(! _1_2.is_negative());
753754
}
755+
756+
#[test]
757+
fn test_hash() {
758+
assert!(hash(&_0) != hash(&_1));
759+
assert!(hash(&_0) != hash(&_3_2));
760+
}
754761
}

trunk/src/librustc/front/test.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ struct TestCtxt<'a> {
5050
path: Vec<ast::Ident>,
5151
ext_cx: ExtCtxt<'a>,
5252
testfns: Vec<Test>,
53-
reexport_mod_ident: ast::Ident,
5453
reexport_test_harness_main: Option<InternedString>,
5554
is_test_crate: bool,
5655
config: ast::CrateConfig,
56+
57+
// top-level re-export submodule, filled out after folding is finished
58+
toplevel_reexport: Option<ast::Ident>,
5759
}
5860

5961
// Traverse the crate, collecting all the test functions, eliding any
@@ -83,7 +85,9 @@ pub fn modify_for_testing(sess: &Session,
8385
struct TestHarnessGenerator<'a> {
8486
cx: TestCtxt<'a>,
8587
tests: Vec<ast::Ident>,
86-
tested_submods: Vec<ast::Ident>,
88+
89+
// submodule name, gensym'd identifier for re-exports
90+
tested_submods: Vec<(ast::Ident, ast::Ident)>,
8791
}
8892

8993
impl<'a> fold::Folder for TestHarnessGenerator<'a> {
@@ -168,10 +172,14 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
168172
*i = nomain(*i);
169173
}
170174
if !tests.is_empty() || !tested_submods.is_empty() {
171-
mod_folded.items.push(mk_reexport_mod(&mut self.cx, tests,
172-
tested_submods));
175+
let (it, sym) = mk_reexport_mod(&mut self.cx, tests, tested_submods);
176+
mod_folded.items.push(it);
177+
173178
if !self.cx.path.is_empty() {
174-
self.tested_submods.push(self.cx.path[self.cx.path.len()-1]);
179+
self.tested_submods.push((self.cx.path[self.cx.path.len()-1], sym));
180+
} else {
181+
debug!("pushing nothing, sym: {}", sym);
182+
self.cx.toplevel_reexport = Some(sym);
175183
}
176184
}
177185

@@ -180,16 +188,16 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
180188
}
181189

182190
fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec<ast::Ident>,
183-
tested_submods: Vec<ast::Ident>) -> Gc<ast::Item> {
191+
tested_submods: Vec<(ast::Ident, ast::Ident)>) -> (Gc<ast::Item>, ast::Ident) {
184192
let mut view_items = Vec::new();
185193
let super_ = token::str_to_ident("super");
186194

187195
view_items.extend(tests.move_iter().map(|r| {
188196
cx.ext_cx.view_use_simple(DUMMY_SP, ast::Public,
189197
cx.ext_cx.path(DUMMY_SP, vec![super_, r]))
190198
}));
191-
view_items.extend(tested_submods.move_iter().map(|r| {
192-
let path = cx.ext_cx.path(DUMMY_SP, vec![super_, r, cx.reexport_mod_ident]);
199+
view_items.extend(tested_submods.move_iter().map(|(r, sym)| {
200+
let path = cx.ext_cx.path(DUMMY_SP, vec![super_, r, sym]);
193201
cx.ext_cx.view_use_simple_(DUMMY_SP, ast::Public, r, path)
194202
}));
195203

@@ -198,14 +206,18 @@ fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec<ast::Ident>,
198206
view_items: view_items,
199207
items: Vec::new(),
200208
};
201-
box(GC) ast::Item {
202-
ident: cx.reexport_mod_ident.clone(),
209+
210+
let sym = token::gensym_ident("__test_reexports");
211+
let it = box(GC) ast::Item {
212+
ident: sym.clone(),
203213
attrs: Vec::new(),
204214
id: ast::DUMMY_NODE_ID,
205215
node: ast::ItemMod(reexport_mod),
206216
vis: ast::Public,
207217
span: DUMMY_SP,
208-
}
218+
};
219+
220+
(it, sym)
209221
}
210222

211223
fn generate_test_harness(sess: &Session,
@@ -220,10 +232,10 @@ fn generate_test_harness(sess: &Session,
220232
}),
221233
path: Vec::new(),
222234
testfns: Vec::new(),
223-
reexport_mod_ident: token::gensym_ident("__test_reexports"),
224235
reexport_test_harness_main: reexport_test_harness_main,
225236
is_test_crate: is_test_crate(&krate),
226237
config: krate.config.clone(),
238+
toplevel_reexport: None,
227239
};
228240

229241
cx.ext_cx.bt_push(ExpnInfo {
@@ -530,7 +542,14 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> Gc<ast::Expr> {
530542
field("should_fail", fail_expr)]);
531543

532544

533-
let mut visible_path = vec![cx.reexport_mod_ident.clone()];
545+
let mut visible_path = match cx.toplevel_reexport {
546+
Some(id) => vec![id],
547+
None => {
548+
cx.sess.bug(
549+
"expected to find top-level re-export name, but found None"
550+
);
551+
}
552+
};
534553
visible_path.extend(path.move_iter());
535554

536555
let fn_expr = ecx.expr_path(ecx.path_global(span, visible_path));

trunk/src/librustc/middle/trans/cleanup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
640640
while !popped_scopes.is_empty() {
641641
let mut scope = popped_scopes.pop().unwrap();
642642

643-
if scope.cleanups.iter().any(|c| cleanup_is_suitable_for(*c, label))
643+
if scope.cleanups.iter().any(|c| cleanup_is_suitable_for(&**c, label))
644644
{
645645
let name = scope.block_name("clean");
646646
debug!("generating cleanups for {}", name);
@@ -649,7 +649,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
649649
None);
650650
let mut bcx_out = bcx_in;
651651
for cleanup in scope.cleanups.iter().rev() {
652-
if cleanup_is_suitable_for(*cleanup, label) {
652+
if cleanup_is_suitable_for(&**cleanup, label) {
653653
bcx_out = cleanup.trans(bcx_out);
654654
}
655655
}

trunk/src/librustc/middle/trans/consts.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn const_deref(cx: &CrateContext, v: ValueRef, t: ty::t, explicit: bool)
170170
}
171171
}
172172
None => {
173-
cx.sess().bug(format!("can't dereference const of type {}",
173+
cx.sess().bug(format!("cannot dereference const of type {}",
174174
ty_to_string(cx.tcx(), t)).as_slice())
175175
}
176176
}
@@ -225,10 +225,12 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
225225
ty::AutoDerefRef(ref adj) => {
226226
let mut ty = ety;
227227
// Save the last autoderef in case we can avoid it.
228-
for _ in range(0, adj.autoderefs-1) {
229-
let (dv, dt) = const_deref(cx, llconst, ty, false);
230-
llconst = dv;
231-
ty = dt;
228+
if adj.autoderefs > 0 {
229+
for _ in range(0, adj.autoderefs-1) {
230+
let (dv, dt) = const_deref(cx, llconst, ty, false);
231+
llconst = dv;
232+
ty = dt;
233+
}
232234
}
233235

234236
match adj.autoref {
@@ -263,6 +265,8 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
263265
// work properly.
264266
let (_, dt) = const_deref(cx, llconst, ty, false);
265267
ty = dt;
268+
} else {
269+
llconst = const_addr_of(cx, llconst, ast::MutImmutable)
266270
}
267271

268272
match ty::get(ty).sty {

trunk/src/librustc/middle/trans/datum.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ impl Datum<Expr> {
451451
name: &str,
452452
expr_id: ast::NodeId)
453453
-> DatumBlock<'a, Lvalue> {
454+
debug!("to_lvalue_datum self: {}", self.to_string(bcx.ccx()));
455+
454456
assert!(ty::lltype_is_sized(bcx.tcx(), self.ty),
455457
"Trying to convert unsized value to lval");
456458
self.match_kind(

trunk/src/librustc/middle/trans/expr.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,11 +2061,17 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
20612061
if ty::type_is_sized(bcx.tcx(), content_ty) {
20622062
deref_owned_pointer(bcx, expr, datum, content_ty)
20632063
} else {
2064-
// A fat pointer and an opened DST value have the same represenation
2065-
// just different types.
2066-
DatumBlock::new(bcx, Datum::new(datum.val,
2067-
ty::mk_open(bcx.tcx(), content_ty),
2068-
datum.kind))
2064+
// A fat pointer and an opened DST value have the same
2065+
// represenation just different types. Since there is no
2066+
// temporary for `*e` here (because it is unsized), we cannot
2067+
// emulate the sized object code path for running drop glue and
2068+
// free. Instead, we schedule cleanup for `e`, turning it into
2069+
// an lvalue.
2070+
let datum = unpack_datum!(
2071+
bcx, datum.to_lvalue_datum(bcx, "deref", expr.id));
2072+
2073+
let datum = Datum::new(datum.val, ty::mk_open(bcx.tcx(), content_ty), LvalueExpr);
2074+
DatumBlock::new(bcx, datum)
20692075
}
20702076
}
20712077

@@ -2094,7 +2100,7 @@ fn deref_once<'a>(bcx: &'a Block<'a>,
20942100
// just different types.
20952101
DatumBlock::new(bcx, Datum::new(datum.val,
20962102
ty::mk_open(bcx.tcx(), content_ty),
2097-
datum.kind))
2103+
LvalueExpr))
20982104
}
20992105
}
21002106

trunk/src/librustc/middle/typeck/infer/coercion.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ impl<'f> Coerce<'f> {
327327

328328
let sty_b = &ty::get(b).sty;
329329
match (sty_a, sty_b) {
330-
(&ty::ty_uniq(_), &ty::ty_rptr(..)) => Err(ty::terr_mismatch),
331330
(&ty::ty_rptr(_, ty::mt{ty: t_a, ..}), &ty::ty_rptr(_, mt_b)) => {
332331
self.unpack_actual_value(t_a, |sty_a| {
333332
match self.unsize_ty(sty_a, mt_b.ty) {
@@ -511,7 +510,7 @@ impl<'f> Coerce<'f> {
511510
let tcx = self.get_ref().infcx.tcx;
512511

513512
match *sty_a {
514-
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
513+
ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
515514
ty::ty_trait(box ty::TyTrait {
516515
def_id,
517516
ref substs,

trunk/src/librustrt/unwind.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ use core::prelude::*;
6161

6262
use alloc::boxed::Box;
6363
use collections::string::String;
64+
use collections::str::StrAllocating;
6465
use collections::vec::Vec;
6566
use core::any::Any;
6667
use core::atomic;
@@ -525,7 +526,8 @@ pub fn begin_unwind_fmt(msg: &fmt::Arguments, file_line: &(&'static str, uint))
525526
let mut v = Vec::new();
526527
let _ = write!(&mut VecWriter { v: &mut v }, "{}", msg);
527528

528-
begin_unwind_inner(box String::from_utf8(v).unwrap(), file_line)
529+
let msg = box String::from_utf8_lossy(v.as_slice()).into_string();
530+
begin_unwind_inner(msg, file_line)
529531
}
530532

531533
/// This is the entry point of unwinding for fail!() and assert!().
@@ -570,7 +572,7 @@ fn begin_unwind_inner(msg: Box<Any + Send>, file_line: &(&'static str, uint)) ->
570572
n => {
571573
let f: Callback = unsafe { mem::transmute(n) };
572574
let (file, line) = *file_line;
573-
f(msg, file, line);
575+
f(&*msg, file, line);
574576
}
575577
}
576578
};

trunk/src/libstd/failure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn on_fail(obj: &Any + Send, file: &'static str, line: uint) {
8181
"task '{}' failed at '{}', {}:{}\n",
8282
n, msg, file, line);
8383
if backtrace::log_enabled() {
84-
let _ = backtrace::write(stderr);
84+
let _ = backtrace::write(&mut *stderr);
8585
}
8686
local_stderr.replace(Some(stderr));
8787
}

trunk/src/libstd/io/stdio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()>) {
203203
let mut my_stdout = local_stdout.replace(None).unwrap_or_else(|| {
204204
box stdout() as Box<Writer + Send>
205205
});
206-
let result = f(my_stdout);
206+
let result = f(&mut *my_stdout);
207207
local_stdout.replace(Some(my_stdout));
208208
result
209209
} else {

trunk/src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl<'a> Parser<'a> {
351351
mut rdr: Box<Reader+'a>)
352352
-> Parser<'a>
353353
{
354-
let tok0 = real_token(rdr);
354+
let tok0 = real_token(&mut *rdr);
355355
let span = tok0.sp;
356356
let placeholder = TokenAndSpan {
357357
tok: token::UNDERSCORE,
@@ -899,7 +899,7 @@ impl<'a> Parser<'a> {
899899
None
900900
};
901901
let next = if self.buffer_start == self.buffer_end {
902-
real_token(self.reader)
902+
real_token(&mut *self.reader)
903903
} else {
904904
// Avoid token copies with `replace`.
905905
let buffer_start = self.buffer_start as uint;
@@ -943,7 +943,7 @@ impl<'a> Parser<'a> {
943943
-> R {
944944
let dist = distance as int;
945945
while self.buffer_length() < dist {
946-
self.buffer[self.buffer_end as uint] = real_token(self.reader);
946+
self.buffer[self.buffer_end as uint] = real_token(&mut *self.reader);
947947
self.buffer_end = (self.buffer_end + 1) & 3;
948948
}
949949
f(&self.buffer[((self.buffer_start + dist - 1) & 3) as uint].tok)

0 commit comments

Comments
 (0)