Add tests for calling trait methods on concrete types
This commit is contained in:
parent
7a019b1bd2
commit
323ff193b8
@ -0,0 +1,30 @@
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(const_fn)]
|
||||
|
||||
pub trait Plus {
|
||||
fn plus(self, rhs: Self) -> Self;
|
||||
}
|
||||
|
||||
impl const Plus for i32 {
|
||||
fn plus(self, rhs: Self) -> Self {
|
||||
self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Plus for u32 {
|
||||
fn plus(self, rhs: Self) -> Self {
|
||||
self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn add_i32(a: i32, b: i32) -> i32 {
|
||||
a.plus(b)
|
||||
}
|
||||
|
||||
pub const fn add_u32(a: u32, b: u32) -> u32 {
|
||||
a.plus(b)
|
||||
//~^ ERROR calls in constant functions are limited to constant functions
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,9 @@
|
||||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
--> $DIR/call-const-trait-method.rs:26:5
|
||||
|
|
||||
LL | a.plus(b)
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0015`.
|
@ -0,0 +1,16 @@
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
struct S;
|
||||
trait T {
|
||||
fn foo();
|
||||
}
|
||||
|
||||
fn non_const() {}
|
||||
|
||||
impl const T for S {
|
||||
fn foo() { non_const() }
|
||||
//~^ ERROR
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,12 @@
|
||||
error[E0723]: can only call other `const fn` within a `const fn`, but `const non_const` is not stable as `const fn`
|
||||
--> $DIR/const-check-fns-in-const-impl.rs:12:16
|
||||
|
|
||||
LL | fn foo() { non_const() }
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= 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`.
|
@ -1,10 +1,8 @@
|
||||
error: const trait impls are not yet implemented
|
||||
--> $DIR/feature-gate.rs:9:1
|
||||
error: fatal error triggered by #[rustc_error]
|
||||
--> $DIR/feature-gate.rs:14:1
|
||||
|
|
||||
LL | impl const T for S {}
|
||||
| ^^^^^-----^^^^^^^^^^^
|
||||
| |
|
||||
| const because of this
|
||||
LL | fn main() {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -3,11 +3,12 @@
|
||||
|
||||
#![cfg_attr(gated, feature(const_trait_impl))]
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
struct S;
|
||||
trait T {}
|
||||
impl const T for S {}
|
||||
//[stock]~^ ERROR const trait impls are experimental
|
||||
//[stock,gated]~^^ ERROR const trait impls are not yet implemented
|
||||
|
||||
fn main() {}
|
||||
#[rustc_error]
|
||||
fn main() {} //[gated]~ ERROR fatal error triggered by #[rustc_error]
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0658]: const trait impls are experimental
|
||||
--> $DIR/feature-gate.rs:9:6
|
||||
--> $DIR/feature-gate.rs:10:6
|
||||
|
|
||||
LL | impl const T for S {}
|
||||
| ^^^^^
|
||||
@ -7,14 +7,6 @@ LL | impl const T for S {}
|
||||
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
|
||||
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
|
||||
|
||||
error: const trait impls are not yet implemented
|
||||
--> $DIR/feature-gate.rs:9:1
|
||||
|
|
||||
LL | impl const T for S {}
|
||||
| ^^^^^-----^^^^^^^^^^^
|
||||
| |
|
||||
| const because of this
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
@ -8,10 +8,8 @@ trait T {}
|
||||
|
||||
impl const S {}
|
||||
//~^ ERROR inherent impls cannot be `const`
|
||||
//~| ERROR const trait impls are not yet implemented
|
||||
|
||||
impl const T {}
|
||||
//~^ ERROR inherent impls cannot be `const`
|
||||
//~| ERROR const trait impls are not yet implemented
|
||||
|
||||
fn main() {}
|
||||
|
@ -9,7 +9,7 @@ LL | impl const S {}
|
||||
= note: only trait implementations may be annotated with `const`
|
||||
|
||||
error: inherent impls cannot be `const`
|
||||
--> $DIR/inherent-impl.rs:13:1
|
||||
--> $DIR/inherent-impl.rs:12:1
|
||||
|
|
||||
LL | impl const T {}
|
||||
| ^^^^^-----^^^^^
|
||||
@ -18,21 +18,5 @@ LL | impl const T {}
|
||||
|
|
||||
= note: only trait implementations may be annotated with `const`
|
||||
|
||||
error: const trait impls are not yet implemented
|
||||
--> $DIR/inherent-impl.rs:9:1
|
||||
|
|
||||
LL | impl const S {}
|
||||
| ^^^^^-----^^^^^
|
||||
| |
|
||||
| const because of this
|
||||
|
||||
error: const trait impls are not yet implemented
|
||||
--> $DIR/inherent-impl.rs:13:1
|
||||
|
|
||||
LL | impl const T {}
|
||||
| ^^^^^-----^^^^^
|
||||
| |
|
||||
| const because of this
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user