Skip to content

Commit 6b3eaac

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 190924 b: refs/heads/auto c: 8afcaab h: refs/heads/master v: v3
1 parent 8d1fc5c commit 6b3eaac

File tree

15 files changed

+136
-1
lines changed

15 files changed

+136
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 633c593bc3f9787decfaf943cdc5659f132ade50
13+
refs/heads/auto: 8afcaabee32fb41eaf065041d7510c6762f12822
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/liballoc/heap.rs

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

11+
#[cfg(stage0)]
1112
#[cfg(not(test))]
1213
use core::ptr::PtrExt;
1314

branches/auto/src/liballoc/rc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ use core::nonzero::NonZero;
159159
use core::ops::{Deref, Drop};
160160
use core::option::Option;
161161
use core::option::Option::{Some, None};
162+
#[cfg(stage0)]
162163
use core::ptr::{self, PtrExt};
164+
#[cfg(not(stage0))]
165+
use core::ptr;
163166
use core::result::Result;
164167
use core::result::Result::{Ok, Err};
165168
use core::intrinsics::assume;

branches/auto/src/libcollections/slice.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ use core::mem;
9999
use core::num::wrapping::WrappingOps;
100100
use core::ops::FnMut;
101101
use core::option::Option::{self, Some, None};
102+
#[cfg(stage0)]
102103
use core::ptr::PtrExt;
103104
use core::ptr;
104105
use core::result::Result;

branches/auto/src/libcore/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub use iter::{Extend, IteratorExt};
4242
pub use iter::{Iterator, DoubleEndedIterator};
4343
pub use iter::{ExactSizeIterator};
4444
pub use option::Option::{self, Some, None};
45+
#[cfg(stage0)]
4546
pub use ptr::{PtrExt, MutPtrExt};
4647
pub use result::Result::{self, Ok, Err};
4748
pub use slice::{AsSlice, SliceExt};

branches/auto/src/libcore/ptr.rs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ pub unsafe fn write<T>(dst: *mut T, src: T) {
262262
intrinsics::move_val_init(&mut *dst, src)
263263
}
264264

