Skip to content

Commit 0cd118d

Browse files
authoredNov 12, 2020
Rollup merge of #78916 - lcnr:const-generics-tests, r=varkor
extend const generics test suite should implement most of #78433, especially all parts of [the hackmd](https://hackmd.io/WnFmN4MjRCqAjGmYfYcu2A?view) which I did not explicitly mention in that issue. r? ``@varkor``
2 parents 55794e4 + a9eacf3 commit 0cd118d

23 files changed

+1126
-0
lines changed
 
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
// edition:2018
3+
#![feature(min_const_generics)]
4+
trait ValidTrait {}
5+
6+
/// This has docs
7+
pub fn extern_fn<const N: usize>() -> impl Iterator<Item = [u8; N]> {
8+
loop {}
9+
}
10+
11+
pub trait Trait<const N: usize> {}
12+
impl Trait<1> for u8 {}
13+
impl Trait<2> for u8 {}
14+
impl<const N: usize> Trait<N> for [u8; N] {}
15+
16+
/// This also has docs
17+
pub fn test<const N: usize>() -> impl Trait<N> where u8: Trait<N> {
18+
loop {}
19+
}
20+
21+
/// Document all the functions
22+
pub async fn a_sink<const N: usize>(v: [u8; N]) -> impl Trait<N> {
23+
loop {}
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// edition:2018
2+
#![feature(min_const_generics)]
3+
4+
pub fn extern_fn<const N: usize>() -> impl Iterator<Item = [u8; N]> {
5+
[[0; N]; N].iter().copied()
6+
}
7+
8+
pub struct ExternTy<const N: usize> {
9+
pub inner: [u8; N],
10+
}
11+
12+
pub type TyAlias<const N: usize> = ExternTy<N>;
13+
14+
pub trait WTrait<const N: usize, const M: usize> {
15+
fn hey<const P: usize>() -> usize {
16+
N + M + P
17+
}
18+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// edition:2018
2+
// aux-build: extern_crate.rs
3+
#![feature(min_const_generics)]
4+
#![crate_name = "foo"]
5+
6+
extern crate extern_crate;
7+
// @has foo/fn.extern_fn.html '//pre[@class="rust fn"]' \
8+
// 'pub fn extern_fn<const N: usize>() -> impl Iterator<Item = [u8; N]>'
9+
pub use extern_crate::extern_fn;
10+
// @has foo/struct.ExternTy.html '//pre[@class="rust struct"]' \
11+
// 'pub struct ExternTy<const N: usize> {'
12+
pub use extern_crate::ExternTy;
13+
// @has foo/type.TyAlias.html '//pre[@class="rust typedef"]' \
14+
// 'type TyAlias<const N: usize> = ExternTy<N>;'
15+
pub use extern_crate::TyAlias;
16+
// @has foo/trait.WTrait.html '//pre[@class="rust trait"]' \
17+
// 'pub trait WTrait<const N: usize, const M: usize>'
18+
// @has - '//*[@class="rust trait"]' 'fn hey<const P: usize>() -> usize'
19+
pub use extern_crate::WTrait;
20+
21+
// @has foo/trait.Trait.html '//pre[@class="rust trait"]' \
22+
// 'pub trait Trait<const N: usize>'
23+
// @has - '//*[@id="impl-Trait%3C1_usize%3E-for-u8"]//code' 'impl Trait<1_usize> for u8'
24+
// @has - '//*[@id="impl-Trait%3C2_usize%3E-for-u8"]//code' 'impl Trait<2_usize> for u8'
25+
// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//code' 'impl Trait<{1 + 2}> for u8'
26+
// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//code' \
27+
// 'impl<const N: usize> Trait<N> for [u8; N]'
28+
pub trait Trait<const N: usize> {}
29+
impl Trait<1> for u8 {}
30+
impl Trait<2> for u8 {}
31+
impl Trait<{1 + 2}> for u8 {}
32+
impl<const N: usize> Trait<N> for [u8; N] {}
33+
34+
// @has foo/struct.Foo.html '//pre[@class="rust struct"]' \
35+
// 'pub struct Foo<const N: usize> where u8: Trait<N>'
36+
pub struct Foo<const N: usize> where u8: Trait<N>;
37+
// @has foo/struct.Bar.html '//pre[@class="rust struct"]' 'pub struct Bar<T, const N: usize>(_)'
38+
pub struct Bar<T, const N: usize>([T; N]);
39+
40+
// @has foo/struct.Foo.html '//h3[@id="impl"]/code' 'impl<const M: usize> Foo<M> where u8: Trait<M>'
41+
impl<const M: usize> Foo<M> where u8: Trait<M> {
42+
// @has - '//*[@id="associatedconstant.FOO_ASSOC"]' 'pub const FOO_ASSOC: usize'
43+
pub const FOO_ASSOC: usize = M + 13;
44+
45+
// @has - '//*[@id="method.hey"]' 'pub fn hey<const N: usize>(&self) -> Bar<u8, N>'
46+
pub fn hey<const N: usize>(&self) -> Bar<u8, N> {
47+
Bar([0; N])
48+
}
49+
}
50+
51+
// @has foo/struct.Bar.html '//h3[@id="impl"]/code' 'impl<const M: usize> Bar<u8, M>'
52+
impl<const M: usize> Bar<u8, M> {
53+
// @has - '//*[@id="method.hey"]' \
54+
// 'pub fn hey<const N: usize>(&self) -> Foo<N> where u8: Trait<N>'
55+
pub fn hey<const N: usize>(&self) -> Foo<N> where u8: Trait<N> {
56+
Foo
57+
}
58+
}
59+
60+
// @has foo/fn.test.html '//pre[@class="rust fn"]' \
61+
// 'pub fn test<const N: usize>() -> impl Trait<N> where u8: Trait<N>'
62+
pub fn test<const N: usize>() -> impl Trait<N> where u8: Trait<N> {
63+
2u8
64+
}
65+
66+
// @has foo/fn.a_sink.html '//pre[@class="rust fn"]' \
67+
// 'pub async fn a_sink<const N: usize>(v: [u8; N]) -> impl Trait<N>'
68+
pub async fn a_sink<const N: usize>(v: [u8; N]) -> impl Trait<N> {
69+
v
70+
}
71+
72+
// @has foo/fn.b_sink.html '//pre[@class="rust fn"]' \
73+
// 'pub async fn b_sink<const N: usize>(__arg0: impl Trait<N>)'
74+
// FIXME(const_generics): This should be `_` not `__arg0`.
75+
pub async fn b_sink<const N: usize>(_: impl Trait<N>) {}
76+
77+
// @has foo/fn.concrete.html '//pre[@class="rust fn"]' \
78+
// 'pub fn concrete() -> [u8; 22]'
79+
pub fn concrete() -> [u8; 3 + std::mem::size_of::<u64>() << 1] {
80+
Default::default()
81+
}
82+
83+
// @has foo/type.Faz.html '//pre[@class="rust typedef"]' \
84+
// 'type Faz<const N: usize> = [u8; N];'
85+
pub type Faz<const N: usize> = [u8; N];
86+
// @has foo/type.Fiz.html '//pre[@class="rust typedef"]' \
87+
// 'type Fiz<const N: usize> = [[u8; N]; 48];'
88+
pub type Fiz<const N: usize> = [[u8; N]; 3 << 4];
89+
90+
macro_rules! define_me {
91+
($t:tt<$q:tt>) => {
92+
pub struct $t<const $q: usize>([u8; $q]);
93+
}
94+
}
95+
96+
// @has foo/struct.Foz.html '//pre[@class="rust struct"]' \
97+
// 'pub struct Foz<const N: usize>(_);'
98+
define_me!(Foz<N>);
99+
100+
trait Q {
101+
const ASSOC: usize;
102+
}
103+
104+
impl<const N: usize> Q for [u8; N] {
105+
const ASSOC: usize = N;
106+
}
107+
108+
// @has foo/fn.q_user.html '//pre[@class="rust fn"]' \
109+
// 'pub fn q_user() -> [u8; 13]'
110+
pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {
111+
[0; <[u8; 13] as Q>::ASSOC]
112+
}
113+
114+
// @has foo/union.Union.html '//pre[@class="rust union"]' \
115+
// 'pub union Union<const N: usize>'
116+
pub union Union<const N: usize> {
117+
// @has - //pre "pub arr: [u8; N]"
118+
pub arr: [u8; N],
119+
// @has - //pre "pub another_arr: [(); N]"
120+
pub another_arr: [(); N],
121+
}
122+
123+
// @has foo/enum.Enum.html '//pre[@class="rust enum"]' \
124+
// 'pub enum Enum<const N: usize>'
125+
pub enum Enum<const N: usize> {
126+
// @has - //pre "Variant([u8; N])"
127+
Variant([u8; N]),
128+
// @has - //pre "EmptyVariant"
129+
EmptyVariant,
130+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
2+
--> $DIR/associated-type-bound-fail.rs:14:5
3+
|
4+
LL | type Assoc: Bar<N>;
5+
| ------ required by this bound in `Foo::Assoc`
6+
...
7+
LL | type Assoc = u16;
8+
| ^^^^^^^^^^^^^^^^^ the trait `Bar<N>` is not implemented for `u16`
9+
|
10+
= help: the following implementations were found:
11+
<u16 as Bar<3_usize>>
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
2+
--> $DIR/associated-type-bound-fail.rs:14:5
3+
|
4+
LL | type Assoc: Bar<N>;
5+
| ------ required by this bound in `Foo::Assoc`
6+
...
7+
LL | type Assoc = u16;
8+
| ^^^^^^^^^^^^^^^^^ the trait `Bar<N>` is not implemented for `u16`
9+
|
10+
= help: the following implementations were found:
11+
<u16 as Bar<3_usize>>
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// revisions: full min
2+
#![cfg_attr(full, allow(incomplete_features))]
3+
#![cfg_attr(full, feature(const_generics))]
4+
#![cfg_attr(min, feature(min_const_generics))]
5+
6+
trait Bar<const N: usize> {}
7+
8+
trait Foo<const N: usize> {
9+
type Assoc: Bar<N>;
10+
}
11+
12+
impl Bar<3> for u16 {}
13+
impl<const N: usize> Foo<N> for i16 {
14+
type Assoc = u16; //~ ERROR the trait bound `u16: Bar<N>`
15+
}
16+
17+
fn main() {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// run-pass
2+
// revisions: full min
3+
#![cfg_attr(full, allow(incomplete_features))]
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(min, feature(min_const_generics))]
6+
7+
trait Bar<const N: usize> {}
8+
9+
trait Foo<const N: usize> {
10+
type Assoc: Bar<N>;
11+
}
12+
13+
impl<const N: usize> Bar<N> for u8 {}
14+
impl Bar<3> for u16 {}
15+
16+
impl<const N: usize> Foo<N> for i8 {
17+
type Assoc = u8;
18+
}
19+
20+
impl Foo<3> for i16 {
21+
type Assoc = u16;
22+
}
23+
24+
fn main() {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// edition:2018
2+
#![cfg_attr(full, feature(const_generics))]
3+
#![cfg_attr(full, allow(incomplete_features))]
4+
#![cfg_attr(min, feature(min_const_generics))]
5+
6+
pub trait Foo<const N: usize> {}
7+
struct Local;
8+
impl<const N: usize> Foo<N> for Local {}
9+
10+
pub fn out_foo<const N: usize>() -> impl Foo<N> { Local }
11+
pub fn in_foo<const N: usize>(_: impl Foo<N>) {}
12+
13+
pub async fn async_simple<const N: usize>(_: [u8; N]) {}
14+
pub async fn async_out_foo<const N: usize>() -> impl Foo<N> { Local }
15+
pub async fn async_in_foo<const N: usize>(_: impl Foo<N>) {}
16+
17+
pub trait Bar<const N: usize> {
18+
type Assoc: Foo<N>;
19+
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
error: generic parameters may not be used in const operations
2+
--> $DIR/const-arg-in-const-arg.rs:14:23
3+
|
4+
LL | let _: [u8; foo::<T>()];
5+
| ^ cannot perform const operation using `T`
6+
|
7+
= note: type parameters may not be used in const expressions
8+
9+
error: generic parameters may not be used in const operations
10+
--> $DIR/const-arg-in-const-arg.rs:15:23
11+
|
12+
LL | let _: [u8; bar::<N>()];
13+
| ^ cannot perform const operation using `N`
14+
|
15+
= help: const parameters may only be used as standalone arguments, i.e. `N`
16+
17+
error: generic parameters may not be used in const operations
18+
--> $DIR/const-arg-in-const-arg.rs:25:23
19+
|
20+
LL | let _ = [0; bar::<N>()];
21+
| ^ cannot perform const operation using `N`
22+
|
23+
= help: const parameters may only be used as standalone arguments, i.e. `N`
24+
25+
error: generic parameters may not be used in const operations
26+
--> $DIR/const-arg-in-const-arg.rs:30:24
27+
|
28+
LL | let _: Foo<{ foo::<T>() }>;
29+
| ^ cannot perform const operation using `T`
30+
|
31+
= note: type parameters may not be used in const expressions
32+
33+
error: generic parameters may not be used in const operations
34+
--> $DIR/const-arg-in-const-arg.rs:31:24
35+
|
36+
LL | let _: Foo<{ bar::<N>() }>;
37+
| ^ cannot perform const operation using `N`
38+
|
39+
= help: const parameters may only be used as standalone arguments, i.e. `N`
40+
41+
error: generic parameters may not be used in const operations
42+
--> $DIR/const-arg-in-const-arg.rs:36:27
43+
|
44+
LL | let _ = Foo::<{ foo::<T>() }>;
45+
| ^ cannot perform const operation using `T`
46+
|
47+
= note: type parameters may not be used in const expressions
48+
49+
error: generic parameters may not be used in const operations
50+
--> $DIR/const-arg-in-const-arg.rs:37:27
51+
|
52+
LL | let _ = Foo::<{ bar::<N>() }>;
53+
| ^ cannot perform const operation using `N`
54+
|
55+
= help: const parameters may only be used as standalone arguments, i.e. `N`
56+
57+
error[E0658]: a non-static lifetime is not allowed in a `const`
58+
--> $DIR/const-arg-in-const-arg.rs:16:23
59+
|
60+
LL | let _: [u8; faz::<'a>(&())];
61+
| ^^
62+
|
63+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
64+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
65+
66+
error[E0658]: a non-static lifetime is not allowed in a `const`
67+
--> $DIR/const-arg-in-const-arg.rs:17:23
68+
|
69+
LL | let _: [u8; baz::<'a>(&())];
70+
| ^^
71+
|
72+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
73+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
74+
75+
error[E0658]: a non-static lifetime is not allowed in a `const`
76+
--> $DIR/const-arg-in-const-arg.rs:18:23
77+
|
78+
LL | let _: [u8; faz::<'b>(&())];
79+
| ^^
80+
|
81+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
82+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
83+
84+
error[E0658]: a non-static lifetime is not allowed in a `const`
85+
--> $DIR/const-arg-in-const-arg.rs:19:23
86+
|
87+
LL | let _: [u8; baz::<'b>(&())];
88+
| ^^
89+
|
90+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
91+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
92+
93+
error[E0658]: a non-static lifetime is not allowed in a `const`
94+
--> $DIR/const-arg-in-const-arg.rs:26:23
95+
|
96+
LL | let _ = [0; faz::<'a>(&())];
97+
| ^^
98+
|
99+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
100+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
101+
102+
error[E0658]: a non-static lifetime is not allowed in a `const`
103+
--> $DIR/const-arg-in-const-arg.rs:27:23
104+
|
105+
LL | let _ = [0; baz::<'a>(&())];
106+
| ^^
107+
|
108+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
109+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
110+
111+
error[E0658]: a non-static lifetime is not allowed in a `const`
112+
--> $DIR/const-arg-in-const-arg.rs:28:23
113+
|
114+
LL | let _ = [0; faz::<'b>(&())];
115+
| ^^
116+
|
117+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
118+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
119+
120+
error[E0658]: a non-static lifetime is not allowed in a `const`
121+
--> $DIR/const-arg-in-const-arg.rs:29:23
122+
|
123+
LL | let _ = [0; baz::<'b>(&())];
124+
| ^^
125+
|
126+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
127+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
128+
129+
error[E0658]: a non-static lifetime is not allowed in a `const`
130+
--> $DIR/const-arg-in-const-arg.rs:32:24
131+
|
132+
LL | let _: Foo<{ faz::<'a>(&()) }>;
133+
| ^^
134+
|
135+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
136+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
137+
138+
error[E0658]: a non-static lifetime is not allowed in a `const`
139+
--> $DIR/const-arg-in-const-arg.rs:33:24
140+
|
141+
LL | let _: Foo<{ baz::<'a>(&()) }>;
142+
| ^^
143+
|
144+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
145+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
146+
147+
error[E0658]: a non-static lifetime is not allowed in a `const`
148+
--> $DIR/const-arg-in-const-arg.rs:34:24
149+
|
150+
LL | let _: Foo<{ faz::<'b>(&()) }>;
151+
| ^^
152+
|
153+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
154+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
155+
156+
error[E0658]: a non-static lifetime is not allowed in a `const`
157+
--> $DIR/const-arg-in-const-arg.rs:35:24
158+
|
159+
LL | let _: Foo<{ baz::<'b>(&()) }>;
160+
| ^^
161+
|
162+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
163+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
164+
165+
error[E0658]: a non-static lifetime is not allowed in a `const`
166+
--> $DIR/const-arg-in-const-arg.rs:38:27
167+
|
168+
LL | let _ = Foo::<{ faz::<'a>(&()) }>;
169+
| ^^
170+
|
171+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
172+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
173+
174+
error[E0658]: a non-static lifetime is not allowed in a `const`
175+
--> $DIR/const-arg-in-const-arg.rs:39:27
176+
|
177+
LL | let _ = Foo::<{ baz::<'a>(&()) }>;
178+
| ^^
179+
|
180+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
181+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
182+
183+
error[E0658]: a non-static lifetime is not allowed in a `const`
184+
--> $DIR/const-arg-in-const-arg.rs:40:27
185+
|
186+
LL | let _ = Foo::<{ faz::<'b>(&()) }>;
187+
| ^^
188+
|
189+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
190+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
191+
192+
error[E0658]: a non-static lifetime is not allowed in a `const`
193+
--> $DIR/const-arg-in-const-arg.rs:41:27
194+
|
195+
LL | let _ = Foo::<{ baz::<'b>(&()) }>;
196+
| ^^
197+
|
198+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
199+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
200+
201+
error: aborting due to 23 previous errors
202+
203+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// revisions: min
2+
// FIXME(const_generics): This test currently causes an ICE because
3+
// we don't yet correctly deal with lifetimes, reenable this test once
4+
// this is fixed.
5+
#![cfg_attr(min, feature(min_const_generics))]
6+
7+
const fn foo<T>() -> usize { std::mem::size_of::<T>() }
8+
const fn bar<const N: usize>() -> usize { N }
9+
const fn faz<'a>(_: &'a ()) -> usize { 13 }
10+
const fn baz<'a>(_: &'a ()) -> usize where &'a (): Sized { 13 }
11+
12+
struct Foo<const N: usize>;
13+
fn test<'a, 'b, T, const N: usize>() where &'b (): Sized {
14+
let _: [u8; foo::<T>()]; //~ ERROR generic parameters may not
15+
let _: [u8; bar::<N>()]; //~ ERROR generic parameters may not
16+
let _: [u8; faz::<'a>(&())]; //~ ERROR a non-static lifetime
17+
let _: [u8; baz::<'a>(&())]; //~ ERROR a non-static lifetime
18+
let _: [u8; faz::<'b>(&())]; //~ ERROR a non-static lifetime
19+
let _: [u8; baz::<'b>(&())]; //~ ERROR a non-static lifetime
20+
21+
// NOTE: This can be a future compat warning instead of an error,
22+
// so we stop compilation before emitting this error in this test.
23+
let _ = [0; foo::<T>()];
24+
25+
let _ = [0; bar::<N>()]; //~ ERROR generic parameters may not
26+
let _ = [0; faz::<'a>(&())]; //~ ERROR a non-static lifetime
27+
let _ = [0; baz::<'a>(&())]; //~ ERROR a non-static lifetime
28+
let _ = [0; faz::<'b>(&())]; //~ ERROR a non-static lifetime
29+
let _ = [0; baz::<'b>(&())]; //~ ERROR a non-static lifetime
30+
let _: Foo<{ foo::<T>() }>; //~ ERROR generic parameters may not
31+
let _: Foo<{ bar::<N>() }>; //~ ERROR generic parameters may not
32+
let _: Foo<{ faz::<'a>(&()) }>; //~ ERROR a non-static lifetime
33+
let _: Foo<{ baz::<'a>(&()) }>; //~ ERROR a non-static lifetime
34+
let _: Foo<{ faz::<'b>(&()) }>; //~ ERROR a non-static lifetime
35+
let _: Foo<{ baz::<'b>(&()) }>; //~ ERROR a non-static lifetime
36+
let _ = Foo::<{ foo::<T>() }>; //~ ERROR generic parameters may not
37+
let _ = Foo::<{ bar::<N>() }>; //~ ERROR generic parameters may not
38+
let _ = Foo::<{ faz::<'a>(&()) }>; //~ ERROR a non-static lifetime
39+
let _ = Foo::<{ baz::<'a>(&()) }>; //~ ERROR a non-static lifetime
40+
let _ = Foo::<{ faz::<'b>(&()) }>; //~ ERROR a non-static lifetime
41+
let _ = Foo::<{ baz::<'b>(&()) }>; //~ ERROR a non-static lifetime
42+
}
43+
44+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// run-pass
2+
// revisions: full min
3+
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
7+
8+
macro_rules! bar {
9+
($($t:tt)*) => { impl<const N: usize> $($t)* };
10+
}
11+
12+
macro_rules! baz {
13+
($t:tt) => { fn test<const M: usize>(&self) -> usize { $t } };
14+
}
15+
16+
struct Foo<const N: usize>;
17+
18+
bar!(Foo<N> { baz!{ M } });
19+
20+
fn main() {
21+
assert_eq!(Foo::<7>.test::<3>(), 3);
22+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// edition:2018
2+
// check-pass
3+
// revisions: full min
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
7+
8+
async fn foo<const N: usize>(arg: [u8; N]) -> usize { arg.len() }
9+
10+
async fn bar<const N: usize>() -> [u8; N] {
11+
[0; N]
12+
}
13+
14+
trait Trait<const N: usize> {
15+
fn fynn(&self) -> usize;
16+
}
17+
impl<const N: usize> Trait<N> for [u8; N] {
18+
fn fynn(&self) -> usize {
19+
N
20+
}
21+
}
22+
async fn baz<const N: usize>() -> impl Trait<N> {
23+
[0; N]
24+
}
25+
26+
async fn biz<const N: usize>(v: impl Trait<N>) -> usize {
27+
v.fynn()
28+
}
29+
30+
async fn user<const N: usize>() {
31+
let _ = foo::<N>(bar().await).await;
32+
let _ = biz(baz::<N>().await).await;
33+
}
34+
35+
fn main() { }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// aux-build:crayte.rs
2+
// edition:2018
3+
// run-pass
4+
// revisions: full min
5+
6+
#![cfg_attr(full, feature(const_generics))]
7+
#![cfg_attr(full, allow(incomplete_features))]
8+
#![cfg_attr(min, feature(min_const_generics))]
9+
extern crate crayte;
10+
11+
use crayte::*;
12+
13+
async fn foo() {
14+
in_foo(out_foo::<3>());
15+
async_simple([0; 17]).await;
16+
async_in_foo(async_out_foo::<4>().await).await;
17+
}
18+
19+
struct Faz<const N: usize>;
20+
21+
impl<const N: usize> Foo<N> for Faz<N> {}
22+
impl<const N: usize> Bar<N> for Faz<N> {
23+
type Assoc = Faz<N>;
24+
}
25+
26+
fn main() {
27+
let _ = foo;
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0277]: the trait bound `(): Foo<N>` is not satisfied
2+
--> $DIR/exhaustive-value.rs:267:5
3+
|
4+
LL | fn test() {}
5+
| --------- required by `Foo::test`
6+
...
7+
LL | <() as Foo<N>>::test()
8+
| ^^^^^^^^^^^^^^^^^^^^ the trait `Foo<N>` is not implemented for `()`
9+
|
10+
= help: the following implementations were found:
11+
<() as Foo<0_u8>>
12+
<() as Foo<100_u8>>
13+
<() as Foo<101_u8>>
14+
<() as Foo<102_u8>>
15+
and 252 others
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0277]: the trait bound `(): Foo<N>` is not satisfied
2+
--> $DIR/exhaustive-value.rs:267:5
3+
|
4+
LL | fn test() {}
5+
| --------- required by `Foo::test`
6+
...
7+
LL | <() as Foo<N>>::test()
8+
| ^^^^^^^^^^^^^^^^^^^^ the trait `Foo<N>` is not implemented for `()`
9+
|
10+
= help: the following implementations were found:
11+
<() as Foo<0_u8>>
12+
<() as Foo<100_u8>>
13+
<() as Foo<101_u8>>
14+
<() as Foo<102_u8>>
15+
and 252 others
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
// revisions: full min
2+
#![cfg_attr(full, feature(const_generics))]
3+
#![cfg_attr(full, allow(incomplete_features))]
4+
#![cfg_attr(min, feature(min_const_generics))]
5+
6+
trait Foo<const N: u8> {
7+
fn test() {}
8+
}
9+
impl Foo<0> for () {}
10+
impl Foo<1> for () {}
11+
impl Foo<2> for () {}
12+
impl Foo<3> for () {}
13+
impl Foo<4> for () {}
14+
impl Foo<5> for () {}
15+
impl Foo<6> for () {}
16+
impl Foo<7> for () {}
17+
impl Foo<8> for () {}
18+
impl Foo<9> for () {}
19+
impl Foo<10> for () {}
20+
impl Foo<11> for () {}
21+
impl Foo<12> for () {}
22+
impl Foo<13> for () {}
23+
impl Foo<14> for () {}
24+
impl Foo<15> for () {}
25+
impl Foo<16> for () {}
26+
impl Foo<17> for () {}
27+
impl Foo<18> for () {}
28+
impl Foo<19> for () {}
29+
impl Foo<20> for () {}
30+
impl Foo<21> for () {}
31+
impl Foo<22> for () {}
32+
impl Foo<23> for () {}
33+
impl Foo<24> for () {}
34+
impl Foo<25> for () {}
35+
impl Foo<26> for () {}
36+
impl Foo<27> for () {}
37+
impl Foo<28> for () {}
38+
impl Foo<29> for () {}
39+
impl Foo<30> for () {}
40+
impl Foo<31> for () {}
41+
impl Foo<32> for () {}
42+
impl Foo<33> for () {}
43+
impl Foo<34> for () {}
44+
impl Foo<35> for () {}
45+
impl Foo<36> for () {}
46+
impl Foo<37> for () {}
47+
impl Foo<38> for () {}
48+
impl Foo<39> for () {}
49+
impl Foo<40> for () {}
50+
impl Foo<41> for () {}
51+
impl Foo<42> for () {}
52+
impl Foo<43> for () {}
53+
impl Foo<44> for () {}
54+
impl Foo<45> for () {}
55+
impl Foo<46> for () {}
56+
impl Foo<47> for () {}
57+
impl Foo<48> for () {}
58+
impl Foo<49> for () {}
59+
impl Foo<50> for () {}
60+
impl Foo<51> for () {}
61+
impl Foo<52> for () {}
62+
impl Foo<53> for () {}
63+
impl Foo<54> for () {}
64+
impl Foo<55> for () {}
65+
impl Foo<56> for () {}
66+
impl Foo<57> for () {}
67+
impl Foo<58> for () {}
68+
impl Foo<59> for () {}
69+
impl Foo<60> for () {}
70+
impl Foo<61> for () {}
71+
impl Foo<62> for () {}
72+
impl Foo<63> for () {}
73+
impl Foo<64> for () {}
74+
impl Foo<65> for () {}
75+
impl Foo<66> for () {}
76+
impl Foo<67> for () {}
77+
impl Foo<68> for () {}
78+
impl Foo<69> for () {}
79+
impl Foo<70> for () {}
80+
impl Foo<71> for () {}
81+
impl Foo<72> for () {}
82+
impl Foo<73> for () {}
83+
impl Foo<74> for () {}
84+
impl Foo<75> for () {}
85+
impl Foo<76> for () {}
86+
impl Foo<77> for () {}
87+
impl Foo<78> for () {}
88+
impl Foo<79> for () {}
89+
impl Foo<80> for () {}
90+
impl Foo<81> for () {}
91+
impl Foo<82> for () {}
92+
impl Foo<83> for () {}
93+
impl Foo<84> for () {}
94+
impl Foo<85> for () {}
95+
impl Foo<86> for () {}
96+
impl Foo<87> for () {}
97+
impl Foo<88> for () {}
98+
impl Foo<89> for () {}
99+
impl Foo<90> for () {}
100+
impl Foo<91> for () {}
101+
impl Foo<92> for () {}
102+
impl Foo<93> for () {}
103+
impl Foo<94> for () {}
104+
impl Foo<95> for () {}
105+
impl Foo<96> for () {}
106+
impl Foo<97> for () {}
107+
impl Foo<98> for () {}
108+
impl Foo<99> for () {}
109+
impl Foo<100> for () {}
110+
impl Foo<101> for () {}
111+
impl Foo<102> for () {}
112+
impl Foo<103> for () {}
113+
impl Foo<104> for () {}
114+
impl Foo<105> for () {}
115+
impl Foo<106> for () {}
116+
impl Foo<107> for () {}
117+
impl Foo<108> for () {}
118+
impl Foo<109> for () {}
119+
impl Foo<110> for () {}
120+
impl Foo<111> for () {}
121+
impl Foo<112> for () {}
122+
impl Foo<113> for () {}
123+
impl Foo<114> for () {}
124+
impl Foo<115> for () {}
125+
impl Foo<116> for () {}
126+
impl Foo<117> for () {}
127+
impl Foo<118> for () {}
128+
impl Foo<119> for () {}
129+
impl Foo<120> for () {}
130+
impl Foo<121> for () {}
131+
impl Foo<122> for () {}
132+
impl Foo<123> for () {}
133+
impl Foo<124> for () {}
134+
impl Foo<125> for () {}
135+
impl Foo<126> for () {}
136+
impl Foo<127> for () {}
137+
impl Foo<128> for () {}
138+
impl Foo<129> for () {}
139+
impl Foo<130> for () {}
140+
impl Foo<131> for () {}
141+
impl Foo<132> for () {}
142+
impl Foo<133> for () {}
143+
impl Foo<134> for () {}
144+
impl Foo<135> for () {}
145+
impl Foo<136> for () {}
146+
impl Foo<137> for () {}
147+
impl Foo<138> for () {}
148+
impl Foo<139> for () {}
149+
impl Foo<140> for () {}
150+
impl Foo<141> for () {}
151+
impl Foo<142> for () {}
152+
impl Foo<143> for () {}
153+
impl Foo<144> for () {}
154+
impl Foo<145> for () {}
155+
impl Foo<146> for () {}
156+
impl Foo<147> for () {}
157+
impl Foo<148> for () {}
158+
impl Foo<149> for () {}
159+
impl Foo<150> for () {}
160+
impl Foo<151> for () {}
161+
impl Foo<152> for () {}
162+
impl Foo<153> for () {}
163+
impl Foo<154> for () {}
164+
impl Foo<155> for () {}
165+
impl Foo<156> for () {}
166+
impl Foo<157> for () {}
167+
impl Foo<158> for () {}
168+
impl Foo<159> for () {}
169+
impl Foo<160> for () {}
170+
impl Foo<161> for () {}
171+
impl Foo<162> for () {}
172+
impl Foo<163> for () {}
173+
impl Foo<164> for () {}
174+
impl Foo<165> for () {}
175+
impl Foo<166> for () {}
176+
impl Foo<167> for () {}
177+
impl Foo<168> for () {}
178+
impl Foo<169> for () {}
179+
impl Foo<170> for () {}
180+
impl Foo<171> for () {}
181+
impl Foo<172> for () {}
182+
impl Foo<173> for () {}
183+
impl Foo<174> for () {}
184+
impl Foo<175> for () {}
185+
impl Foo<176> for () {}
186+
impl Foo<177> for () {}
187+
impl Foo<178> for () {}
188+
impl Foo<179> for () {}
189+
impl Foo<180> for () {}
190+
impl Foo<181> for () {}
191+
impl Foo<182> for () {}
192+
impl Foo<183> for () {}
193+
impl Foo<184> for () {}
194+
impl Foo<185> for () {}
195+
impl Foo<186> for () {}
196+
impl Foo<187> for () {}
197+
impl Foo<188> for () {}
198+
impl Foo<189> for () {}
199+
impl Foo<190> for () {}
200+
impl Foo<191> for () {}
201+
impl Foo<192> for () {}
202+
impl Foo<193> for () {}
203+
impl Foo<194> for () {}
204+
impl Foo<195> for () {}
205+
impl Foo<196> for () {}
206+
impl Foo<197> for () {}
207+
impl Foo<198> for () {}
208+
impl Foo<199> for () {}
209+
impl Foo<200> for () {}
210+
impl Foo<201> for () {}
211+
impl Foo<202> for () {}
212+
impl Foo<203> for () {}
213+
impl Foo<204> for () {}
214+
impl Foo<205> for () {}
215+
impl Foo<206> for () {}
216+
impl Foo<207> for () {}
217+
impl Foo<208> for () {}
218+
impl Foo<209> for () {}
219+
impl Foo<210> for () {}
220+
impl Foo<211> for () {}
221+
impl Foo<212> for () {}
222+
impl Foo<213> for () {}
223+
impl Foo<214> for () {}
224+
impl Foo<215> for () {}
225+
impl Foo<216> for () {}
226+
impl Foo<217> for () {}
227+
impl Foo<218> for () {}
228+
impl Foo<219> for () {}
229+
impl Foo<220> for () {}
230+
impl Foo<221> for () {}
231+
impl Foo<222> for () {}
232+
impl Foo<223> for () {}
233+
impl Foo<224> for () {}
234+
impl Foo<225> for () {}
235+
impl Foo<226> for () {}
236+
impl Foo<227> for () {}
237+
impl Foo<228> for () {}
238+
impl Foo<229> for () {}
239+
impl Foo<230> for () {}
240+
impl Foo<231> for () {}
241+
impl Foo<232> for () {}
242+
impl Foo<233> for () {}
243+
impl Foo<234> for () {}
244+
impl Foo<235> for () {}
245+
impl Foo<236> for () {}
246+
impl Foo<237> for () {}
247+
impl Foo<238> for () {}
248+
impl Foo<239> for () {}
249+
impl Foo<240> for () {}
250+
impl Foo<241> for () {}
251+
impl Foo<242> for () {}
252+
impl Foo<243> for () {}
253+
impl Foo<244> for () {}
254+
impl Foo<245> for () {}
255+
impl Foo<246> for () {}
256+
impl Foo<247> for () {}
257+
impl Foo<248> for () {}
258+
impl Foo<249> for () {}
259+
impl Foo<250> for () {}
260+
impl Foo<251> for () {}
261+
impl Foo<252> for () {}
262+
impl Foo<253> for () {}
263+
impl Foo<254> for () {}
264+
impl Foo<255> for () {}
265+
266+
fn foo<const N: u8>() {
267+
<() as Foo<N>>::test() //~ ERROR the trait bound `(): Foo<N>`
268+
}
269+
270+
fn main() {
271+
foo::<7>();
272+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/generic-param-mismatch.rs:7:5
3+
|
4+
LL | fn test<const N: usize, const M: usize>() -> [u8; M] {
5+
| ------- expected `[u8; M]` because of return type
6+
LL | [0; N]
7+
| ^^^^^^ expected `M`, found `N`
8+
|
9+
= note: expected array `[u8; M]`
10+
found array `[u8; N]`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/generic-param-mismatch.rs:7:5
3+
|
4+
LL | fn test<const N: usize, const M: usize>() -> [u8; M] {
5+
| ------- expected `[u8; M]` because of return type
6+
LL | [0; N]
7+
| ^^^^^^ expected `M`, found `N`
8+
|
9+
= note: expected array `[u8; M]`
10+
found array `[u8; N]`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// revisions: full min
2+
#![cfg_attr(full, allow(incomplete_features))]
3+
#![cfg_attr(full, feature(const_generics))]
4+
#![cfg_attr(min, feature(min_const_generics))]
5+
6+
fn test<const N: usize, const M: usize>() -> [u8; M] {
7+
[0; N] //~ ERROR mismatched types
8+
}
9+
10+
fn main() {}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
error: expressions must be enclosed in braces to be used as const generic arguments
2+
--> $DIR/macro_rules-braces.rs:34:17
3+
|
4+
LL | let _: baz!(N);
5+
| ^
6+
|
7+
help: enclose the `const` expression in braces
8+
|
9+
LL | let _: baz!({ N });
10+
| ^ ^
11+
12+
error: constant expression depends on a generic parameter
13+
--> $DIR/macro_rules-braces.rs:10:13
14+
|
15+
LL | [u8; $x]
16+
| ^^^^^^^^
17+
...
18+
LL | let _: foo!({{ N }});
19+
| ------------- in this macro invocation
20+
|
21+
= note: this may fail depending on what value the parameter takes
22+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
23+
24+
error: constant expression depends on a generic parameter
25+
--> $DIR/macro_rules-braces.rs:15:13
26+
|
27+
LL | [u8; { $x }]
28+
| ^^^^^^^^^^^^
29+
...
30+
LL | let _: bar!({ N });
31+
| ----------- in this macro invocation
32+
|
33+
= note: this may fail depending on what value the parameter takes
34+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
35+
36+
error: constant expression depends on a generic parameter
37+
--> $DIR/macro_rules-braces.rs:20:13
38+
|
39+
LL | Foo<$x>
40+
| ^^^^^^^
41+
...
42+
LL | let _: baz!({{ N }});
43+
| ------------- in this macro invocation
44+
|
45+
= note: this may fail depending on what value the parameter takes
46+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
47+
48+
error: constant expression depends on a generic parameter
49+
--> $DIR/macro_rules-braces.rs:25:13
50+
|
51+
LL | Foo<{ $x }>
52+
| ^^^^^^^^^^^
53+
...
54+
LL | let _: biz!({ N });
55+
| ----------- in this macro invocation
56+
|
57+
= note: this may fail depending on what value the parameter takes
58+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
59+
60+
error: aborting due to 5 previous errors
61+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error: expressions must be enclosed in braces to be used as const generic arguments
2+
--> $DIR/macro_rules-braces.rs:34:17
3+
|
4+
LL | let _: baz!(N);
5+
| ^
6+
|
7+
help: enclose the `const` expression in braces
8+
|
9+
LL | let _: baz!({ N });
10+
| ^ ^
11+
12+
error: generic parameters may not be used in const operations
13+
--> $DIR/macro_rules-braces.rs:31:20
14+
|
15+
LL | let _: foo!({{ N }});
16+
| ^ cannot perform const operation using `N`
17+
|
18+
= help: const parameters may only be used as standalone arguments, i.e. `N`
19+
20+
error: generic parameters may not be used in const operations
21+
--> $DIR/macro_rules-braces.rs:33:19
22+
|
23+
LL | let _: bar!({ N });
24+
| ^ cannot perform const operation using `N`
25+
|
26+
= help: const parameters may only be used as standalone arguments, i.e. `N`
27+
28+
error: generic parameters may not be used in const operations
29+
--> $DIR/macro_rules-braces.rs:36:20
30+
|
31+
LL | let _: baz!({{ N }});
32+
| ^ cannot perform const operation using `N`
33+
|
34+
= help: const parameters may only be used as standalone arguments, i.e. `N`
35+
36+
error: generic parameters may not be used in const operations
37+
--> $DIR/macro_rules-braces.rs:38:19
38+
|
39+
LL | let _: biz!({ N });
40+
| ^ cannot perform const operation using `N`
41+
|
42+
= help: const parameters may only be used as standalone arguments, i.e. `N`
43+
44+
error: aborting due to 5 previous errors
45+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// revisions: full min
2+
#![cfg_attr(full, allow(incomplete_features))]
3+
#![cfg_attr(full, feature(const_generics))]
4+
#![cfg_attr(min, feature(min_const_generics))]
5+
6+
fn test<const N: usize>() {
7+
struct Foo<const M: usize>;
8+
macro_rules! foo {
9+
($x:expr) => {
10+
[u8; $x] //[full]~ ERROR constant expression depends
11+
}
12+
}
13+
macro_rules! bar {
14+
($x:expr) => {
15+
[u8; { $x }] //[full]~ ERROR constant expression depends
16+
}
17+
}
18+
macro_rules! baz {
19+
( $x:expr) => {
20+
Foo<$x> //[full]~ ERROR constant expression depends
21+
}
22+
}
23+
macro_rules! biz {
24+
($x:expr) => {
25+
Foo<{ $x }> //[full]~ ERROR constant expression depends
26+
};
27+
}
28+
29+
let _: foo!(N);
30+
let _: foo!({ N });
31+
let _: foo!({{ N }}); //[min]~ ERROR generic parameters may not
32+
let _: bar!(N);
33+
let _: bar!({ N }); //[min]~ ERROR generic parameters may not
34+
let _: baz!(N); //~ ERROR expressions must be enclosed in braces
35+
let _: baz!({ N });
36+
let _: baz!({{ N }}); //[min]~ ERROR generic parameters may not
37+
let _: biz!(N);
38+
let _: biz!({ N }); //[min]~ ERROR generic parameters may not
39+
}
40+
41+
fn main() {
42+
test::<3>();
43+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// check-pass
2+
// revisions: full min
3+
#![cfg_attr(full, feature(const_generics))]
4+
#![cfg_attr(full, allow(incomplete_features))]
5+
#![cfg_attr(min, feature(min_const_generics))]
6+
7+
trait Bar<const N: usize> { fn bar() {} }
8+
trait Foo<const N: usize>: Bar<N> {}
9+
10+
fn test<T, const N: usize>() where T: Foo<N> {
11+
<T as Bar<N>>::bar();
12+
}
13+
14+
struct Faz<const N: usize>;
15+
16+
impl<const N: usize> Faz<N> {
17+
fn test<T>() where T: Foo<N> {
18+
<T as Bar<N>>::bar()
19+
}
20+
}
21+
22+
trait Fiz<const N: usize> {
23+
fn fiz<T>() where T: Foo<N> {
24+
<T as Bar<N>>::bar();
25+
}
26+
}
27+
28+
impl<const N: usize> Bar<N> for u8 {}
29+
impl<const N: usize> Foo<N> for u8 {}
30+
impl<const N: usize> Fiz<N> for u8 {}
31+
fn main() {
32+
test::<u8, 13>();
33+
Faz::<3>::test::<u8>();
34+
<u8 as Fiz<13>>::fiz::<u8>();
35+
}

0 commit comments

Comments
 (0)
Please sign in to comment.