Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis nikomatsakis/issue-64960.rs Secret
Created Oct 9, 2019

Embed
What would you like to do?
use std::fmt::Formatter;
use std::marker::PhantomData;
async fn foo(_: String) {
}
#[derive(Copy, Clone)]
pub struct Arguments<'a> {
// Format string pieces to print.
pieces: &'a [&'a str],
// Dynamic arguments for interpolation, to be interleaved with string
// pieces. (Every argument is preceded by a string piece.)
args: &'a [ArgumentV1<'a>],
}
pub struct ArgumentV1<'a> {
value: &'a Void,
formatter: fn(&Void, &mut Formatter<'_>) -> std::fmt::Result,
}
struct Void {
_priv: (),
//_oibit_remover: PhantomData<*mut dyn Fn()>,
}
impl<'a> Arguments<'a> {
/// When using the format_args!() macro, this function is used to generate the
/// Arguments structure.
#[doc(hidden)] #[inline]
pub fn new_v1(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
Arguments {
pieces,
args,
}
}
}
impl<'a> ArgumentV1<'a> {
pub fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter<'_>) -> std::fmt::Result) -> ArgumentV1<'b> {
unsafe {
ArgumentV1 {
formatter: std::mem::transmute(f),
value: std::mem::transmute(x)
}
}
}
}
fn format(a: Arguments) -> String {
"".to_string()
}
fn bar() -> impl Send {
async move
{
foo(
format(Arguments::new_v1(
&["", ":"],
&match (&1_i32, &2_i32) {
(arg0, arg1) =>
[ArgumentV1::new(arg0, ::core::fmt::Display::fmt),
ArgumentV1::new(arg1, ::core::fmt::Display::fmt)],
}))).await;
}
}
fn main() { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.