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:
commit
4262598dd4
@ -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() {
|
||||
|
||||
}
|
||||
}
|
@ -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() {}
|
@ -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();
|
||||
| ^^^^^^^^^^^^^^^
|
@ -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() {}
|
@ -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();
|
||||
| ^^^^^^^^^^^^
|
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…
x
Reference in New Issue
Block a user