Skip to content

Commit d1e4d9a

Browse files
committed
const_items_unit_type_default: add tests
1 parent 83dbb0c commit d1e4d9a

File tree

7 files changed

+108
-0
lines changed

7 files changed

+108
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ check-fail
2+
3+
#![feature(const_items_unit_type_default)]
4+
5+
const _ = assert!(false);
6+
//~^ ERROR: evaluation panicked: assertion failed: false [E0080]
7+
const _ = assert!(2 + 2 == 5);
8+
//~^ ERROR: evaluation panicked: assertion failed: 2 + 2 == 5 [E0080]
9+
10+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0080]: evaluation panicked: assertion failed: false
2+
--> $DIR/assert-fail.rs:5:11
3+
|
4+
LL | const _ = assert!(false);
5+
| ^^^^^^^^^^^^^^ evaluation of `_` failed here
6+
7+
error[E0080]: evaluation panicked: assertion failed: 2 + 2 == 5
8+
--> $DIR/assert-fail.rs:7:11
9+
|
10+
LL | const _ = assert!(2 + 2 == 5);
11+
| ^^^^^^^^^^^^^^^^^^^ evaluation of `_` failed here
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0080`.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ check-pass
2+
#![feature(const_items_unit_type_default)]
3+
4+
const _ = assert!(true);
5+
const _ = assert!(2 + 2 == 4);
6+
7+
fn main() {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ check-fail
2+
3+
#![feature(const_items_unit_type_default)]
4+
5+
const _ = {
6+
assert!(true);
7+
2 + 2 //~ ERROR: mismatched types [E0308]
8+
};
9+
10+
const fn id<T>(t: T) -> T {
11+
t
12+
}
13+
14+
const _ = id(2);
15+
//~^ ERROR: mismatched types [E0308]
16+
const _ = id(());
17+
18+
19+
fn main() {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/typecheck.rs:7:5
3+
|
4+
LL | 2 + 2
5+
| ^^^^^ expected `()`, found integer
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/typecheck.rs:14:14
9+
|
10+
LL | const _ = id(2);
11+
| -- ^ expected `()`, found integer
12+
| |
13+
| arguments to this function are incorrect
14+
|
15+
help: the return type of this call is `{integer}` due to the type of the argument passed
16+
--> $DIR/typecheck.rs:14:11
17+
|
18+
LL | const _ = id(2);
19+
| ^^^-^
20+
| |
21+
| this argument influences the return type of `id`
22+
note: function defined here
23+
--> $DIR/typecheck.rs:10:10
24+
|
25+
LL | const fn id<T>(t: T) -> T {
26+
| ^^ ----
27+
28+
error: aborting due to 2 previous errors
29+
30+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ check-pass
2+
#![feature(const_items_unit_type_default)]
3+
4+
#[cfg(false)]
5+
const _ = assert!(false);
6+
7+
#[expect(unused)]
8+
const _ = {
9+
let a = 1;
10+
assert!(true);
11+
};
12+
13+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ check-pass
2+
#![feature(const_items_unit_type_default)]
3+
4+
macro_rules! foo {
5+
($item:item) => {
6+
$item
7+
};
8+
}
9+
10+
foo!(const _ = {};);
11+
12+
fn main() {
13+
foo!(const _ = {};);
14+
}

0 commit comments

Comments
 (0)