Is there any way to use a const value as a literal in a macro?

So for example, I want to do something similar to this:

// my_proc_macro.rs
fn my_proc_macro(filename: &'static str) -> TokenStream {
  quote! {
    include_str!(#filename)
  }
}
// main.rs
const FILENAME: &'static str = "myfile.txt";

let x = my_proc_macro(FILENAME);

I feel like macro expansion is too early for this to work, but I'm open to equivalent hacky solutions.

No, macros get expanded long before any sort of const evaluation

2 Likes