<p dir="auto">We need a way to export macros from modules and import them in other modules.</p>
<p dir="auto">Currently we either prepend a string of macro definitions to every file, such as with <code class="notranslate">debug!</code>, <code class="notranslate">error!</code>, etc., or we just copy and paste the macros we need. This second approach leads to code duplication and lots of subtly different implementations.</p>
<p dir="auto">As a temporary workaround, we could probably use <code class="notranslate">include!</code>.</p>
<p dir="auto">Compiler version:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="rustc 0.13.0-nightly (399ff259e 2014-11-20 00:27:07 +0000)
binary: rustc
commit-hash: 399ff259e18c1061aa4ea60856fcecb486d36624
commit-date: 2014-11-20 00:27:07 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-nightly"><pre class="notranslate"><code class="notranslate">rustc 0.13.0-nightly (399ff259e 2014-11-20 00:27:07 +0000)
binary: rustc
commit-hash: 399ff259e18c1061aa4ea60856fcecb486d36624
commit-date: 2014-11-20 00:27:07 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-nightly
</code></pre></div>
<p dir="auto">Error with backtrace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;std macros&gt;:3:24: 10:11 error: type `NullWriter` cannot be dereferenced
&lt;std macros&gt;:3         let dst = &amp;mut *$dst;
&lt;std macros&gt;:4         format_args!(|args| { dst.write_fmt(args) }, $($arg)*)
&lt;std macros&gt;:5     })
&lt;std macros&gt;:6 )
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' panicked at 'index out of bounds: the len is 6 but the index is 6', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/lib.rs:1

stack backtrace:
   1:     0x7f4d33ad19c0 - rt::backtrace::imp::write::h7fe8534f465d0e09y9s
   2:     0x7f4d33ad4b60 - failure::on_fail::h3fe2ecde6aab0bb8rwt
   3:     0x7f4d34277c80 - unwind::begin_unwind_inner::he6bc2073d4eb582enbd
   4:     0x7f4d34277900 - unwind::begin_unwind_fmt::h305b4b28825355b2y8c
   5:     0x7f4d342778c0 - rust_begin_unwind
   6:     0x7f4d342bda70 - panicking::panic_fmt::h9d03fcf6b4c3f8e10Nl
   7:     0x7f4d342c2e60 - panicking::panic_bounds_check::h5c6357fea6530f04yMl
   8:     0x7f4d31946130 - codemap::FileMap::get_line::h8bd7cfe56e6cfd5e1aF
   9:     0x7f4d319749b0 - diagnostic::emit::h2322127ddc0c36debCG
  10:     0x7f4d319713d0 - diagnostic::EmitterWriter.Emitter::emit::hb9a4d5c26c04e1df0xG
  11:     0x7f4d3196fc50 - diagnostic::Handler::emit::ha390aea82acc4940kfG
  12:     0x7f4d31942910 - diagnostic::SpanHandler::span_err::h83b27707d23c7bfej3F
  13:     0x7f4d32d40720 - middle::typeck::infer::InferCtxt&lt;'a, 'tcx&gt;::type_error_message_str_with_expected::h72941615d6be270289E
  14:     0x7f4d32c4c840 - middle::typeck::infer::InferCtxt&lt;'a, 'tcx&gt;::type_error_message::h3e78576a7aeba36csfF
  15:     0x7f4d32c55f70 - middle::typeck::check::check_expr_with_unifier::h23742768f253d831DLl
  16:     0x7f4d32c55f70 - middle::typeck::check::check_expr_with_unifier::h23742768f253d831DLl
  17:     0x7f4d32ccac40 - middle::typeck::check::check_decl_local::h24893462a5fe4409xSn
  18:     0x7f4d32ccae00 - middle::typeck::check::check_stmt::h1ca15bfe8a7d5a87xUn
  19:     0x7f4d32c04d90 - middle::typeck::check::check_block_with_expected::heebc1a2b04a42760MYn
  20:     0x7f4d32c55f70 - middle::typeck::check::check_expr_with_unifier::h23742768f253d831DLl
  21:     0x7f4d32ccae00 - middle::typeck::check::check_stmt::h1ca15bfe8a7d5a87xUn
  22:     0x7f4d32c04d90 - middle::typeck::check::check_block_with_expected::heebc1a2b04a42760MYn
  23:     0x7f4d32c00810 - middle::typeck::check::check_fn::hd39b1b6b62f22c3fici
  24:     0x7f4d32c00530 - middle::typeck::check::check_bare_fn::h779ff7b2db70ca5bn1h
  25:     0x7f4d32bfc310 - middle::typeck::check::check_item::hde22067b8b575546vli
  26:     0x7f4d32c001c0 - middle::typeck::check::check_item_types::h7118271db2ab8ea8x0h
  27:     0x7f4d32fece10 - util::common::time::h4997555828079517418
  28:     0x7f4d32fec020 - middle::typeck::check_crate::h0949dffd97487b5ejVL
  29:     0x7f4d3477ba10 - driver::driver::phase_3_run_analysis_passes::h7f3610cf195b4c3abfS
  30:     0x7f4d34770830 - driver::driver::compile_input::h13734d451479d6e7VVR
  31:     0x7f4d347f57b0 - driver::run_compiler::h0a1cb9376c105f68pUT
  32:     0x7f4d347f56a0 - driver::run::closure.59745
  33:     0x7f4d34601ee0 - task::TaskBuilder&lt;S&gt;::try_future::closure.39051
  34:     0x7f4d34601cd0 - task::TaskBuilder&lt;S&gt;::spawn_internal::closure.39022
  35:     0x7f4d34b15b90 - task::NativeSpawner.Spawner::spawn::closure.2472
  36:     0x7f4d342d04c0 - rust_try_inner
  37:     0x7f4d342d04b0 - rust_try
  38:     0x7f4d342755e0 - unwind::try::h7c27f4e149aed3f2IZc
  39:     0x7f4d34275470 - task::Task::run::h75863ac7ddab20c0y5b
  40:     0x7f4d34b158d0 - task::NativeSpawner.Spawner::spawn::closure.2398
  41:     0x7f4d34276c90 - thread::thread_start::h7822af80b22f729bEqc
  42:     0x7f4d2eb5b250 - start_thread
  43:     0x7f4d33f4d3b9 - clone
  44:                0x0 - &lt;unknown&gt;"><pre class="notranslate"><code class="notranslate">&lt;std macros&gt;:3:24: 10:11 error: type `NullWriter` cannot be dereferenced
