Skip to content

Commit 6cdfb60

Browse files
committed
make assoc fn inherit const stability from inherent const impl blocks
1 parent 1eb0657 commit 6cdfb60

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
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
}

tests/ui/traits/const-traits/auxiliary/staged-api.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ compile-flags: -Znext-solver
21
#![feature(const_trait_impl)]
32
#![feature(staged_api)]
43
#![stable(feature = "rust1", since = "1.0.0")]
@@ -19,6 +18,14 @@ impl const MyTrait for Unstable {
1918
fn func() {}
2019
}
2120

21+
// tested in inherent-impl-stability.rs instead to avoid clutter
22+
#[stable(feature = "rust1", since = "1.0.0")]
23+
#[rustc_const_unstable(feature = "unstable", issue = "none")]
24+
const impl Unstable {
25+
#[stable(feature = "rust1", since = "1.0.0")]
26+
pub fn inherent_func() {}
27+
}
28+
2229
#[stable(feature = "rust1", since = "1.0.0")]
2330
pub struct Unstable2;
2431

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ aux-build: staged-api.rs
2+
extern crate staged_api;
3+
4+
use staged_api::*;
5+
6+
// Const stability has no impact on usage in non-const contexts.
7+
fn non_const_context() {
8+
Unstable::inherent_func();
9+
}
10+
11+
const fn stable_const_context() {
12+
Unstable::inherent_func();
13+
//~^ ERROR: `staged_api::Unstable::inherent_func` is not yet stable as a const fn
14+
}
15+
16+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: `staged_api::Unstable::inherent_func` is not yet stable as a const fn
2+
--> $DIR/inherent-impl-stability.rs:12:5
3+
|
4+
LL | Unstable::inherent_func();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
help: add `#![feature(unstable)]` to the crate attributes to enable
8+
|
9+
LL + #![feature(unstable)]
10+
|
11+
12+
error: aborting due to 1 previous error
13+

0 commit comments

Comments
 (0)