Skip to content

Commit 4992eb2

Browse files
Test rustc_const_unstable on trait fns
1 parent 8e7609b commit 4992eb2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![allow(incomplete_features)]
2+
#![feature(allow_internal_unstable)]
3+
#![feature(const_add)]
4+
#![feature(const_trait_impl)]
5+
#![feature(staged_api)]
6+
7+
pub struct Int(i32);
8+
9+
#[rustc_const_unstable(feature = "const_add", issue = "none")]
10+
impl const std::ops::Add for Int {
11+
type Output = Self;
12+
13+
fn add(self, rhs: Self) -> Self {
14+
Int(self.0 + rhs.0)
15+
}
16+
}
17+
18+
#[stable(feature = "rust1", since = "1.0.0")]
19+
#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
20+
pub const fn foo() -> Int {
21+
Int(1i32) + Int(2i32)
22+
//~^ ERROR can only call other `const fn` within a `const fn`
23+
}
24+
25+
// ok
26+
#[stable(feature = "rust1", since = "1.0.0")]
27+
#[rustc_const_unstable(feature = "bar", issue = "none")]
28+
pub const fn bar() -> Int {
29+
Int(1i32) + Int(2i32)
30+
}
31+
32+
33+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0723]: can only call other `const fn` within a `const fn`, but `const <Int as std::ops::Add>::add` is not stable as `const fn`
2+
--> $DIR/stability.rs:21:5
3+
|
4+
LL | Int(1i32) + Int(2i32)
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
8+
= help: add `#![feature(const_fn)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0723`.

0 commit comments

Comments
 (0)