&lt;std macros&gt;:3         let dst = &amp;mut *$dst;
&lt;std macros&gt;:4         format_args!(|args| { dst.write_fmt(args) }, $($arg)*)
&lt;std macros&gt;:5     })
&lt;std macros&gt;:6 )
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' panicked at 'index out of bounds: the len is 6 but the index is 6', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/lib.rs:1

stack backtrace:
   1:     0x7f4d33ad19c0 - rt::backtrace::imp::write::h7fe8534f465d0e09y9s
   2:     0x7f4d33ad4b60 - failure::on_fail::h3fe2ecde6aab0bb8rwt
   3:     0x7f4d34277c80 - unwind::begin_unwind_inner::he6bc2073d4eb582enbd
   4:     0x7f4d34277900 - unwind::begin_unwind_fmt::h305b4b28825355b2y8c
   5:     0x7f4d342778c0 - rust_begin_unwind
   6:     0x7f4d342bda70 - panicking::panic_fmt::h9d03fcf6b4c3f8e10Nl
   7:     0x7f4d342c2e60 - panicking::panic_bounds_check::h5c6357fea6530f04yMl
   8:     0x7f4d31946130 - codemap::FileMap::get_line::h8bd7cfe56e6cfd5e1aF
   9:     0x7f4d319749b0 - diagnostic::emit::h2322127ddc0c36debCG
  10:     0x7f4d319713d0 - diagnostic::EmitterWriter.Emitter::emit::hb9a4d5c26c04e1df0xG
  11:     0x7f4d3196fc50 - diagnostic::Handler::emit::ha390aea82acc4940kfG
  12:     0x7f4d31942910 - diagnostic::SpanHandler::span_err::h83b27707d23c7bfej3F
  13:     0x7f4d32d40720 - middle::typeck::infer::InferCtxt&lt;'a, 'tcx&gt;::type_error_message_str_with_expected::h72941615d6be270289E
  14:     0x7f4d32c4c840 - middle::typeck::infer::InferCtxt&lt;'a, 'tcx&gt;::type_error_message::h3e78576a7aeba36csfF
  15:     0x7f4d32c55f70 - middle::typeck::check::check_expr_with_unifier::h23742768f253d831DLl
  16:     0x7f4d32c55f70 - middle::typeck::check::check_expr_with_unifier::h23742768f253d831DLl
  17:     0x7f4d32ccac40 - middle::typeck::check::check_decl_local::h24893462a5fe4409xSn
  18:     0x7f4d32ccae00 - middle::typeck::check::check_stmt::h1ca15bfe8a7d5a87xUn
  19:     0x7f4d32c04d90 - middle::typeck::check::check_block_with_expected::heebc1a2b04a42760MYn
  20:     0x7f4d32c55f70 - middle::typeck::check::check_expr_with_unifier::h23742768f253d831DLl
  21:     0x7f4d32ccae00 - middle::typeck::check::check_stmt::h1ca15bfe8a7d5a87xUn
  22:     0x7f4d32c04d90 - middle::typeck::check::check_block_with_expected::heebc1a2b04a42760MYn
  23:     0x7f4d32c00810 - middle::typeck::check::check_fn::hd39b1b6b62f22c3fici
  24:     0x7f4d32c00530 - middle::typeck::check::check_bare_fn::h779ff7b2db70ca5bn1h
  25:     0x7f4d32bfc310 - middle::typeck::check::check_item::hde22067b8b575546vli
  26:     0x7f4d32c001c0 - middle::typeck::check::check_item_types::h7118271db2ab8ea8x0h
  27:     0x7f4d32fece10 - util::common::time::h4997555828079517418
  28:     0x7f4d32fec020 - middle::typeck::check_crate::h0949dffd97487b5ejVL
  29:     0x7f4d3477ba10 - driver::driver::phase_3_run_analysis_passes::h7f3610cf195b4c3abfS
  30:     0x7f4d34770830 - driver::driver::compile_input::h13734d451479d6e7VVR
  31:     0x7f4d347f57b0 - driver::run_compiler::h0a1cb9376c105f68pUT
  32:     0x7f4d347f56a0 - driver::run::closure.59745
  33:     0x7f4d34601ee0 - task::TaskBuilder&lt;S&gt;::try_future::closure.39051
  34:     0x7f4d34601cd0 - task::TaskBuilder&lt;S&gt;::spawn_internal::closure.39022
  35:     0x7f4d34b15b90 - task::NativeSpawner.Spawner::spawn::closure.2472
  36:     0x7f4d342d04c0 - rust_try_inner
  37:     0x7f4d342d04b0 - rust_try
  38:     0x7f4d342755e0 - unwind::try::h7c27f4e149aed3f2IZc
  39:     0x7f4d34275470 - task::Task::run::h75863ac7ddab20c0y5b
  40:     0x7f4d34b158d0 - task::NativeSpawner.Spawner::spawn::closure.2398
  41:     0x7f4d34276c90 - thread::thread_start::h7822af80b22f729bEqc
  42:     0x7f4d2eb5b250 - start_thread
  43:     0x7f4d33f4d3b9 - clone
  44:                0x0 - &lt;unknown&gt;
