Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE with proc-macro expanding to illegal type syntax #66467

Closed
jfrimmel opened this issue Nov 16, 2019 · 2 comments
Closed

ICE with proc-macro expanding to illegal type syntax #66467

jfrimmel opened this issue Nov 16, 2019 · 2 comments

Comments

@jfrimmel
Copy link
Contributor

I've written a proc macro, that consistently produces an ICE. You'll find the code and the backtrace below. Note, that the ICE occurs with any type, that originates in an external crate, that is not included in the Cargo.toml (tested with regex::Regex and spin::Once).

`proc-macro-ice` Source code

Cargo.toml

[package]
name = "proc-macro-ice"
version = "0.1.0"
edition = "2018"

[lib]
proc-macro = true

[dependencies]
quote = "1.0"

src/lib.rs

extern crate proc_macro;

use proc_macro::TokenStream;
use quote::quote;

#[proc_macro_attribute]
pub fn y(_: TokenStream, _: TokenStream) -> TokenStream {
    let expanded = quote! {
        struct A(regex::Regex);
        static X: A(regex::Regex) = A(regex::Regex::new("a"));
    };
    expanded.into()
}

tests/ice.rs

#[proc_macro_ice::y]
struct S;

Backtrace on cargo test:

error[E0433]: failed to resolve: use of undeclared type or module `regex`
 --> tests/ice.rs:1:1
  |
1 | #[proc_macro_ice::y]
  | ^^^^^^^^^^^^^^^^^^^^ use of undeclared type or module `regex`

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/4f03f4a989d1c8346c19dfb417a77c09b34408b8/src/libcore/macros.rs:41:40
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:61
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1030
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:188
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:205
  10: rustc_driver::report_ice
  11: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at /rustc/4f03f4a989d1c8346c19dfb417a77c09b34408b8/src/liballoc/boxed.rs:956
  12: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}::{{closure}}
             at /rustc/4f03f4a989d1c8346c19dfb417a77c09b34408b8/src/libproc_macro/bridge/client.rs:305
  13: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:468
  14: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:373
  15: rust_begin_unwind
             at src/libstd/panicking.rs:302
  16: core::panicking::panic_fmt
             at src/libcore/panicking.rs:141
  17: core::panicking::panic
             at src/libcore/panicking.rs:72
  18: rustc::hir::lowering::LoweringContext::lower_path_segment
  19: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  20: <rustc::hir::ptr::P<[T]> as core::iter::traits::collect::FromIterator<T>>::from_iter
  21: rustc::hir::lowering::LoweringContext::lower_qpath
  22: rustc::hir::lowering::LoweringContext::lower_path_ty
  23: rustc::hir::lowering::LoweringContext::lower_ty_direct
  24: rustc::hir::lowering::item::<impl rustc::hir::lowering::LoweringContext>::lower_item_kind
  25: rustc::hir::lowering::item::<impl rustc::hir::lowering::LoweringContext>::lower_item
  26: rustc::hir::lowering::LoweringContext::with_hir_id_owner
  27: <rustc::hir::lowering::item::ItemLowerer as syntax::visit::Visitor>::visit_mod
  28: rustc::hir::lowering::lower_crate
  29: rustc_interface::passes::BoxedResolver::access::{{closure}}
  30: rustc_interface::passes::configure_and_expand::{{closure}}
  31: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::access
  32: rustc_interface::queries::Query<T>::compute
  33: rustc_interface::queries::Query<T>::compute
  34: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::global_ctxt
  35: rustc_interface::interface::run_compiler_in_existing_thread_pool
  36: std::thread::local::LocalKey<T>::with
  37: scoped_tls::ScopedKey<T>::set
  38: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.40.0-nightly (4f03f4a98 2019-11-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.
error: could not compile `proc-macro-ice`.

To learn more, run the command again with --verbose.
@jfrimmel
Copy link
Contributor Author

Note the wrong syntax, that is quoted:

struct A(regex::Regex);
static X: A(regex::Regex) = A(regex::Regex::new("a"));

It seems, that the wrong parenthesis on the specified type cause the crash.

@jfrimmel jfrimmel changed the title ICE with proc-macro expanding to non-declared crate ICE with proc-macro expanding to illegal type syntax Nov 16, 2019
@csmoe
Copy link
Member

csmoe commented Nov 16, 2019

Fixed by #66390

@csmoe csmoe closed this as completed Nov 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants