Skip to content

Commit

Permalink
Check that we can constrain the hidden tpye of a TAIT used in a const…
Browse files Browse the repository at this point in the history
… generic type
  • Loading branch information
oli-obk committed May 31, 2024
1 parent 06c4cc4 commit befcdec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
10 changes: 10 additions & 0 deletions tests/ui/type-alias-impl-trait/const_generic_type.infer.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: `Bar` is forbidden as the type of a const generic parameter
--> $DIR/const_generic_type.rs:7:24
|
LL | async fn test<const N: crate::Bar>() {
| ^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
error[E0283]: type annotations needed
--> $DIR/const_generic_type.rs:6:1
--> $DIR/const_generic_type.rs:7:1
|
LL | async fn test<const N: crate::Bar>() {}
LL | async fn test<const N: crate::Bar>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
|
= note: cannot satisfy `_: std::fmt::Display`

error: `Bar` is forbidden as the type of a const generic parameter
--> $DIR/const_generic_type.rs:6:24
--> $DIR/const_generic_type.rs:7:24
|
LL | async fn test<const N: crate::Bar>() {}
LL | async fn test<const N: crate::Bar>() {
| ^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
Expand Down
10 changes: 7 additions & 3 deletions tests/ui/type-alias-impl-trait/const_generic_type.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
//@edition: 2021
//@revisions: infer no_infer

#![feature(type_alias_impl_trait)]
type Bar = impl std::fmt::Display;

async fn test<const N: crate::Bar>() {}
//~^ ERROR: type annotations needed
//~| ERROR: `Bar` is forbidden as the type of a const generic parameter
async fn test<const N: crate::Bar>() {
//[no_infer]~^ ERROR: type annotations needed
//~^^ ERROR: `Bar` is forbidden as the type of a const generic parameter
#[cfg(infer)]
let x: u32 = N;
}

fn main() {}

0 comments on commit befcdec

Please sign in to comment.