dtolnay / proc-macro2

Apache License 2.0
739 stars 117 forks source link

quote panics when proc-macro2 uses nightly feature #85

Closed BigBigos closed 6 years ago

BigBigos commented 6 years ago

I have encountered this problem after I enabled the nightly feature of proc-macro2. There is no issue when the nightly feature is disabled.

I am testing it with the recent nightly toolchain, but the problem goes back to nightly-2018-04-06 at the very least.

See also: rust-lang/rust#50184

A simple usage of quote!() causes:

thread 'main' panicked at 'proc_macro::__internal::with_sess() called before set_parse_sess()!', libproc_macro/lib.rs:1319:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:205
   3: std::panicking::default_hook
             at libstd/panicking.rs:221
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:457
   5: std::panicking::begin_panic
   6: proc_macro::__internal::with_sess
   7: proc_macro2::imp::Span::call_site
             at /home/bigos/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.3.7/src/unstable.rs:214
   8: proc_macro2::Span::call_site
             at /home/bigos/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-0.3.7/src/lib.rs:186
   9: quote_test::main
             at src/main.rs:5
  10: std::rt::lang_start::{{closure}}
             at /checkout/src/libstd/rt.rs:74
  11: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:304
  12: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  13: std::rt::lang_start_internal
             at libstd/panicking.rs:283
             at libstd/panic.rs:361
             at libstd/rt.rs:58
  14: std::rt::lang_start
             at /checkout/src/libstd/rt.rs:74
  15: main
  16: __libc_start_main
  17: _start

You can reproduce it with:

Cargo.toml

[package]
name = "quote-test"
version = "0.1.0"

[dependencies]
proc-macro2 = { version = "0.3.1", features = ["nightly"] }
quote = "0.5.1"

src/main.rs

#[macro_use]
extern crate quote;

fn main() {
    quote!();
}
dtolnay commented 6 years ago

The nightly feature builds on the compiler's proc_macro which is currently only available within procedural macros. To use proc-macro2 / quote inside of main it needs to be without the nightly feature.

BigBigos commented 6 years ago

It seems I have a dependency issue then. One of the dependencies must enable the nightly feature in proc-macro2 but another uses quote!() in main (more specifically: string_cache_codegen uses it for its build.rs).

Will try to track down the dependency and see if anything can be done about it.

alexcrichton commented 6 years ago

Ah yeah as @dtolnay mentioned this is currently expected (unfortunately), so I'm going to close this