make assoc fn inherit const stability from inherent const impl blocks

This commit is contained in:
Deadbeef 2025-11-28 23:31:41 -05:00
parent 1eb0657f78
commit 6cdfb609f9
4 changed files with 38 additions and 2 deletions

View file

@ -54,7 +54,7 @@ fn inherit_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
match def_kind {
DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => {
match tcx.def_kind(tcx.local_parent(def_id)) {
DefKind::Impl { of_trait: true } => true,
DefKind::Impl { .. } => true,
_ => false,
}
}

View file

@ -1,4 +1,3 @@
//@ compile-flags: -Znext-solver
#![feature(const_trait_impl)]
#![feature(staged_api)]
#![stable(feature = "rust1", since = "1.0.0")]
@ -19,6 +18,14 @@ impl const MyTrait for Unstable {
fn func() {}
}
// tested in inherent-impl-stability.rs instead to avoid clutter
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "unstable", issue = "none")]
const impl Unstable {
#[stable(feature = "rust1", since = "1.0.0")]
pub fn inherent_func() {}
}
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Unstable2;

View file

@ -0,0 +1,16 @@
//@ aux-build: staged-api.rs
extern crate staged_api;
use staged_api::*;
// Const stability has no impact on usage in non-const contexts.
fn non_const_context() {
Unstable::inherent_func();
}
const fn stable_const_context() {
Unstable::inherent_func();
//~^ ERROR: `staged_api::Unstable::inherent_func` is not yet stable as a const fn
}
fn main() {}

View file

@ -0,0 +1,13 @@
error: `staged_api::Unstable::inherent_func` is not yet stable as a const fn
--> $DIR/inherent-impl-stability.rs:12:5
|
LL | Unstable::inherent_func();
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: add `#![feature(unstable)]` to the crate attributes to enable
|
LL + #![feature(unstable)]
|
error: aborting due to 1 previous error