Rollup merge of #86775 - fee1-dead:impl-const-test, r=jonas-schievink

Test for const trait impls behind feature gates

 - Make the previous cross-crate tests use revisions instead of being separate files
 - Added test for gating const trait impls.

cc ``@oli-obk`` ``@jonas-schievink``
This commit is contained in:
Yuki Okushi 2021-07-02 06:20:31 +09:00 committed by GitHub
commit 4262598dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 95 additions and 22 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

@ -1,18 +0,0 @@
// aux-build: cross-crate.rs
extern crate cross_crate;
use cross_crate::*;
fn non_const_context() {
NonConst.func();
Const.func();
}
const fn const_context() {
NonConst.func();
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants
Const.func();
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants
}
fn main() {}

View File

@ -1,5 +1,5 @@
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
--> $DIR/cross-crate-feature-enabled.rs:15:5
--> $DIR/cross-crate.rs:16:5
|
LL | NonConst.func();
| ^^^^^^^^^^^^^^^

View File

@ -1,4 +1,5 @@
#![feature(const_trait_impl)]
// revisions: stock gated
#![cfg_attr(gated, feature(const_trait_impl))]
#![allow(incomplete_features)]
// aux-build: cross-crate.rs
@ -15,6 +16,7 @@ const fn const_context() {
NonConst.func();
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants
Const.func();
//[stock]~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants
}
fn main() {}

View File

@ -1,11 +1,11 @@
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
--> $DIR/cross-crate-feature-disabled.rs:12:5
--> $DIR/cross-crate.rs:16:5
|
LL | NonConst.func();
| ^^^^^^^^^^^^^^^
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
--> $DIR/cross-crate-feature-disabled.rs:14:5
--> $DIR/cross-crate.rs:18:5
|
LL | Const.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