]> git.lizzy.rs Git - rust.git/blob - src/test/ui/const-generics/type-dependent/auxiliary/type_dependent_lib.rs
Rollup merge of #74325 - GuillaumeGomez:focus-source-file-sidebar, r=kinnison
[rust.git] / src / test / ui / const-generics / type-dependent / auxiliary / type_dependent_lib.rs
1 #![feature(const_generics)]
2 #![allow(incomplete_features)]
3
4 pub struct Struct<const N: usize>(());
5
6 impl<const N: usize> Struct<N> {
7     pub fn new() -> Self {
8         Struct(())
9     }
10
11     pub fn same_ty<const M: usize>(&self) -> (usize, usize) {
12         (N, M)
13     }
14
15     pub fn different_ty<const M: u8>(&self) -> (usize, u8) {
16         (N, M)
17     }
18
19     pub fn containing_ty<T, const M: u8>(&self) -> (usize, u8) {
20         (std::mem::size_of::<T>() +  N, M)
21     }
22
23     pub fn we_have_to_go_deeper<const M: usize>(&self) -> Struct<M> {
24         Struct(())
25     }
26 }
27
28 pub trait Foo {
29     fn foo<const M: usize>(&self) -> usize;
30 }
31
32 impl Foo for Struct<7> {
33     fn foo<const M: usize>(&self) -> usize {
34         M
35     }
36 }