]> git.lizzy.rs Git - rust.git/blob - tests/ui/const-generics/type-dependent/issue-71348.rs
Auto merge of #106646 - Amanieu:ilp32-object, r=Mark-Simulacrum
[rust.git] / tests / ui / const-generics / type-dependent / issue-71348.rs
1 // [full] run-pass
2 // revisions: full min
3 #![cfg_attr(full, feature(adt_const_params))]
4 #![cfg_attr(full, allow(incomplete_features))]
5
6 struct Foo {
7     i: i32,
8 }
9
10 trait Get<'a, const N: &'static str> {
11     //[min]~^ ERROR `&'static str` is forbidden as the type of a const generic parameter
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
19     //[min]~^ ERROR `&'static str` is forbidden as the type of a const generic parameter
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 }