Test for const trait impls behind feature gates
This commit is contained in:
parent
b3a79832c0
commit
ee9c614ece
4 changed files with 89 additions and 0 deletions
|
@ -0,0 +1,22 @@
|
||||||
|
#![feature(const_trait_impl)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
#![feature(staged_api)]
|
||||||
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
pub trait MyTrait {
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
fn func();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
pub struct Unstable;
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[rustc_const_unstable(feature = "staged", issue = "none")]
|
||||||
|
impl const MyTrait for Unstable {
|
||||||
|
fn func() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
39
src/test/ui/rfc-2632-const-trait-impl/staged-api.rs
Normal file
39
src/test/ui/rfc-2632-const-trait-impl/staged-api.rs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
// revisions: stock staged
|
||||||
|
#![cfg_attr(staged, feature(staged))]
|
||||||
|
|
||||||
|
#![feature(const_trait_impl)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
#![feature(staged_api)]
|
||||||
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
||||||
|
// aux-build: staged-api.rs
|
||||||
|
extern crate staged_api;
|
||||||
|
|
||||||
|
use staged_api::*;
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
pub struct Stable;
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(staged, rustc_const_stable(feature = "rust1", since = "1.0.0"))]
|
||||||
|
// ^ should trigger error with or without the attribute
|
||||||
|
impl const MyTrait for Stable {
|
||||||
|
fn func() { //~ ERROR trait methods cannot be stable const fn
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn non_const_context() {
|
||||||
|
Unstable::func();
|
||||||
|
Stable::func();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "none", issue = "none")]
|
||||||
|
const fn const_context() {
|
||||||
|
Unstable::func();
|
||||||
|
//[stock]~^ ERROR `<staged_api::Unstable as staged_api::MyTrait>::func` is not yet stable as a const fn
|
||||||
|
Stable::func();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,10 @@
|
||||||
|
error: trait methods cannot be stable const fn
|
||||||
|
--> $DIR/staged-api.rs:22:5
|
||||||
|
|
|
||||||
|
LL | / fn func() {
|
||||||
|
LL | |
|
||||||
|
LL | | }
|
||||||
|
| |_____^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
error: trait methods cannot be stable const fn
|
||||||
|
--> $DIR/staged-api.rs:22:5
|
||||||
|
|
|
||||||
|
LL | / fn func() {
|
||||||
|
LL | |
|
||||||
|
LL | | }
|
||||||
|
| |_____^
|
||||||
|
|
||||||
|
error: `<staged_api::Unstable as staged_api::MyTrait>::func` is not yet stable as a const fn
|
||||||
|
--> $DIR/staged-api.rs:34:5
|
||||||
|
|
|
||||||
|
LL | Unstable::func();
|
||||||
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: add `#![feature(staged)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
Loading…
Add table
Reference in a new issue