Skip to content

Commit 1911eb8

Browse files
committed
Add missing const stability attributes
1 parent 41f84c2 commit 1911eb8

File tree

7 files changed

+14
-7
lines changed

7 files changed

+14
-7
lines changed

library/core/src/array/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ impl<T, const N: usize> [T; N] {
512512

513513
/// Returns a slice containing the entire array. Equivalent to `&s[..]`.
514514
#[stable(feature = "array_as_slice", since = "1.57.0")]
515+
#[rustc_const_stable(feature = "array_as_slice", since = "1.57.0")]
515516
pub const fn as_slice(&self) -> &[T] {
516517
self
517518
}

library/core/src/cell.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,7 @@ impl<T: ?Sized> UnsafeCell<T> {
19591959
/// ```
19601960
#[inline(always)]
19611961
#[stable(feature = "unsafe_cell_raw_get", since = "1.56.0")]
1962+
#[rustc_const_stable(feature = "unsafe_cell_raw_get", since = "1.56.0")]
19621963
pub const fn raw_get(this: *const Self) -> *mut T {
19631964
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
19641965
// #[repr(transparent)]. This exploits libstd's special status, there is

library/core/src/num/int_macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ macro_rules! int_impl {
10641064
///
10651065
/// ```
10661066
#[stable(feature = "saturating_div", since = "1.58.0")]
1067+
#[rustc_const_stable(feature = "saturating_div", since = "1.58.0")]
10671068
#[must_use = "this returns the result of the operation, \
10681069
without modifying the original"]
10691070
#[inline]

library/core/src/num/nonzero.rs

+1
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ macro_rules! nonzero_unsigned_is_power_of_two {
972972
/// ```
973973
#[must_use]
974974
#[stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
975+
#[rustc_const_stable(feature = "nonzero_is_power_of_two", since = "1.59.0")]
975976
#[inline]
976977
pub const fn is_power_of_two(self) -> bool {
977978
// LLVM 11 normalizes `unchecked_sub(x, 1) & x == 0` to the implementation seen here.

library/core/src/num/uint_macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ macro_rules! uint_impl {
11321132
///
11331133
/// ```
11341134
#[stable(feature = "saturating_div", since = "1.58.0")]
1135+
#[rustc_const_stable(feature = "saturating_div", since = "1.58.0")]
11351136
#[must_use = "this returns the result of the operation, \
11361137
without modifying the original"]
11371138
#[inline]
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#![feature(staged_api)]
2+
#![feature(const_trait_impl)]
23
#![stable(feature = "stable", since = "1.0.0")]
34

45
#[stable(feature = "stable", since = "1.0.0")]
56
pub const fn foo() {} //~ ERROR function has missing const stability attribute
67

78
#[unstable(feature = "unstable", issue = "none")]
8-
pub const fn bar() {} // ok for now
9+
pub const fn bar() {} // ok because function is unstable
910

1011
#[stable(feature = "stable", since = "1.0.0")]
1112
pub struct Foo;
@@ -14,11 +15,12 @@ impl Foo {
1415
pub const fn foo() {} //~ ERROR associated function has missing const stability attribute
1516

1617
#[unstable(feature = "unstable", issue = "none")]
17-
pub const fn bar() {} // ok for now
18+
pub const fn bar() {} // ok because function is unstable
1819
}
1920

20-
// FIXME When #![feature(const_trait_impl)] is stabilized, add tests for const
21-
// trait impls. Right now, a "trait methods cannot be stable const fn" error is
22-
// emitted, but that's not in the scope of this test.
21+
// FIXME Once #![feature(const_trait_impl)] is allowed to be stable, add a test
22+
// for const trait impls. Right now, a "trait methods cannot be stable const fn"
23+
// error is emitted. This occurs prior to the lint being tested here, such that
24+
// the lint cannot currently be tested on this use case.
2325

2426
fn main() {}

src/test/ui/stability-attribute/missing-const-stability.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: function has missing const stability attribute
2-
--> $DIR/missing-const-stability.rs:5:1
2+
--> $DIR/missing-const-stability.rs:6:1
33
|
44
LL | pub const fn foo() {}
55
| ^^^^^^^^^^^^^^^^^^^^^
66

77
error: associated function has missing const stability attribute
8-
--> $DIR/missing-const-stability.rs:14:5
8+
--> $DIR/missing-const-stability.rs:15:5
99
|
1010
LL | pub const fn foo() {}
1111
| ^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)