Test for const trait impls behind feature gates

This commit is contained in:
Deadbeef 2021-07-01 18:43:08 +08:00
parent b3a79832c0
commit ee9c614ece
No known key found for this signature in database
GPG Key ID: 6525773485376D92
4 changed files with 89 additions and 0 deletions

View File

@ -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() {
}
}

View 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() {}

View File

@ -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

View File

@ -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