Skip to content

ICE when proc-macro crate and non proc-macro crate share Cargo project #50640

Description

@SergioBenitez

This is a regression introduced in a recent nightly.

When a lib and a bin are declared in the same Cargo project, where the lib is of type proc-macro, rustc experiences an ICE with a message of thread 'main' panicked at 'librustc_metadata/creader.rs:520: proc-macro crate not dylib', librustc/session/mod.rs:1281:26. This error does not occur when the proc-macro lib and the bin are split into independent Cargo projects. Running with CARGO_INCREMENTAL=0 does not change the outcome.

Cargo.toml looks as follows:

[package]
name = "demo"
version = "0.0.1"

[lib]
name = "codegen"
proc-macro = true
path = "src/lib.rs"

[[bin]]
name = "main"
path = "src/main.rs"

[dependencies]

src/lib.rs looks as follows:

#![feature(proc_macro)]

extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn demo(_args: TokenStream, input: TokenStream) -> TokenStream {
    input
}

src/main.rs looks as follows:

#![feature(proc_macro)]

extern crate codegen;

use codegen::demo;

#[demo]
fn test() { }

fn main() {
    println!("Hello, world!");
}

The full error log:

Details
❯ rustc --version --verbose
rustc 1.27.0-nightly (e5f80f2a4 2018-05-09)
binary: rustc
commit-hash: e5f80f2a4f016bf724a1cfb580619d71c8fd39ec
commit-date: 2018-05-09
host: x86_64-apple-darwin
release: 1.27.0-nightly
LLVM version: 6.0

❯ RUST_BACKTRACE=1 cargo check -v
Checking demo v0.0.1 (file:///rustc-bug)
Running rustc --crate-name main src/main.rs --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=411579df123c68f9 -C extra-filename=-411579df123c68f9 --out-dir /rustc-bug/target/debug/deps -C incremental=/rustc-bug/target/debug/incremental -L dependency=/rustc-bug/target/debug/deps --extern codegen=/rustc-bug/target/debug/deps/libcodegen-c52c60a16469d04d.rmeta
thread 'main' panicked at 'librustc_metadata/creader.rs:520: proc-macro crate not dylib', librustc/session/mod.rs:1281:26
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
1: std::sys_common::backtrace::print
2: std::panicking::default_hook::{{closure}}
3: std::panicking::default_hook
4: rustc::util::common::panic_hook
5: std::panicking::rust_panic_with_hook
6: std::panicking::begin_panic
7: rustc::session::opt_span_bug_fmt::{{closure}}
8: rustc::ty::context::tls::with_opt::{{closure}}
9: rustc::ty::context::tls::with_context_opt
10: rustc::ty::context::tls::with_opt
11: rustc::session::opt_span_bug_fmt
12: rustc::session::span_bug_fmt
13: rustc_metadata::creader::CrateLoader::resolve_crate
14: <rustc_metadata::creader::CrateLoader<'a> as rustc::middle::cstore::CrateLoader>::process_extern_crate
15: rustc_resolve::build_reduced_graph::<impl rustc_resolve::Resolver<'a>>::build_reduced_graph_for_item
16: <rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor<'a, 'b> as syntax::visit::Visitor<'a>>::visit_item
17: syntax::visit::walk_item
18: <rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor<'a, 'b> as syntax::visit::Visitor<'a>>::visit_item
19: syntax::ext::expand::Expansion::visit_with
20: rustc_resolve::macros::<impl syntax::ext::base::Resolver for rustc_resolve::Resolver<'a>>::visit_expansion
21: syntax::ext::expand::MacroExpander::collect_invocations
22: syntax::ext::expand::MacroExpander::expand
23: syntax::ext::expand::MacroExpander::expand_crate
24: rustc_driver::driver::phase_2_configure_and_expand_inner::{{closure}}
25: rustc::util::common::time
26: rustc_driver::driver::phase_2_configure_and_expand
27: rustc_driver::driver::compile_input
28: rustc_driver::run_compiler_impl
29: <scoped_tls::ScopedKey>::set
30: syntax::with_globals
31: <std::panic::AssertUnwindSafe as core::ops::function::FnOnce<()>>::call_once
32: __rust_maybe_catch_panic
33: rustc_driver::run
34: rustc_driver::main
35: std::rt::lang_start::{{closure}}
36: std::panicking::try::do_call
37: __rust_maybe_catch_panic
38: std::rt::lang_start_internal
39: main
query stack during panic:
end of query stack

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.27.0-nightly (e5f80f2a4 2018-05-09) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

error: Could not compile demo.

Caused by:
process didn't exit successfully: rustc --crate-name main src/main.rs --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=411579df123c68f9 -C extra-filename=-411579df123c68f9 --out-dir /rustc-bug/target/debug/deps -C incremental=/rustc-bug/target/debug/incremental -L dependency=/rustc-bug/target/debug/deps --extern codegen=/rustc-bug/target/debug/deps/libcodegen-c52c60a16469d04d.rmeta (exit code: 101)

Activity

  1. emilyalbini commented on May 11, 2018

    @emilyalbini
    Member

    A bisect points at #50345 as the cause of the regression, which is a rollup. The only thing that might make sense in there is the cargo update. cc @alexcrichton

  2. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)
    C-bugCategory: This is a bug.
    on May 11, 2018
  3. added this to the 1.27 milestone on May 11, 2018
  4. alexcrichton commented on May 11, 2018

    @alexcrichton
    Member

    Yep looks like a Cargo regression, looking into it

  5. added a commit that references this issue on May 11, 2018
    5e76cbc
  6. alexcrichton commented on May 11, 2018

    @alexcrichton
    Member

    I believe this should be fixed in rust-lang/cargo#5520

  7. added 2 commits that reference this issue on May 11, 2018
    cfeb768
    cbf6c57
  8. added a commit that references this issue on May 12, 2018
  9. 4 remaining items

  10. added a commit that references this issue on May 14, 2018
  11. added a commit that references this issue on May 15, 2018
  12. added a commit that references this issue on May 15, 2018
  13. SergioBenitez commented on May 16, 2018

    @SergioBenitez
    ContributorAuthor

    This is still an issue in 2018-05-15 when running cargo check.

  14. added and removed on May 16, 2018
  15. emilyalbini commented on May 16, 2018

    @emilyalbini
    Member

    @SergioBenitez the issue is fixed in cargo, and cargo was updated in beta. The PR updating it in nightly (#50696) is not merged yet.

  16. added a commit that references this issue on May 16, 2018
  17. added a commit that references this issue on May 16, 2018
    4208bd5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions