Skip to content

Commit 4b9363b

Browse files
committed
Move const tests to ui tests
1 parent d894026 commit 4b9363b

11 files changed

+69
-141
lines changed

tests/consts.rs

Lines changed: 0 additions & 141 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Error: check_trait_impl(impl <const> Foo < const ^const0_0 > for (rigid (scalar u32)) where [type_of_const ^const0_0 is (rigid (scalar u32))] { })
2+
3+
Caused by:
4+
failed to prove {Foo((rigid (scalar u32)), const !const_1)} given {@ ConstHasType(!const_1 , (rigid (scalar u32)))}, got {}

tests/ui/consts/generic_mismatch.🔬

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
crate Foo {
3+
trait Foo<const C> where [type_of_const C is bool] {}
4+
5+
impl<const C> Foo<const C> for u32 where [type_of_const C is u32] {}
6+
}
7+
]

tests/ui/consts/holds.🔬

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@check-pass
2+
[
3+
crate Foo {
4+
trait Foo<const C> where [type_of_const C is bool] {}
5+
6+
impl<> Foo<const true> for u32 where [] {}
7+
}
8+
]

tests/ui/consts/mismatch.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Error: check_trait_impl(impl <> Foo < const 42_(rigid (scalar u32)) > for (rigid (scalar u32)) where [] { })
2+
3+
Caused by:
4+
failed to prove {Foo((rigid (scalar u32)), const 42_(rigid (scalar u32)))} given {}, got {}

tests/ui/consts/mismatch.🔬

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
crate Foo {
3+
trait Foo<const C> where [type_of_const C is bool] {}
4+
5+
impl<> Foo<const 42_u32> for u32 where [] {}
6+
}
7+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// This test is weird, but it's also not something rustc ever generates.
2+
/// Types on const generics only get exactly one `type_of_const` bound.
3+
/// Either way, it is still sound, because there is no constant that possibly
4+
/// satisfies those bounds (similar to how there is no type that satisfies `Drop` + `Copy`).
5+
//@check-pass
6+
[
7+
crate Foo {
8+
trait Foo<const C> where [type_of_const C is bool, type_of_const C is u32] {}
9+
}
10+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Error: check_trait(Foo)
2+
3+
Caused by:
4+
0: prove_where_clause_well_formed(type_of_const 0_(rigid (scalar bool)) is (rigid (scalar u32)))
5+
1: failed to prove {(rigid (scalar u32)) = (rigid (scalar bool))} given {@ ConstHasType(0_(rigid (scalar bool)) , (rigid (scalar u32)))}, got {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// This test is the short version of `generic_mismatch`, skipping
2+
/// substituting and directly going to a wrong constant.
3+
[
4+
crate Foo {
5+
trait Foo<> where [type_of_const true is u32] {}
6+
}
7+
]

tests/ui/consts/ok.🔬

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@check-pass
2+
[
3+
crate Foo {
4+
trait Foo<const C> where [type_of_const C is bool] {}
5+
trait Bar<const C> where [type_of_const C is u32] {}
6+
7+
impl<const C> Foo<const C> for u32 where [type_of_const C is bool] {}
8+
}
9+
]

0 commit comments

Comments
 (0)