make assoc fn inherit const stability from inherent const impl blocks
This commit is contained in:
parent
1eb0657f78
commit
6cdfb609f9
4 changed files with 38 additions and 2 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
16
tests/ui/traits/const-traits/inherent-impl-stability.rs
Normal file
16
tests/ui/traits/const-traits/inherent-impl-stability.rs
Normal 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() {}
|
||||
13
tests/ui/traits/const-traits/inherent-impl-stability.stderr
Normal file
13
tests/ui/traits/const-traits/inherent-impl-stability.stderr
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue