title: Is there a way to get the file and the module path of where a procedural macro is attached at compile-time?
body: <p>I'm looking for the equivalent of <code>file!()</code> &amp; <code>module_path!()</code> in a procedural macro context.</p>
  
  <p>For example, the following doesn't work:</p>
  
  <p><code>file.rs</code>:</p>
  
  <pre class="lang-rust prettyprint-override"><code>#[some_attribute]
  const A: bool = true;
  </code></pre>
  
  <p><code>macro.rs</code>:</p>
  
  <pre class="lang-rust prettyprint-override"><code>#[proc_macro_attribute]
  pub fn some_attribute(attr: TokenStream, input: TokenStream) -&gt; TokenStream {
      println!("{}", file!());
  
      input
  }
  </code></pre>
  
  <p>This prints <code>macro.rs</code> which makes sense, but what I want is <code>file.rs</code>. Is there a way to achieve this? Is there also a similar way for <code>module_path!()</code>?</p>
  
  <p>A requirement of this is that has to happen at compile-time.</p>
  
  <p>I'm trying to create a file in the <code>OUT_DIR</code> containing constant values where the attribute is added with the module and the file that they are in.</p>