-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test
rustc_const_unstable
on trait fns
- Loading branch information
1 parent
8e7609b
commit 4992eb2
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#![allow(incomplete_features)] | ||
#![feature(allow_internal_unstable)] | ||
#![feature(const_add)] | ||
#![feature(const_trait_impl)] | ||
#![feature(staged_api)] | ||
|
||
pub struct Int(i32); | ||
|
||
#[rustc_const_unstable(feature = "const_add", issue = "none")] | ||
impl const std::ops::Add for Int { | ||
type Output = Self; | ||
|
||
fn add(self, rhs: Self) -> Self { | ||
Int(self.0 + rhs.0) | ||
} | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_stable(feature = "rust1", since = "1.0.0")] | ||
pub const fn foo() -> Int { | ||
Int(1i32) + Int(2i32) | ||
//~^ ERROR can only call other `const fn` within a `const fn` | ||
} | ||
|
||
// ok | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_unstable(feature = "bar", issue = "none")] | ||
pub const fn bar() -> Int { | ||
Int(1i32) + Int(2i32) | ||
} | ||
|
||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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` | ||
--> $DIR/stability.rs:21:5 | ||
| | ||
LL | Int(1i32) + Int(2i32) | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 | ||
= help: add `#![feature(const_fn)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0723`. |