Skip to content

Commit

Permalink
make some functions promotable to reduce fallout
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 28, 2020
1 parent 0294e3f commit 76240d7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl<T: ?Sized> *const T {
/// Casts to a pointer of another type.
#[stable(feature = "ptr_cast", since = "1.38.0")]
#[rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0")]
#[rustc_promotable] // Operation cannot fail, so it may be promoted.
#[inline]
pub const fn cast<U>(self) -> *const U {
self as _
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
/// ```
#[inline(always)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_promotable]
#[rustc_promotable] // Operation cannot fail, so it may be promoted.
#[rustc_const_stable(feature = "const_ptr_null", since = "1.32.0")]
pub const fn null<T>() -> *const T {
0 as *const T
Expand All @@ -214,7 +214,7 @@ pub const fn null<T>() -> *const T {
/// ```
#[inline(always)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_promotable]
#[rustc_promotable] // Operation cannot fail, so it may be promoted.
#[rustc_const_stable(feature = "const_ptr_null", since = "1.32.0")]
pub const fn null_mut<T>() -> *mut T {
0 as *mut T
Expand Down
1 change: 1 addition & 0 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl<T: ?Sized> *mut T {
/// Casts to a pointer of another type.
#[stable(feature = "ptr_cast", since = "1.38.0")]
#[rustc_const_stable(feature = "const_ptr_cast", since = "1.38.0")]
#[rustc_promotable] // Operation cannot fail, so it may be promoted.
#[inline]
pub const fn cast<U>(self) -> *mut U {
self as _
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl<T> [T] {
/// [`as_mut_ptr`]: #method.as_mut_ptr
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_slice_as_ptr", since = "1.32.0")]
#[rustc_promotable] // Operation cannot fail, so it may be promoted.
#[inline]
pub const fn as_ptr(&self) -> *const T {
self as *const [T] as *const T
Expand Down Expand Up @@ -432,6 +433,7 @@ impl<T> [T] {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
#[rustc_promotable] // Operation cannot fail, so it may be promoted.
#[inline]
pub const fn as_mut_ptr(&mut self) -> *mut T {
self as *mut [T] as *mut T
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ impl Ipv4Addr {
/// let addr = Ipv4Addr::new(127, 0, 0, 1);
/// ```
#[rustc_const_stable(feature = "const_ipv4", since = "1.32.0")]
#[rustc_promotable] // Operation cannot fail, so it may be promoted.
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr {
// `s_addr` is stored as BE on all machine and the array is in BE order.
Expand Down Expand Up @@ -1045,6 +1046,7 @@ impl Ipv6Addr {
/// ```
#[rustc_allow_const_fn_unstable(const_fn_transmute)]
#[rustc_const_stable(feature = "const_ipv6", since = "1.32.0")]
#[rustc_promotable] // Operation cannot fail, so it may be promoted.
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr {
let addr16 = [
Expand Down

0 comments on commit 76240d7

Please sign in to comment.