Skip to content

Commit 4e7327c

Browse files
committed
make assoc fn inherit const stability from inherent const impl blocks
Currently, one cannot add any const stability annotations on the individual assoc fns at all, as the specific pass that checks for const stability on const fn seems to run as a HIR visitor. I suspect there are things to be cleaned up there.
1 parent 32b53c9 commit 4e7327c

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

compiler/rustc_passes/src/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn inherit_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
5454
match def_kind {
5555
DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => {
5656
match tcx.def_kind(tcx.local_parent(def_id)) {
57-
DefKind::Impl { of_trait: true } => true,
57+
DefKind::Impl { .. } => true,
5858
_ => false,
5959
}
6060
}

library/alloc/src/raw_vec/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ const fn min_non_zero_cap(size: usize) -> usize {
165165
}
166166
}
167167

168+
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
168169
const impl<T, A: [const] Allocator + [const] Destruct> RawVec<T, A> {
169170
/// Like `with_capacity`, but parameterized over the choice of
170171
/// allocator for the returned `RawVec`.
171172
#[cfg(not(no_global_oom_handling))]
172173
#[inline]
173-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
174174
pub(crate) fn with_capacity_in(capacity: usize, alloc: A) -> Self
175175
{
176176
Self {
@@ -183,7 +183,6 @@ const impl<T, A: [const] Allocator + [const] Destruct> RawVec<T, A> {
183183
/// caller to ensure `len == self.capacity()`.
184184
#[cfg(not(no_global_oom_handling))]
185185
#[inline(never)]
186-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
187186
pub(crate) fn grow_one(&mut self)
188187
{
189188
// SAFETY: All calls on self.inner pass T::LAYOUT as the elem_layout
@@ -411,10 +410,10 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawVec<T, A> {
411410
}
412411
}
413412

413+
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
414414
const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
415415
#[cfg(not(no_global_oom_handling))]
416416
#[inline]
417-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
418417
fn with_capacity_in(capacity: usize, alloc: A, elem_layout: Layout) -> Self
419418
{
420419
match Self::try_allocate_in(capacity, AllocInit::Uninitialized, alloc, elem_layout) {
@@ -428,7 +427,6 @@ const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
428427
Err(err) => handle_error(err),
429428
}
430429
}
431-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
432430
fn try_allocate_in(
433431
capacity: usize,
434432
init: AllocInit,
@@ -474,7 +472,6 @@ const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
474472
/// - `elem_layout`'s size must be a multiple of its alignment
475473
#[cfg(not(no_global_oom_handling))]
476474
#[inline]
477-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
478475
unsafe fn grow_one(&mut self, elem_layout: Layout)
479476
{
480477
// SAFETY: Precondition passed to caller
@@ -489,7 +486,6 @@ const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
489486
/// initially construct `self`
490487
/// - `elem_layout`'s size must be a multiple of its alignment
491488
/// - The sum of `len` and `additional` must be greater than the current capacity
492-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
493489
unsafe fn grow_amortized(
494490
&mut self,
495491
len: usize,
@@ -532,7 +528,6 @@ const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
532528
// not marked inline(never) since we want optimizers to be able to observe the specifics of this
533529
// function, see tests/codegen-llvm/vec-reserve-extend.rs.
534530
#[cold]
535-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
536531
unsafe fn finish_grow(
537532
&self,
538533
cap: usize,

library/alloc/src/vec/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ impl<T> Vec<T> {
847847
}
848848
}
849849

850+
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
850851
const impl<T, A: [const] Allocator + [const] Destruct> Vec<T, A> {
851852
/// Constructs a new, empty `Vec<T, A>` with at least the specified capacity
852853
/// with the provided allocator.
@@ -906,7 +907,6 @@ const impl<T, A: [const] Allocator + [const] Destruct> Vec<T, A> {
906907
#[cfg(not(no_global_oom_handling))]
907908
#[inline]
908909
#[unstable(feature = "allocator_api", issue = "32838")]
909-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
910910
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self
911911
{
912912
Vec { buf: RawVec::with_capacity_in(capacity, alloc), len: 0 }
@@ -937,7 +937,6 @@ const impl<T, A: [const] Allocator + [const] Destruct> Vec<T, A> {
937937
#[inline]
938938
#[stable(feature = "rust1", since = "1.0.0")]
939939
#[rustc_confusables("push_back", "put", "append")]
940-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
941940
pub fn push(&mut self, value: T)
942941
{
943942
let _ = self.push_mut(value);
@@ -975,7 +974,6 @@ const impl<T, A: [const] Allocator + [const] Destruct> Vec<T, A> {
975974
#[inline]
976975
#[unstable(feature = "push_mut", issue = "135974")]
977976
#[must_use = "if you don't need a reference to the value, use `Vec::push` instead"]
978-
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
979977
pub fn push_mut(&mut self, value: T) -> &mut T
980978
{
981979
// Inform codegen that the length does not change across grow_one().

0 commit comments

Comments
 (0)