]> git.lizzy.rs Git - rust.git/blob - tests/ui/const-generics/const-arg-in-const-arg.rs
Rollup merge of #106859 - tialaramex:master, r=Nilstrieb
[rust.git] / tests / ui / const-generics / const-arg-in-const-arg.rs
1 // revisions: full min
2
3 #![cfg_attr(full, feature(generic_const_exprs))]
4 #![cfg_attr(full, allow(incomplete_features))]
5
6 const fn foo<T>() -> usize { std::mem::size_of::<T>() }
7 const fn bar<const N: usize>() -> usize { N }
8 const fn faz<'a>(_: &'a ()) -> usize { 13 }
9 const fn baz<'a>(_: &'a ()) -> usize where &'a (): Sized { 13 }
10
11 struct Foo<const N: usize>;
12 fn test<'a, 'b, T, const N: usize>() where &'b (): Sized {
13     let _: [u8; foo::<T>()]; //[min]~ ERROR generic parameters may not
14                              //[full]~^ ERROR unconstrained generic constant
15     let _: [u8; bar::<N>()]; //[min]~ ERROR generic parameters may not
16                              //[min]~^ ERROR unresolved item provided when a constant was expected
17                              //[full]~^^ ERROR unconstrained generic constant
18     let _: [u8; faz::<'a>(&())]; //[min]~ ERROR a non-static lifetime
19                                  //~^ ERROR cannot specify lifetime arguments
20     let _: [u8; baz::<'a>(&())]; //[min]~ ERROR a non-static lifetime
21     let _: [u8; faz::<'b>(&())]; //[min]~ ERROR a non-static lifetime
22                                  //~^ ERROR cannot specify lifetime arguments
23     let _: [u8; baz::<'b>(&())]; //[min]~ ERROR a non-static lifetime
24
25     let _ = [0; foo::<T>()]; //[min]~ ERROR constant expression depends on a generic parameter
26                              //[full]~^ ERROR unconstrained generic constant
27     let _ = [0; bar::<N>()]; //[min]~ ERROR generic parameters may not
28                              //[min]~^ ERROR unresolved item provided when a constant was expected
29                              //[full]~^^ ERROR unconstrained generic constant
30     let _ = [0; faz::<'a>(&())]; //[min]~ ERROR a non-static lifetime
31                                  //~^ ERROR cannot specify lifetime arguments
32     let _ = [0; baz::<'a>(&())]; //[min]~ ERROR a non-static lifetime
33     let _ = [0; faz::<'b>(&())]; //[min]~ ERROR a non-static lifetime
34                                  //~^ ERROR cannot specify lifetime arguments
35     let _ = [0; baz::<'b>(&())]; //[min]~ ERROR a non-static lifetime
36     let _: Foo<{ foo::<T>() }>; //[min]~ ERROR generic parameters may not
37                                 //[full]~^ ERROR unconstrained generic constant
38     let _: Foo<{ bar::<N>() }>; //[min]~ ERROR generic parameters may not
39                                 //[min]~^ ERROR unresolved item provided when a constant was expected
40                                 //[full]~^^ ERROR unconstrained generic constant
41     let _: Foo<{ faz::<'a>(&()) }>; //[min]~ ERROR a non-static lifetime
42                                     //~^ ERROR cannot specify lifetime arguments
43     let _: Foo<{ baz::<'a>(&()) }>; //[min]~ ERROR a non-static lifetime
44     let _: Foo<{ faz::<'b>(&()) }>; //[min]~ ERROR a non-static lifetime
45                                     //~^ ERROR cannot specify lifetime arguments
46     let _: Foo<{ baz::<'b>(&()) }>; //[min]~ ERROR a non-static lifetime
47     let _ = Foo::<{ foo::<T>() }>; //[min]~ ERROR generic parameters may not
48                                    //[full]~^ ERROR unconstrained generic constant
49     let _ = Foo::<{ bar::<N>() }>; //[min]~ ERROR generic parameters may not
50                                    //[min]~^ ERROR unresolved item provided when a constant was expected
51                                    //[full]~^^ ERROR unconstrained generic constant
52     let _ = Foo::<{ faz::<'a>(&()) }>; //[min]~ ERROR a non-static lifetime
53                                        //~^ ERROR cannot specify lifetime arguments
54     let _ = Foo::<{ baz::<'a>(&()) }>; //[min]~ ERROR a non-static lifetime
55     let _ = Foo::<{ faz::<'b>(&()) }>; //[min]~ ERROR a non-static lifetime
56                                        //~^ ERROR cannot specify lifetime arguments
57     let _ = Foo::<{ baz::<'b>(&()) }>; //[min]~ ERROR a non-static lifetime
58 }
59
60 fn main() {}