]>
Commit | Line | Data |
---|---|---|
1b1a35ee XL |
1 | // [full] run-pass |
2 | // revisions: full min | |
3 | #![cfg_attr(full, feature(const_generics))] | |
4 | #![cfg_attr(full, allow(incomplete_features))] | |
3dfed10e XL |
5 | |
6 | struct Foo { | |
7 | i: i32, | |
8 | } | |
9 | ||
10 | trait Get<'a, const N: &'static str> { | |
1b1a35ee | 11 | //[min]~^ ERROR `&'static str` is forbidden as the type of a const generic parameter |
3dfed10e XL |
12 | type Target: 'a; |
13 | ||
14 | fn get(&'a self) -> &'a Self::Target; | |
15 | } | |
16 | ||
17 | impl Foo { | |
18 | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target | |
1b1a35ee | 19 | //[min]~^ ERROR `&'static str` is forbidden as the type of a const generic parameter |
3dfed10e XL |
20 | where |
21 | Self: Get<'a, N>, | |
22 | { | |
23 | self.get() | |
24 | } | |
25 | } | |
26 | ||
27 | impl<'a> Get<'a, "int"> for Foo { | |
28 | type Target = i32; | |
29 | ||
30 | fn get(&'a self) -> &'a Self::Target { | |
31 | &self.i | |
32 | } | |
33 | } | |
34 | ||
35 | fn main() { | |
36 | let foo = Foo { i: 123 }; | |
37 | assert_eq!(foo.ask::<"int">(), &123); | |
38 | } |