Skip to content

Commit 431987f

Browse files
committed
---
yaml --- r: 130467 b: refs/heads/try c: 7d72bdb h: refs/heads/master i: 130465: 212a36a 130463: 0e2ff33 v: v3
1 parent d31901e commit 431987f

37 files changed

+126
-329
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: c964cb229bd342bdeb0b4506c3a6d32b03e575f6
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 67b97ab6d2b7de9b69fd97dc171fcf8feec932ff
5-
refs/heads/try: 821afc4ce8367ed3d9e536925007aac5e8e3835e
5+
refs/heads/try: 7d72bdb226b9f7918de997e2e10315c9d9a0a62d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<T> Rawlink<T> {
9090
/// Convert the `Rawlink` into an Option value
9191
fn resolve_immut<'a>(&self) -> Option<&'a T> {
9292
unsafe {
93-
self.p.as_ref()
93+
mem::transmute(self.p.to_option())
9494
}
9595
}
9696

branches/try/src/libcore/ptr.rs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -256,46 +256,27 @@ pub unsafe fn position<T>(buf: *const T, f: |&T| -> bool) -> uint {
256256
pub trait RawPtr<T> {
257257
/// Returns the null pointer.
258258
fn null() -> Self;
259-
260259
/// Returns true if the pointer is equal to the null pointer.
261260
fn is_null(&self) -> bool;
262-
263261
/// Returns true if the pointer is not equal to the null pointer.
264262
fn is_not_null(&self) -> bool { !self.is_null() }
265-
266263
/// Returns the value of this pointer (ie, the address it points to)
267264
fn to_uint(&self) -> uint;
268-
269-
/// Returns `None` if the pointer is null, or else returns a reference to the
270-
/// value wrapped in `Some`.
265+
/// Returns `None` if the pointer is null, or else returns the value wrapped
266+
/// in `Some`.
271267
///
272268
/// # Safety Notes
273269
///
274-
/// While this method and its mutable counterpart are useful for null-safety,
275-
/// it is important to note that this is still an unsafe operation because
276-
/// the returned value could be pointing to invalid memory.
277-
unsafe fn as_ref<'a>(&self) -> Option<&'a T>;
278-
279-
/// A synonym for `as_ref`, except with incorrect lifetime semantics
280-
#[deprecated="Use `as_ref` instead"]
281-
unsafe fn to_option<'a>(&'a self) -> Option<&'a T> {
282-
mem::transmute(self.as_ref())
283-
}
284-
270+
/// While this method is useful for null-safety, it is important to note
271+
/// that this is still an unsafe operation because the returned value could
272+
/// be pointing to invalid memory.
273+
unsafe fn to_option(&self) -> Option<&T>;
285274
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
286275
/// the object, or one-byte-past-the-end. `count` is in units of T; e.g. a
287276
/// `count` of 3 represents a pointer offset of `3 * sizeof::<T>()` bytes.
288277
unsafe fn offset(self, count: int) -> Self;
289278
}
290279

