Skip to content

Commit 8d47326

Browse files
committed
---
yaml --- r: 68809 b: refs/heads/auto c: 294999c h: refs/heads/master i: 68807: f4bea72 v: v3
1 parent 7ad637f commit 8d47326

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
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 8fa09736efcd100ec675a2fe0e29906607996485
17+
refs/heads/auto: 294999c3508ef4cbc2d221f531a6255c82fb95d3
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/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/auto/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/auto/src/test/run-pass/traits-default-method-mut.rs

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

0 commit comments

Comments
 (0)