Skip to content

Commit c424510

Browse files
committed
Add tests for cross-crate usage of impl const
1 parent 3b9453b commit c424510

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
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+
pub trait MyTrait {
5+
fn func(self);
6+
}
7+
8+
pub struct NonConst;
9+
10+
impl MyTrait for NonConst {
11+
fn func(self) {
12+
13+
}
14+
}
15+
16+
pub struct Const;
17+
18+
impl const MyTrait for Const {
19+
fn func(self) {
20+
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// aux-build: cross-crate.rs
2+
extern crate cross_crate;
3+
4+
use cross_crate::*;
5+
6+
fn non_const_context() {
7+
NonConst.func();
8+
Const.func();
9+
}
10+
11+
const fn const_context() {
12+
NonConst.func();
13+
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants
14+
Const.func();
15+
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants
16+
}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
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
3+
|
4+
LL | NonConst.func();
5+
| ^^^^^^^^^^^^^^^
6+
7+
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
9+
|
10+
LL | Const.func();
11+
| ^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0015`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(const_trait_impl)]
2+
#![allow(incomplete_features)]
3+
4+
// aux-build: cross-crate.rs
5+
extern crate cross_crate;
6+
7+
use cross_crate::*;
8+
9+
fn non_const_context() {
10+
NonConst.func();
11+
Const.func();
12+
}
13+
14+
const fn const_context() {
15+
NonConst.func();
16+
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants
17+
Const.func();
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
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
3+
|
4+
LL | NonConst.func();
5+
| ^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0015`.

0 commit comments

Comments
 (0)