Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
9 changes: 8 additions & 1 deletion tests/ui/traits/const-traits/auxiliary/staged-api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ compile-flags: -Znext-solver
#![feature(const_trait_impl)]
#![feature(staged_api)]
#![stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions tests/ui/traits/const-traits/inherent-impl-stability.rs
Original file line number Diff line number Diff line change
@@ -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() {}
13 changes: 13 additions & 0 deletions tests/ui/traits/const-traits/inherent-impl-stability.stderr
Original file line number Diff line number Diff line change
@@ -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

Loading