Skip to content

Commit 2184663

Browse files
committed
Use "stable" version of the intrinsic on stage0
1 parent 18ab95f commit 2184663

File tree

5 files changed

+24
-36
lines changed

5 files changed

+24
-36
lines changed

src/libcore/intrinsics.rs

+1-32
Original file line numberDiff line numberDiff line change
@@ -1381,38 +1381,7 @@ extern "rust-intrinsic" {
13811381
}
13821382

13831383
#[cfg(stage0)]
1384-
/// Computes the byte offset that needs to be applied to `ptr` in order to
1385-
/// make it aligned to `align`.
1386-
/// If it is not possible to align `ptr`, the implementation returns
1387-
/// `usize::max_value()`.
1388-
///
1389-
/// There are no guarantees whatsover that offsetting the pointer will not
1390-
/// overflow or go beyond the allocation that `ptr` points into.
1391-
/// It is up to the caller to ensure that the returned offset is correct
1392-
/// in all terms other than alignment.
1393-
///
1394-
/// # Examples
1395-
///
1396-
/// Accessing adjacent `u8` as `u16`
1397-
///
1398-
/// ```
1399-
/// # #![feature(core_intrinsics)]
1400-
/// # fn foo(n: usize) {
1401-
/// # use std::intrinsics::align_offset;
1402-
/// # use std::mem::align_of;
1403-
/// # unsafe {
1404-
/// let x = [5u8, 6u8, 7u8, 8u8, 9u8];
1405-
/// let ptr = &x[n] as *const u8;
1406-
/// let offset = align_offset(ptr as *const (), align_of::<u16>());
1407-
/// if offset < x.len() - n - 1 {
1408-
/// let u16_ptr = ptr.offset(offset as isize) as *const u16;
1409-
/// assert_ne!(*u16_ptr, 500);
1410-
/// } else {
1411-
/// // while the pointer can be aligned via `offset`, it would point
1412-
/// // outside the allocation
1413-
/// }
1414-
/// # } }
1415-
/// ```
1384+
/// remove me after the next release
14161385
pub unsafe fn align_offset(ptr: *const (), align: usize) -> usize {
14171386
let offset = ptr as usize % align;
14181387
if offset == 0 {

src/libcore/ptr.rs

+20
Original file line numberDiff line numberDiff line change
@@ -662,12 +662,22 @@ impl<T: ?Sized> *const T {
662662
/// }
663663
/// # } }
664664
/// ```
665+
#[cfg(not(stage0))]
665666
#[unstable(feature = "align_offset", issue = "44488")]
666667
pub fn align_offset(self, align: usize) -> usize {
667668
unsafe {
668669
intrinsics::align_offset(self as *const _, align)
669670
}
670671
}
672+
673+
#[cfg(stage0)]
674+
#[stable(feature = "rust1", since = "1.0.0")]
675+
/// remove me after the next release
676+
pub fn align_offset(self, align: usize) -> usize {
677+
unsafe {
678+
intrinsics::align_offset(self as *const _, align)
679+
}
680+
}
671681
}
672682

673683
#[lang = "mut_ptr"]
@@ -891,12 +901,22 @@ impl<T: ?Sized> *mut T {
891901
/// }
892902
/// # } }
893903
/// ```
904+
#[cfg(not(stage0))]
894905
#[unstable(feature = "align_offset", issue = "44488")]
895906
pub fn align_offset(self, align: usize) -> usize {
896907
unsafe {
897908
intrinsics::align_offset(self as *const _, align)
898909
}
899910
}
911+
912+
#[cfg(stage0)]
913+
#[stable(feature = "rust1", since = "1.0.0")]
914+
/// remove me after the next release
915+
pub fn align_offset(self, align: usize) -> usize {
916+
unsafe {
917+
intrinsics::align_offset(self as *const _, align)
918+
}
919+
}
900920
}
901921

902922
// Equality for pointers

src/libcore/str/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use fmt;
2323
use iter::{Map, Cloned, FusedIterator};
2424
use slice::{self, SliceIndex};
2525
use mem;
26-
use intrinsics::align_offset;
2726

2827
pub mod pattern;
2928

@@ -1471,7 +1470,7 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
14711470
let ptr = v.as_ptr();
14721471
let align = unsafe {
14731472
// the offset is safe, because `index` is guaranteed inbounds
1474-
align_offset(ptr.offset(index as isize) as *const (), usize_bytes)
1473+
ptr.offset(index as isize).align_offset(usize_bytes)
14751474
};
14761475
if align == 0 {
14771476
while index < blocks_end {

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
#![feature(allocator_internals)]
243243
#![feature(allow_internal_unsafe)]
244244
#![feature(allow_internal_unstable)]
245+
#![cfg_attr(not(stage0), feature(align_offset))]
245246
#![feature(asm)]
246247
#![feature(box_syntax)]
247248
#![feature(cfg_target_has_atomic)]

src/libstd/sys_common/memchr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
pub mod fallback {
1616
use cmp;
1717
use mem;
18-
use intrinsics::align_offset;
1918

2019
const LO_U64: u64 = 0x0101010101010101;
2120
const HI_U64: u64 = 0x8080808080808080;
@@ -66,7 +65,7 @@ pub mod fallback {
6665
let usize_bytes = mem::size_of::<usize>();
6766

6867
// search up to an aligned boundary
69-
let mut offset = unsafe { align_offset(ptr as *const _, usize_bytes) };
68+
let mut offset = ptr.align_offset(usize_bytes);
7069
if offset > 0 {
7170
offset = cmp::min(offset, len);
7271
if let Some(index) = text[..offset].iter().position(|elt| *elt == x) {

0 commit comments

Comments
 (0)