From 1911eb8b6180f513a666372baf6e56f78b82dcd8 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Wed, 17 Nov 2021 21:08:16 -0500 Subject: [PATCH] Add missing const stability attributes --- library/core/src/array/mod.rs | 1 + library/core/src/cell.rs | 1 + library/core/src/num/int_macros.rs | 1 + library/core/src/num/nonzero.rs | 1 + library/core/src/num/uint_macros.rs | 1 + .../stability-attribute/missing-const-stability.rs | 12 +++++++----- .../missing-const-stability.stderr | 4 ++-- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 121aa634deb..ee79021ed53 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -512,6 +512,7 @@ impl [T; N] { /// Returns a slice containing the entire array. Equivalent to `&s[..]`. #[stable(feature = "array_as_slice", since = "1.57.0")] + #[rustc_const_stable(feature = "array_as_slice", since = "1.57.0")] pub const fn as_slice(&self) -> &[T] { self } diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 5fd60b75928..feb94555658 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -1959,6 +1959,7 @@ impl UnsafeCell { /// ``` #[inline(always)] #[stable(feature = "unsafe_cell_raw_get", since = "1.56.0")] + #[rustc_const_stable(feature = "unsafe_cell_raw_get", since = "1.56.0")] pub const fn raw_get(this: *const Self) -> *mut T { // We can just cast the pointer from `UnsafeCell` to `T` because of // #[repr(transparent)]. This exploits libstd's special status, there is diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 79436c8e8ed..3164b0c5d3c 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -1064,6 +1064,7 @@ macro_rules! int_impl { /// /// ``` #[stable(feature = "saturating_div", since = "1.58.0")] + #[rustc_const_stable(feature = "saturating_div", since = "1.58.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index e21ae489179..1ebd1c58f2b 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -972,6 +972,7 @@ macro_rules! nonzero_unsigned_is_power_of_two { /// ``` #[must_use] #[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")] + #[rustc_const_stable(feature = "nonzero_is_power_of_two", since = "1.59.0")] #[inline] pub const fn is_power_of_two(self) -> bool { // LLVM 11 normalizes `unchecked_sub(x, 1) & x == 0` to the implementation seen here. diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 0bb65497776..c1a134e68cd 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1132,6 +1132,7 @@ macro_rules! uint_impl { /// /// ``` #[stable(feature = "saturating_div", since = "1.58.0")] + #[rustc_const_stable(feature = "saturating_div", since = "1.58.0")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/src/test/ui/stability-attribute/missing-const-stability.rs b/src/test/ui/stability-attribute/missing-const-stability.rs index 39af6e9e3b9..57e64737d0f 100644 --- a/src/test/ui/stability-attribute/missing-const-stability.rs +++ b/src/test/ui/stability-attribute/missing-const-stability.rs @@ -1,11 +1,12 @@ #![feature(staged_api)] +#![feature(const_trait_impl)] #![stable(feature = "stable", since = "1.0.0")] #[stable(feature = "stable", since = "1.0.0")] pub const fn foo() {} //~ ERROR function has missing const stability attribute #[unstable(feature = "unstable", issue = "none")] -pub const fn bar() {} // ok for now +pub const fn bar() {} // ok because function is unstable #[stable(feature = "stable", since = "1.0.0")] pub struct Foo; @@ -14,11 +15,12 @@ impl Foo { pub const fn foo() {} //~ ERROR associated function has missing const stability attribute #[unstable(feature = "unstable", issue = "none")] - pub const fn bar() {} // ok for now + pub const fn bar() {} // ok because function is unstable } -// FIXME When #![feature(const_trait_impl)] is stabilized, add tests for const -// trait impls. Right now, a "trait methods cannot be stable const fn" error is -// emitted, but that's not in the scope of this test. +// FIXME Once #![feature(const_trait_impl)] is allowed to be stable, add a test +// for const trait impls. Right now, a "trait methods cannot be stable const fn" +// error is emitted. This occurs prior to the lint being tested here, such that +// the lint cannot currently be tested on this use case. fn main() {} diff --git a/src/test/ui/stability-attribute/missing-const-stability.stderr b/src/test/ui/stability-attribute/missing-const-stability.stderr index ee98e7b0e3f..7eba99a477a 100644 --- a/src/test/ui/stability-attribute/missing-const-stability.stderr +++ b/src/test/ui/stability-attribute/missing-const-stability.stderr @@ -1,11 +1,11 @@ error: function has missing const stability attribute - --> $DIR/missing-const-stability.rs:5:1 + --> $DIR/missing-const-stability.rs:6:1 | LL | pub const fn foo() {} | ^^^^^^^^^^^^^^^^^^^^^ error: associated function has missing const stability attribute - --> $DIR/missing-const-stability.rs:14:5 + --> $DIR/missing-const-stability.rs:15:5 | LL | pub const fn foo() {} | ^^^^^^^^^^^^^^^^^^^^^