Skip to content

Commit 45391bd

Browse files
committed
Add tests for mismatched type_const
1 parent ad69a7a commit 45391bd

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ known-bug: #132980
2+
// Move this test to tests/ui/const-generics/mgca/type_const-only-in-trait.rs
3+
// once fixed.
4+
5+
#![expect(incomplete_features)]
6+
#![feature(associated_const_equality, min_generic_const_args)]
7+
8+
trait GoodTr {
9+
#[type_const]
10+
const NUM: usize;
11+
}
12+
13+
struct BadS;
14+
15+
impl GoodTr for BadS {
16+
const NUM: usize = 42;
17+
}
18+
19+
fn accept_good_tr<const N: usize, T: GoodTr<NUM = { N }>>(_x: &T) {}
20+
21+
fn main() {
22+
accept_good_tr(&BadS);
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![expect(incomplete_features)]
2+
#![feature(associated_const_equality, min_generic_const_args)]
3+
4+
trait BadTr {
5+
const NUM: usize;
6+
}
7+
8+
struct GoodS;
9+
10+
impl BadTr for GoodS {
11+
#[type_const]
12+
const NUM: usize = 84;
13+
}
14+
15+
fn accept_bad_tr<const N: usize, T: BadTr<NUM = { N }>>(_x: &T) {}
16+
//~^ ERROR use of trait associated const without `#[type_const]`
17+
18+
fn main() {
19+
accept_bad_tr::<84, _>(&GoodS);
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: use of trait associated const without `#[type_const]`
2+
--> $DIR/type_const-only-in-impl.rs:15:43
3+
|
4+
LL | fn accept_bad_tr<const N: usize, T: BadTr<NUM = { N }>>(_x: &T) {}
5+
| ^^^^^^^^^^^
6+
|
7+
= note: the declaration in the trait must be marked with `#[type_const]`
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)