]> git.lizzy.rs Git - rust.git/blob - src/test/ui/const-generics/type-dependent/issue-71348.rs
Auto merge of #74060 - kpp:remove_length_at_most_32, r=dtolnay
[rust.git] / src / test / ui / const-generics / type-dependent / issue-71348.rs
1 // run-pass
2 #![feature(const_generics)]
3 #![allow(incomplete_features)]
4
5 struct Foo {
6     i: i32,
7 }
8
9 trait Get<'a, const N: &'static str> {
10     type Target: 'a;
11
12     fn get(&'a self) -> &'a Self::Target;
13 }
14
15 impl Foo {
16     fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
17     where
18         Self: Get<'a, N>,
19     {
20         self.get()
21     }
22 }
23
24 impl<'a> Get<'a, "int"> for Foo {
25     type Target = i32;
26
27     fn get(&'a self) -> &'a Self::Target {
28         &self.i
29     }
30 }
31
32 fn main() {
33     let foo = Foo { i: 123 };
34     assert_eq!(foo.ask::<"int">(), &123);
35 }