</code></pre></div>
<p dir="auto">Offending code:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="use std::fmt;
struct NullWriter;
impl fmt::FormatWriter for NullWriter {
  fn write(&amp;mut self, bytes: &amp;[u8]) -&gt; fmt::Result {
    Ok(())
  }
}
fn main() {
  let mut n = NullWriter;
  write!(n, &quot;1, 2, {}&quot;, 3);
}"><pre class="notranslate"><span class="pl-k">use</span> std<span class="pl-kos">::</span>fmt<span class="pl-kos">;</span>
<span class="pl-k">struct</span> <span class="pl-smi">NullWriter</span><span class="pl-kos">;</span>
<span class="pl-k">impl</span> fmt<span class="pl-kos">::</span><span class="pl-smi">FormatWriter</span> <span class="pl-k">for</span> <span class="pl-smi">NullWriter</span> <span class="pl-kos">{</span>
  <span class="pl-k">fn</span> <span class="pl-en">write</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">self</span><span class="pl-kos">,</span> <span class="pl-s1">bytes</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-kos">[</span><span class="pl-smi">u8</span><span class="pl-kos">]</span><span class="pl-kos">)</span> -&gt; fmt<span class="pl-kos">::</span><span class="pl-smi">Result</span> <span class="pl-kos">{</span>
    <span class="pl-v">Ok</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span>
<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">let</span> <span class="pl-k">mut</span> n = <span class="pl-v">NullWriter</span><span class="pl-kos">;</span>
  <span class="pl-en">write</span><span class="pl-en">!</span><span class="pl-kos">(</span>n, <span class="pl-s">"1, 2, {}"</span>, <span class="pl-c1">3</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">If it's of any help, this also happens when using libcore directly (my original use-case) with <code class="notranslate">#![no_std]</code>.</p>