1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#![cfg_attr(rustfmt, rustfmt::skip)]

use super::*;

pub(in crate)
fn mb_file_expanded (output: TokenStream2)
  -> TokenStream2
{
    let mut debug_macros_dir =
        match ::std::env::var_os("DEBUG_MACROS_LOCATION") {
            | Some(it) => ::std::path::PathBuf::from(it),
            | None => return output,
        }
    ;
    let hopefully_unique = {
        use ::std::hash::*;
        let ref mut hasher =
            ::std::collections::hash_map::RandomState::new()
                .build_hasher()
        ;
        hasher.finish()
    };

    debug_macros_dir.push("safer-ffi-debugged-proc-macros");
    ::std::fs::create_dir_all(&debug_macros_dir)
        .unwrap_or_else(|err| panic!(
            "`DEBUG_MACROS_LOCATION`-error: failed to create {}: {}",
            debug_macros_dir.display(), err,
        ))
    ;
    let ref file_name = {
        debug_macros_dir.push(format!("{:016x}.rs", hopefully_unique));
        debug_macros_dir
            .into_os_string()
            .into_string()
            .expect("`DEBUG_MACROS_LOCATION`-error: \
                non-UTF-8 paths are not supported\
            ")
    };

    let macro_name = Ident::new(&format!("_{hopefully_unique:016x}"), Span::call_site());

    ::std::fs::write(
        file_name,
        ::std::panic::catch_unwind(|| ::prettyplease::unparse(&parse_quote!(#output)))
            .unwrap_or_else(|_| quote!(#output).to_string())
        ,
    )
        .unwrap_or_else(|err| panic!(
            "`DEBUG_MACROS_LOCATION`-error: failed to write to `{}`: {}",
            file_name, err
        ))
    ;
    let warning =
        compile_warning(&quote!(), &format!(
            "Output emitted to {file_name}",
        ))
    ;
    quote!(
        #warning

        ::core::include! {
            #file_name
        }
    )
}