From: Ian Jackson Date: Mon, 16 May 2022 15:24:53 +0000 (+0100) Subject: W X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=21ff3e9ba4ba532ae7490772a2d07e19f77d0e09;p=rust-experiments.git W --- diff --git a/src/main.rs b/src/main.rs index 3e80125..de3f0a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,10 +2,18 @@ #![allow(unused_variables)] #![allow(unused_imports)] +use std::mem; use std::mem::MaybeUninit; type S = &'static str; + +#[repr(C)] +struct Concat( + [S; A], + [S; B], +); + trait Ish { const N: usize; } trait Has { @@ -21,18 +29,21 @@ impl Has<1> for Inner { const F: [S; 1] = ["i"]; } -struct Outer { o: usize, } +struct Outer { o: usize, p: usize } impl Ish for Outer { - const N: usize = Inner::N + 1; + const N: usize = Inner::N + 2; } -impl Has<{ Inner::N + 1 }> for Outer { - const F: [S; 2] = { - const TUPLE: ([S;1], [S; Inner::N]) = ( - ["i"; 1], - >::F, - ); - panic!() +impl Has<{ Inner::N + 2 }> for Outer { + const F: [S; Inner::N + 2] = { + const TUPLE: Concat< + 2, + { Inner::N }, + > = Concat( + ["o", "p"], + Inner::F, + ); + unsafe { mem::transmute(TUPLE) } }; } @@ -66,6 +77,6 @@ impl Ish for Outer { */ fn main(){ -// eprintln!("IF {:?}", Inner::F); -// eprintln!("OF {:?}", Outer::F); + eprintln!("IF {:?}", Inner::F); + eprintln!("OF {:?}", Outer::F); }