Skip to content

Commit 4262598

Browse files
authored
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``
2 parents 6fc27cd + ee9c614 commit 4262598

8 files changed

+95
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(const_trait_impl)]
2+
#![allow(incomplete_features)]
3+
4+
#![feature(staged_api)]
5+
#![stable(feature = "rust1", since = "1.0.0")]
6+
7+
#[stable(feature = "rust1", since = "1.0.0")]
8+
pub trait MyTrait {
9+
#[stable(feature = "rust1", since = "1.0.0")]
10+
fn func();
11+
}
12+
13+
#[stable(feature = "rust1", since = "1.0.0")]
14+
pub struct Unstable;
15+
16+
#[stable(feature = "rust1", since = "1.0.0")]
17+
#[rustc_const_unstable(feature = "staged", issue = "none")]
18+
impl const MyTrait for Unstable {
19+
fn func() {
20+
21+
}
22+
}

src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.rs

-18
This file was deleted.

src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.stderr renamed to src/test/ui/rfc-2632-const-trait-impl/cross-crate.gated.stderr

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

src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.rs renamed to src/test/ui/rfc-2632-const-trait-impl/cross-crate.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![feature(const_trait_impl)]
1+
// revisions: stock gated
2+
#![cfg_attr(gated, feature(const_trait_impl))]
23
#![allow(incomplete_features)]
34

45
// aux-build: cross-crate.rs
@@ -15,6 +16,7 @@ const fn const_context() {
1516
NonConst.func();
1617
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1718
Const.func();
19+
//[stock]~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1820
}
1921

2022
fn main() {}

src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-disabled.stderr renamed to src/test/ui/rfc-2632-const-trait-impl/cross-crate.stock.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
2-
--> $DIR/cross-crate-feature-disabled.rs:12:5
2+
--> $DIR/cross-crate.rs:16:5
33
|
44
LL | NonConst.func();
55
| ^^^^^^^^^^^^^^^
66

77
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
8-
--> $DIR/cross-crate-feature-disabled.rs:14:5
8+
--> $DIR/cross-crate.rs:18:5
99
|
1010
LL | Const.func();
1111
| ^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// revisions: stock staged
2+
#![cfg_attr(staged, feature(staged))]
3+
4+
#![feature(const_trait_impl)]
5+
#![allow(incomplete_features)]
6+
7+
#![feature(staged_api)]
8+
#![stable(feature = "rust1", since = "1.0.0")]
9+
10+
// aux-build: staged-api.rs
11+
extern crate staged_api;
12+
13+
use staged_api::*;
14+
15+
#[stable(feature = "rust1", since = "1.0.0")]
16+
pub struct Stable;
17+
18+
#[stable(feature = "rust1", since = "1.0.0")]
19+
#[cfg_attr(staged, rustc_const_stable(feature = "rust1", since = "1.0.0"))]
20+
// ^ should trigger error with or without the attribute
21+
impl const MyTrait for Stable {
22+
fn func() { //~ ERROR trait methods cannot be stable const fn
23+
24+
}
25+
}
26+
27+
fn non_const_context() {
28+
Unstable::func();
29+
Stable::func();
30+
}
31+
32+
#[unstable(feature = "none", issue = "none")]
33+
const fn const_context() {
34+
Unstable::func();
35+
//[stock]~^ ERROR `<staged_api::Unstable as staged_api::MyTrait>::func` is not yet stable as a const fn
36+
Stable::func();
37+
}
38+
39+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: trait methods cannot be stable const fn
2+
--> $DIR/staged-api.rs:22:5
3+
|
4+
LL | / fn func() {
5+
LL | |
6+
LL | | }
7+
| |_____^
8+
9+
error: aborting due to previous error
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: trait methods cannot be stable const fn
2+
--> $DIR/staged-api.rs:22:5
3+
|
4+
LL | / fn func() {
5+
LL | |
6+
LL | | }
7+
| |_____^
8+
9+
error: `<staged_api::Unstable as staged_api::MyTrait>::func` is not yet stable as a const fn
10+
--> $DIR/staged-api.rs:34:5
11+
|
12+
LL | Unstable::func();
13+
| ^^^^^^^^^^^^^^^^
14+
|
15+
= help: add `#![feature(staged)]` to the crate attributes to enable
16+
17+
error: aborting due to 2 previous errors
18+

0 commit comments

Comments
 (0)