Skip to content

Commit 6afb333

Browse files
committed
---
yaml --- r: 154810 b: refs/heads/try2 c: a4d257b h: refs/heads/master v: v3
1 parent c32c2ef commit 6afb333

32 files changed

+319
-73
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: ab3999f6151347169c1871627f27bf2d10ad4b3f
8+
refs/heads/try2: a4d257b1500e8853d093f8ba38dc9561ad242f71
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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-
mem::transmute(self.p.to_option())
93+
self.p.as_ref()
9494
}
9595
}
9696

branches/try2/src/libcore/ptr.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,27 +256,46 @@ 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+
259260
/// Returns true if the pointer is equal to the null pointer.
260261
fn is_null(&self) -> bool;
262+
261263
/// Returns true if the pointer is not equal to the null pointer.
262264
fn is_not_null(&self) -> bool { !self.is_null() }
265+
263266
/// Returns the value of this pointer (ie, the address it points to)
264267
fn to_uint(&self) -> uint;
265-
/// Returns `None` if the pointer is null, or else returns the value wrapped
266-
/// in `Some`.
268+
269+
/// Returns `None` if the pointer is null, or else returns a reference to the
270+
/// value wrapped in `Some`.
267271
///
268272
/// # Safety Notes
269273
///
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>;
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+
274285
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
275286
/// the object, or one-byte-past-the-end. `count` is in units of T; e.g. a
276287
/// `count` of 3 represents a pointer offset of `3 * sizeof::<T>()` bytes.
277288
unsafe fn offset(self, count: int) -> Self;
278289
}
279290

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+
280299
impl<T> RawPtr<T> for *const T {
281300
#[inline]
282301
fn null() -> *const T { null() }
@@ -293,7 +312,7 @@ impl<T> RawPtr<T> for *const T {
293312
}
294313

295314
#[inline]
296-
unsafe fn to_option(&self) -> Option<&T> {
315+
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
297316
if self.is_null() {
298317
None
299318
} else {
@@ -318,7 +337,7 @@ impl<T> RawPtr<T> for *mut T {
318337
}
319338

320339
#[inline]
321-
unsafe fn to_option(&self) -> Option<&T> {
340+
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
322341
if self.is_null() {
323342
None
324343
} else {
@@ -327,6 +346,17 @@ impl<T> RawPtr<T> for *mut T {
327346
}
328347
}
329348

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+
330360
// Equality for pointers
331361
impl<T> PartialEq for *const T {
332362
#[inline]

branches/try2/src/libcoretest/ptr.rs

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

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

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

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

116116
let q: *mut int = &mut 2;
117-
assert_eq!(q.to_option().unwrap(), &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+
}
118143
}
119144
}
120145

branches/try2/src/liblibc/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,12 +2965,14 @@ 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;
29682969
pub static IPPROTO_TCP: c_int = 6;
29692970
pub static IPPROTO_IP: c_int = 0;
29702971
pub static IPPROTO_IPV6: c_int = 41;
29712972
pub static IP_MULTICAST_TTL: c_int = 33;
29722973
pub static IP_MULTICAST_LOOP: c_int = 34;
29732974
pub static IP_TTL: c_int = 2;
2975+
pub static IP_HDRINCL: c_int = 3;
29742976
pub static IP_ADD_MEMBERSHIP: c_int = 35;
29752977
pub static IP_DROP_MEMBERSHIP: c_int = 36;
29762978
pub static IPV6_ADD_MEMBERSHIP: c_int = 20;
@@ -3021,8 +3023,12 @@ pub mod consts {
30213023
pub mod extra {
30223024
use types::os::arch::c95::c_int;
30233025

3026+
pub static AF_PACKET : c_int = 17;
3027+
pub static IPPROTO_RAW : c_int = 255;
3028+
30243029
pub static O_RSYNC : c_int = 16400;
30253030
pub static O_DSYNC : c_int = 16;
3031+
pub static O_NONBLOCK : c_int = 128;
30263032
pub static O_SYNC : c_int = 16400;
30273033

30283034
pub static PROT_GROWSDOWN : c_int = 0x01000000;

branches/try2/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.to_option() } {
285+
match unsafe { FILTER.as_ref() } {
286286
Some(filter) if filter.is_match(args.to_string().as_slice()) => return,
287287
_ => {}
288288
}

branches/try2/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));

branches/try2/src/librustc/middle/kind.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
1211
use middle::freevars::freevar_entry;
1312
use middle::freevars;
1413
use middle::subst;
@@ -587,15 +586,15 @@ fn check_ty(cx: &mut Context, aty: &Ty) {
587586
match aty.node {
588587
TyPath(_, _, id) => {
589588
match cx.tcx.item_substs.borrow().find(&id) {
590-
None => { }
589+
None => {}
591590
Some(ref item_substs) => {
592591
let def_map = cx.tcx.def_map.borrow();
593592
let did = def_map.get_copy(&id).def_id();
594593
let generics = ty::lookup_item_type(cx.tcx, did).generics;
595594
for def in generics.types.iter() {
596595
let ty = *item_substs.substs.types.get(def.space,
597596
def.index);
598-
check_typaram_bounds(cx, aty.span, ty, def)
597+
check_typaram_bounds(cx, aty.span, ty, def);
599598
}
600599
}
601600
}
@@ -668,7 +667,7 @@ fn check_bounds_on_structs_or_enums_in_type_if_possible(cx: &mut Context,
668667
.zip(polytype.generics
669668
.types
670669
.iter()) {
671-
check_typaram_bounds(cx, span, *ty, type_param_def)
670+
check_typaram_bounds(cx, span, *ty, type_param_def);
672671
}
673672

674673
// Check trait bounds.

branches/try2/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
}

branches/try2/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 {

0 commit comments

Comments
 (0)