291-
/// Methods on mutable raw pointers
292-
pub trait RawMutPtr<T>{
293-
/// Returns `None` if the pointer is null, or else returns a mutable reference
294-
/// to the value wrapped in `Some`. As with `as_ref`, this is unsafe because
295-
/// it cannot verify the validity of the returned pointer.
296-
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T>;
297-
}
298-
299280
impl<T> RawPtr<T> for *const T {
300281
#[inline]
301282
fn null() -> *const T { null() }
@@ -312,7 +293,7 @@ impl<T> RawPtr<T> for *const T {
312293
}
313294

314295
#[inline]
315-
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
296+
unsafe fn to_option(&self) -> Option<&T> {
316297
if self.is_null() {
317298
None
318299
} else {
@@ -337,7 +318,7 @@ impl<T> RawPtr<T> for *mut T {
337318
}
338319

339320
#[inline]
340-
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
321+
unsafe fn to_option(&self) -> Option<&T> {
341322
if self.is_null() {
342323
None
343324
} else {
@@ -346,17 +327,6 @@ impl<T> RawPtr<T> for *mut T {
346327
}
347328
}
348329

349-
impl<T> RawMutPtr<T> for *mut T {
350-
#[inline]
351-
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
352-
if self.is_null() {
353-
None
354-
} else {
355-
Some(&mut **self)
356-
}
357-
}
358-
}
359-
360330
// Equality for pointers
361331
impl<T> PartialEq for *const T {
362332
#[inline]

branches/try/src/libcoretest/ptr.rs

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -102,44 +102,19 @@ fn test_is_null() {
102102
}
103103

104104
#[test]
105-
fn test_as_ref() {
105+
fn test_to_option() {
106106
unsafe {
107107
let p: *const int = null();
108-
assert_eq!(p.as_ref(), None);
108+
assert_eq!(p.to_option(), None);
109109

110110
let q: *const int = &2;
111-
assert_eq!(q.as_ref().unwrap(), &2);
111+
assert_eq!(q.to_option().unwrap(), &2);
112112

113113
let p: *mut int = mut_null();
114-
assert_eq!(p.as_ref(), None);
114+
assert_eq!(p.to_option(), None);
115115

116116
let q: *mut int = &mut 2;
117-
assert_eq!(q.as_ref().unwrap(), &2);
118-
119-
// Lifetime inference
120-
let u = 2i;
121-
{
122-
let p: *const int = &u as *const _;
123-
assert_eq!(p.as_ref().unwrap(), &2);
124-
}
125-
}
126-
}
127-
128-
#[test]
129-
fn test_as_mut() {
130-
unsafe {
131-
let p: *mut int = mut_null();
132-
assert!(p.as_mut() == None);
133-
134-
let q: *mut int = &mut 2;
135-
assert!(q.as_mut().unwrap() == &mut 2);
136-
137-
// Lifetime inference
138-
let mut u = 2i;
139-
{
140-
let p: *mut int = &mut u as *mut _;
141-
assert!(p.as_mut().unwrap() == &mut 2);
142-
}
117+
assert_eq!(q.to_option().unwrap(), &2);
143118
}
144119
}
145120

branches/try/src/liblibc/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,14 +2965,12 @@ pub mod consts {
29652965
pub static AF_INET6: c_int = 10;
29662966
pub static SOCK_STREAM: c_int = 2;
29672967
pub static SOCK_DGRAM: c_int = 1;
2968-
pub static SOCK_RAW: c_int = 3;
29692968
pub static IPPROTO_TCP: c_int = 6;
29702969
pub static IPPROTO_IP: c_int = 0;
29712970
pub static IPPROTO_IPV6: c_int = 41;
29722971
pub static IP_MULTICAST_TTL: c_int = 33;
29732972
pub static IP_MULTICAST_LOOP: c_int = 34;
29742973
pub static IP_TTL: c_int = 2;
2975-
pub static IP_HDRINCL: c_int = 3;
29762974
pub static IP_ADD_MEMBERSHIP: c_int = 35;
29772975
pub static IP_DROP_MEMBERSHIP: c_int = 36;
29782976
pub static IPV6_ADD_MEMBERSHIP: c_int = 20;
@@ -3023,12 +3021,8 @@ pub mod consts {
30233021
pub mod extra {
30243022
use types::os::arch::c95::c_int;
30253023

3026-
pub static AF_PACKET : c_int = 17;
3027-
pub static IPPROTO_RAW : c_int = 255;
3028-
30293024
pub static O_RSYNC : c_int = 16400;
30303025
pub static O_DSYNC : c_int = 16;
3031-
pub static O_NONBLOCK : c_int = 128;
30323026
pub static O_SYNC : c_int = 16400;
30333027

30343028
pub static PROT_GROWSDOWN : c_int = 0x01000000;

branches/try/src/liblog/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl Drop for DefaultLogger {
282282
pub fn log(level: u32, loc: &'static LogLocation, args: &fmt::Arguments) {
283283
// Test the literal string from args against the current filter, if there
284284
// is one.
285-
match unsafe { FILTER.as_ref() } {
285+
match unsafe { FILTER.to_option() } {
286286
Some(filter) if filter.is_match(args.to_string().as_slice()) => return,
287287
_ => {}
288288
}

branches/try/src/libnum/complex.rs

Lines changed: 7 additions & 16 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, Hash)]
21+
#[deriving(PartialEq,Clone)]
2222
pub struct Complex<T> {
2323
/// Real portion of the complex number
2424
pub re: T,
@@ -36,8 +36,10 @@ impl<T: Clone + Num> Complex<T> {
3636
Complex { re: re, im: im }
3737
}
3838

39-
/// Returns the square of the norm (since `T` doesn't necessarily
40-
/// have a sqrt function), i.e. `re^2 + im^2`.
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+
*/
4143
#[inline]
4244
pub fn norm_sqr(&self) -> T {
4345
self.re * self.re + self.im * self.im
@@ -191,8 +193,7 @@ mod test {
191193
#![allow(non_uppercase_statics)]
192194

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

197198
pub static _0_0i : Complex64 = Complex { re: 0.0, im: 0.0 };
198199
pub static _1_0i : Complex64 = Complex { re: 1.0, im: 0.0 };
@@ -366,14 +367,4 @@ mod test {
366367
test(-_neg1_1i, "1-1i".to_string());
367368
test(_05_05i, "0.5+0.5i".to_string());
368369
}
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-
}
379370
}

branches/try/src/libnum/rational.rs

Lines changed: 1 addition & 8 deletions
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, Hash)]
24+
#[deriving(Clone)]
2525
#[allow(missing_doc)]
2626
pub struct Ratio<T> {
2727
numer: T,
@@ -380,7 +380,6 @@ 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;
384383
use std::num;
385384

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

branches/try/src/librustc/front/test.rs

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

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

9389
impl<'a> fold::Folder for TestHarnessGenerator<'a> {
@@ -172,14 +168,10 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
172168
*i = nomain(*i);
173169
}
174170
if !tests.is_empty() || !tested_submods.is_empty() {
175-
let (it, sym) = mk_reexport_mod(&mut self.cx, tests, tested_submods);
176-
mod_folded.items.push(it);
177-
171+
mod_folded.items.push(mk_reexport_mod(&mut self.cx, tests,
172+
tested_submods));
178173
if !self.cx.path.is_empty() {
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);
174+
self.tested_submods.push(self.cx.path[self.cx.path.len()-1]);
183175
}
184176
}
185177

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

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

195187
view_items.extend(tests.move_iter().map(|r| {
196188
cx.ext_cx.view_use_simple(DUMMY_SP, ast::Public,
197189
cx.ext_cx.path(DUMMY_SP, vec![super_, r]))
198190
}));
199-
view_items.extend(tested_submods.move_iter().map(|(r, sym)| {
200-
let path = cx.ext_cx.path(DUMMY_SP, vec![super_, r, sym]);
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]);
201193
cx.ext_cx.view_use_simple_(DUMMY_SP, ast::Public, r, path)
202194
}));
203195

@@ -206,18 +198,14 @@ fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec<ast::Ident>,
206198
view_items: view_items,
207199
items: Vec::new(),
208200
};
209-
210-
let sym = token::gensym_ident("__test_reexports");
211-
let it = box(GC) ast::Item {
212-
ident: sym.clone(),
201+
box(GC) ast::Item {
202+
ident: cx.reexport_mod_ident.clone(),
213203
attrs: Vec::new(),
214204
id: ast::DUMMY_NODE_ID,
215205
node: ast::ItemMod(reexport_mod),
216206
vis: ast::Public,
217207
span: DUMMY_SP,
218-
};
219-
220-
(it, sym)
208+
}
221209
}
222210

223211
fn generate_test_harness(sess: &Session,
@@ -232,10 +220,10 @@ fn generate_test_harness(sess: &Session,
232220
}),
233221
path: Vec::new(),
234222
testfns: Vec::new(),
223+
reexport_mod_ident: token::gensym_ident("__test_reexports"),
235224
reexport_test_harness_main: reexport_test_harness_main,
236225
is_test_crate: is_test_crate(&krate),
237226
config: krate.config.clone(),
238-
toplevel_reexport: None,
239227
};
240228

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

544532

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-
};
533+
let mut visible_path = vec![cx.reexport_mod_ident.clone()];
553534
visible_path.extend(path.move_iter());
554535

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

0 commit comments

Comments
 (0)