]> git.lizzy.rs Git - rust.git/blob - src/test/ui/const-generics/const-param-elided-lifetime.rs
Auto merge of #79342 - CDirkx:ipaddr-const, r=oli-obk
[rust.git] / src / test / ui / const-generics / const-param-elided-lifetime.rs
1 // Elided lifetimes within the type of a const generic parameters is disallowed. This matches the
2 // behaviour of trait bounds where `fn foo<T: Ord<&u8>>() {}` is illegal. Though we could change
3 // elided lifetimes within the type of a const generic parameters to be 'static, like elided
4 // lifetimes within const/static items.
5 // revisions: full min
6
7 #![cfg_attr(full, feature(const_generics))]
8 #![cfg_attr(full, allow(incomplete_features))]
9 #![cfg_attr(min, feature(min_const_generics))]
10
11 struct A<const N: &u8>;
12 //~^ ERROR `&` without an explicit lifetime name cannot be used here
13 //[min]~^^ ERROR `&'static u8` is forbidden
14 trait B {}
15
16 impl<const N: &u8> A<N> {
17 //~^ ERROR `&` without an explicit lifetime name cannot be used here
18 //[min]~^^ ERROR `&'static u8` is forbidden
19     fn foo<const M: &u8>(&self) {}
20     //~^ ERROR `&` without an explicit lifetime name cannot be used here
21     //[min]~^^ ERROR `&'static u8` is forbidden
22 }
23
24 impl<const N: &u8> B for A<N> {}
25 //~^ ERROR `&` without an explicit lifetime name cannot be used here
26 //[min]~^^ ERROR `&'static u8` is forbidden
27
28 fn bar<const N: &u8>() {}
29 //~^ ERROR `&` without an explicit lifetime name cannot be used here
30 //[min]~^^ ERROR `&'static u8` is forbidden
31
32 fn main() {}