Skip to content

Test for const trait impls behind feature gates #86775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/auxiliary/staged-api.rs
Original file line number Diff line number Diff line change
@@ -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() {

}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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();
| ^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {}
Original file line number Diff line number Diff line change
@@ -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();
| ^^^^^^^^^^^^
Expand Down
39 changes: 39 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/staged-api.rs
Original file line number Diff line number Diff line change
@@ -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() {}
10 changes: 10 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/staged-api.staged.stderr
Original file line number Diff line number Diff line change
@@ -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

18 changes: 18 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/staged-api.stock.stderr
Original file line number Diff line number Diff line change
@@ -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