Skip to content

Commit ca4ba5a

Browse files
committed
---
yaml --- r: 64182 b: refs/heads/snap-stage3 c: 294999c h: refs/heads/master v: v3
1 parent f608e21 commit ca4ba5a

File tree

4 files changed

+99
-19
lines changed

4 files changed

+99
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 8fa09736efcd100ec675a2fe0e29906607996485
4+
refs/heads/snap-stage3: 294999c3508ef4cbc2d221f531a6255c82fb95d3
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/ptr.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use option::{Option, Some, None};
1515
use sys;
1616
use unstable::intrinsics;
1717
use util::swap;
18+
use ops::{Add,Sub};
19+
use num::Int;
1820

1921
#[cfg(not(test))] use cmp::{Eq, Ord};
2022
use uint;
@@ -384,6 +386,46 @@ impl<T> Ord for *const T {
384386
}
385387
}
386388

389+
#[cfg(not(test))]
390+
impl<T, I: Int> Add<I, *T> for *T {
391+
/// Add an integer value to a pointer to get an offset pointer.
392+
/// Is calculated according to the size of the type pointed to.
393+
#[inline]
394+
pub fn add(&self, rhs: &I) -> *T {
395+
self.offset(rhs.to_int() as uint)
396+
}
397+
}
398+
399+
#[cfg(not(test))]
400+
impl<T, I: Int> Sub<I, *T> for *T {
401+
/// Subtract an integer value from a pointer to get an offset pointer.
402+
/// Is calculated according to the size of the type pointed to.
403+
#[inline]
404+
pub fn sub(&self, rhs: &I) -> *T {
405+
self.offset(-rhs.to_int() as uint)
406+
}
407+
}
408+
409+
#[cfg(not(test))]
410+
impl<T, I: Int> Add<I, *mut T> for *mut T {
411+
/// Add an integer value to a pointer to get an offset pointer.
412+
/// Is calculated according to the size of the type pointed to.
413+
#[inline]
414+
pub fn add(&self, rhs: &I) -> *mut T {
415+
self.offset(rhs.to_int() as uint)
416+
}
417+
}
418+
419+
#[cfg(not(test))]
420+
impl<T, I: Int> Sub<I, *mut T> for *mut T {
421+
/// Subtract an integer value from a pointer to get an offset pointer.
422+
/// Is calculated according to the size of the type pointed to.
423+
#[inline]
424+
pub fn sub(&self, rhs: &I) -> *mut T {
425+
self.offset(-rhs.to_int() as uint)
426+
}
427+
}
428+
387429
#[cfg(test)]
388430
pub mod ptr_tests {
389431
use super::*;
@@ -501,6 +543,60 @@ pub mod ptr_tests {
501543
}
502544
}
503545

546+
#[test]
547+
fn test_ptr_addition() {
548+
use vec::raw::*;
549+
550+
unsafe {
551+
let xs = ~[5, ..16];
552+
let mut ptr = to_ptr(xs);
553+
let end = ptr + 16;
554+
555+
while ptr < end {
556+
assert_eq!(*ptr, 5);
557+
ptr = ptr + 1u;
558+
}
559+
560+
let mut xs_mut = xs.clone();
561+
let mut m_ptr = to_mut_ptr(xs_mut);
562+
let m_end = m_ptr + 16i16;
563+
564+
while m_ptr < m_end {
565+
*m_ptr += 5;
566+
m_ptr = m_ptr + 1u8;
567+
}
568+
569+
assert_eq!(xs_mut, ~[10, ..16]);
570+
}
571+
}
572+
573+
#[test]
574+
fn test_ptr_subtraction() {
575+
use vec::raw::*;
576+
577+
unsafe {
578+
let xs = ~[0,1,2,3,4,5,6,7,8,9];
579+
let mut idx = 9i8;
580+
let ptr = to_ptr(xs);
581+
582+
while idx >= 0i8 {
583+
assert_eq!(*(ptr + idx), idx as int);
584+
idx = idx - 1i8;
585+
}
586+
587+
let mut xs_mut = xs.clone();
588+
let mut m_start = to_mut_ptr(xs_mut);
589+
let mut m_ptr = m_start + 9u32;
590+
591+
while m_ptr >= m_start {
592+
*m_ptr += *m_ptr;
593+
m_ptr = m_ptr - 1i8;
594+
}
595+
596+
assert_eq!(xs_mut, ~[0,2,4,6,8,10,12,14,16,18]);
597+
}
598+
}
599+
504600
#[test]
505601
fn test_ptr_array_each_with_len() {
506602
unsafe {

branches/snap-stage3/src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,9 +1074,10 @@ impl Parser {
10741074
// This version of parse arg doesn't necessarily require
10751075
// identifier names.
10761076
pub fn parse_arg_general(&self, require_name: bool) -> arg {
1077-
let mut is_mutbl = self.eat_keyword(keywords::Mut);
1077+
let mut is_mutbl = false;
10781078
let pat = if require_name || self.is_named_argument() {
10791079
self.parse_arg_mode();
1080+
is_mutbl = self.eat_keyword(keywords::Mut);
10801081
let pat = self.parse_pat();
10811082

10821083
if is_mutbl && !ast_util::pat_is_ident(pat) {

branches/snap-stage3/src/test/run-pass/traits-default-method-mut.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)