265+
#[cfg(stage0)]
265266
/// Methods on raw pointers
266267
#[stable(feature = "rust1", since = "1.0.0")]
267268
pub trait PtrExt {
@@ -298,6 +299,7 @@ pub trait PtrExt {
298299
unsafe fn offset(self, count: isize) -> Self where Self::Target: Sized;
299300
}
300301

302+
#[cfg(stage0)]
301303
/// Methods on mutable raw pointers
302304
#[stable(feature = "rust1", since = "1.0.0")]
303305
pub trait MutPtrExt {
@@ -317,6 +319,7 @@ pub trait MutPtrExt {
317319
unsafe fn as_mut<'a>(&self) -> Option<&'a mut Self::Target>;
318320
}
319321

322+
#[cfg(stage0)]
320323
#[stable(feature = "rust1", since = "1.0.0")]
321324
impl<T: ?Sized> PtrExt for *const T {
322325
type Target = T;
@@ -344,6 +347,7 @@ impl<T: ?Sized> PtrExt for *const T {
344347
}
345348
}
346349

350+
#[cfg(stage0)]
347351
#[stable(feature = "rust1", since = "1.0.0")]
348352
impl<T: ?Sized> PtrExt for *mut T {
349353
type Target = T;
@@ -371,6 +375,7 @@ impl<T: ?Sized> PtrExt for *mut T {
371375
}
372376
}
373377

378+
#[cfg(stage0)]
374379
#[stable(feature = "rust1", since = "1.0.0")]
375380
impl<T: ?Sized> MutPtrExt for *mut T {
376381
type Target = T;
@@ -388,6 +393,119 @@ impl<T: ?Sized> MutPtrExt for *mut T {
388393
}
389394
}
390395

396+
#[cfg(not(stage0))]
397+
#[stable(feature = "rust1", since = "1.0.0")]
398+
#[lang = "const_ptr"]
399+
impl<T: ?Sized> *const T {
400+
/// Returns true if the pointer is null.
401+
#[stable(feature = "rust1", since = "1.0.0")]
402+
#[inline]
403+
pub fn is_null(self) -> bool {
404+
self == 0 as *const T
405+
}
406+
407+
/// Returns `None` if the pointer is null, or else returns a reference to
408+
/// the value wrapped in `Some`.
409+
///
410+
/// # Safety
411+
///
412+
/// While this method and its mutable counterpart are useful for
413+
/// null-safety, it is important to note that this is still an unsafe
414+
/// operation because the returned value could be pointing to invalid
415+
/// memory.
416+
#[unstable(feature = "core",
417+
reason = "Option is not clearly the right return type, and we may want \
418+
to tie the return lifetime to a borrow of the raw pointer")]
419+
#[inline]
420+
pub unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
421+
if self.is_null() {
422+
None
423+
} else {
424+
Some(&**self)
425+
}
426+
}
427+
428+
/// Calculates the offset from a pointer. `count` is in units of T; e.g. a
429+
/// `count` of 3 represents a pointer offset of `3 * sizeof::<T>()` bytes.
430+
///
431+
/// # Safety
432+
///
433+
/// The offset must be in-bounds of the object, or one-byte-past-the-end.
434+
/// Otherwise `offset` invokes Undefined Behaviour, regardless of whether
435+
/// the pointer is used.
436+
#[stable(feature = "rust1", since = "1.0.0")]
437+
#[inline]
438+
pub unsafe fn offset(self, count: isize) -> *const T where T: Sized {
439+
intrinsics::offset(self, count)
440+
}
441+
}
442+
443+
#[cfg(not(stage0))]
444+
#[stable(feature = "rust1", since = "1.0.0")]
445+
#[lang = "mut_ptr"]
446+
impl<T: ?Sized> *mut T {
447+
/// Returns true if the pointer is null.
448+
#[stable(feature = "rust1", since = "1.0.0")]
449+
#[inline]
450+
pub fn is_null(self) -> bool {
451+
self == 0 as *mut T
452+
}
453+
454+
/// Returns `None` if the pointer is null, or else returns a reference to
455+
/// the value wrapped in `Some`.
456+
///
457+
/// # Safety
458+
///
459+
/// While this method and its mutable counterpart are useful for
460+
/// null-safety, it is important to note that this is still an unsafe
461+
/// operation because the returned value could be pointing to invalid
462+
/// memory.
463+
#[unstable(feature = "core",
464+
reason = "Option is not clearly the right return type, and we may want \
465+
to tie the return lifetime to a borrow of the raw pointer")]
466+
#[inline]
467+
pub unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
468+
if self.is_null() {
469+
None
470+
} else {
471+
Some(&**self)
472+
}
473+
}
474+
475+
/// Calculates the offset from a pointer. `count` is in units of T; e.g. a
476+
/// `count` of 3 represents a pointer offset of `3 * sizeof::<T>()` bytes.
477+
///
478+
/// # Safety
479+
///
480+
/// The offset must be in-bounds of the object, or one-byte-past-the-end.
481+
/// Otherwise `offset` invokes Undefined Behaviour, regardless of whether
482+
/// the pointer is used.
483+
#[stable(feature = "rust1", since = "1.0.0")]
484+
#[inline]
485+
pub unsafe fn offset(self, count: isize) -> *mut T where T: Sized {
486+
intrinsics::offset(self, count) as *mut T
487+
}
488+
489+
/// Returns `None` if the pointer is null, or else returns a mutable
490+
/// reference to the value wrapped in `Some`.
491+
///
492+
/// # Safety
493+
///
494+
/// As with `as_ref`, this is unsafe because it cannot verify the validity
495+
/// of the returned pointer.
496+
#[unstable(feature = "core",
497+
reason = "return value does not necessarily convey all possible \
498+
information")]
499+
#[inline]
500+
pub unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
501+
if self.is_null() {
502+
None
503+
} else {
504+
Some(&mut **self)
505+
}
506+
}
507+
}
508+
391509
// Equality for pointers
392510
#[stable(feature = "rust1", since = "1.0.0")]
393511
impl<T: ?Sized> PartialEq for *const T {

branches/auto/src/libcore/slice.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use option::Option::{None, Some};
4949
use result::Result;
5050
use result::Result::{Ok, Err};
5151
use ptr;
52+
#[cfg(stage0)]
5253
use ptr::PtrExt;
5354
use mem;
5455
use mem::size_of;

branches/auto/src/libcore/str/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use mem;
3030
use num::Int;
3131
use ops::{Fn, FnMut};
3232
use option::Option::{self, None, Some};
33+
#[cfg(stage0)]
3334
use ptr::PtrExt;
3435
use raw::{Repr, Slice};
3536
use result::Result::{self, Ok, Err};

branches/auto/src/libstd/collections/hash/table.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ use num::wrapping::{OverflowingOps, WrappingOps};
2424
use ops::{Deref, DerefMut, Drop};
2525
use option::Option;
2626
use option::Option::{Some, None};
27+
#[cfg(stage0)]
2728
use ptr::{self, PtrExt, Unique};
29+
#[cfg(not(stage0))]
30+
use ptr::{self, Unique};
2831
use rt::heap::{allocate, deallocate, EMPTY};
2932
use collections::hash_state::HashState;
3033

branches/auto/src/libstd/io/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use iter::Iterator;
2020
use marker::Sized;
2121
use ops::{Drop, FnOnce};
2222
use option::Option::{self, Some, None};
23+
#[cfg(stage0)]
2324
use ptr::PtrExt;
2425
use result::Result::{Ok, Err};
2526
use result;

branches/auto/src/libstd/old_io/extensions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use num::Int;
2626
use ops::FnOnce;
2727
use option::Option;
2828
use option::Option::{Some, None};
29+
#[cfg(stage0)]
2930
use ptr::PtrExt;
3031
use result::Result::{Ok, Err};
3132
#[cfg(stage0)]

branches/auto/src/libstd/old_io/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ impl<'a> Reader for &'a mut (Reader+'a) {
935935
// API yet. If so, it should be a method on Vec.
936936
unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec<T>, start: uint, end: uint) -> &'a mut [T] {
937937
use slice;
938+
#[cfg(stage0)]
938939
use ptr::PtrExt;
939940

940941
assert!(start <= end);

branches/auto/src/libstd/os.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use option::Option::{Some, None};
5252
use option::Option;
5353
use old_path::{Path, GenericPath, BytesContainer};
5454
use path::{self, PathBuf};
55+
#[cfg(stage0)]
5556
use ptr::PtrExt;
5657
use ptr;
5758
use result::Result::{Err, Ok};

branches/auto/src/libstd/prelude/v1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#[doc(no_inline)] pub use iter::{Iterator, IteratorExt, Extend};
4141
#[stable(feature = "rust1", since = "1.0.0")]
4242
#[doc(no_inline)] pub use option::Option::{self, Some, None};
43+
#[cfg(stage0)]
4344
#[stable(feature = "rust1", since = "1.0.0")]
4445
#[doc(no_inline)] pub use ptr::{PtrExt, MutPtrExt};
4546
#[stable(feature = "rust1", since = "1.0.0")]

branches/auto/src/libstd/rt/at_exit_imp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//!
1313
//! Documentation can be found on the `rt::at_exit` function.
1414
15+
#[cfg(stage0)]
1516
use core::prelude::*;
1617

1718
use boxed;

0 commit comments

Comments
 (0)