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 from public re-export of private enum variant in proc macro #79148

Closed
jam1garner opened this issue Nov 17, 2020 · 2 comments · Fixed by #100268
Closed

ICE from public re-export of private enum variant in proc macro #79148

jam1garner opened this issue Nov 17, 2020 · 2 comments · Fixed by #100268
Assignees
Labels
A-proc-macros Area: Procedural macros A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jam1garner
Copy link
Contributor

Code

proc macro:

use proc_macro::TokenStream;

#[proc_macro]
pub fn cause_ice(_: TokenStream) -> TokenStream {
    quote::quote!(
        enum IceCause {
            Variant,
        }

        pub use IceCause::Variant;
    ).into()
}

usage:

ice_macro::cause_ice!();

ICE is caused by pub re-exporting a single variant of a non-pub enum generated within a proc macro. Cannot be recreated with a declarative macro. marking the enum as pub/pub(in super), or pub(super) fixes the issue, while pub(crate) and pub(self) do not.

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
binary: rustc
commit-hash: ffa2e7ae8fbf9badc035740db949b9dae271c29f
commit-date: 2020-10-24
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0

Also recreated on stable:

rustc 1.47.0 (18bf6b4f0 2020-10-07)
binary: rustc
commit-hash: 18bf6b4f01a6feaf7259ba7cdae58031af1b7b39
commit-date: 2020-10-07
host: x86_64-unknown-linux-gnu
release: 1.47.0
LLVM version: 11.0

Error output

thread 'rustc' panicked at '`enum` keyword should exist in snippet', src/librustc_resolve/imports.rs:1453:26
note: run with `RUST_BACKTRACE=1` environment variable to display a 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.47.0 (18bf6b4f0 2020-10-07) running on x86_64-unknown-linux-gnu

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

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

error: could not compile `ice-reproduction`
Backtrace

stack backtrace:
   0: rust_begin_unwind
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:483:5
   1: core::panicking::panic_fmt
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/core/src/panicking.rs:85:14
   2: core::option::expect_failed
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/core/src/option.rs:1260:5
   3: rustc_resolve::ModuleData::for_each_child
   4: rustc_resolve::imports::ImportResolver::finalize_imports
   5: rustc_resolve::Resolver::resolve_crate
   6: rustc_interface::passes::configure_and_expand_inner
   7: rustc_interface::passes::configure_and_expand::{{closure}}
   8: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::new
   9: rustc_interface::passes::configure_and_expand
  10: rustc_interface::queries::Queries::expansion
  11: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  12: rustc_span::with_source_map
  13: rustc_interface::interface::create_compiler_and_run
  14: scoped_tls::ScopedKey<T>::set

*backtrace is from nightly commit ffa2e7a

I'd love to implement a fix, but figured I should make an issue to ensure it's not dupe work first and would appreciate any guidance as far as where to look and possible concerns when fixing.

@jam1garner jam1garner added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 17, 2020
@jyn514 jyn514 added the A-proc-macros Area: Procedural macros label Nov 17, 2020
@jyn514
Copy link
Member

jyn514 commented Nov 17, 2020

Note that this requires calling the proc-macro, not just defining it.

use ice_reproduction::cause_ice;

cause_ice!();

Here's a backtrace from 1.49:

thread 'rustc' panicked at '`enum` keyword should exist in snippet', compiler/rustc_resolve/src/imports.rs:1443:26
stack backtrace:
   0: rust_begin_unwind
             at /rustc/cf9cf7c923eb01146971429044f216a3ca905e06/library/std/src/panicking.rs:495:5
   1: core::panicking::panic_fmt
             at /rustc/cf9cf7c923eb01146971429044f216a3ca905e06/library/core/src/panicking.rs:92:14
   2: core::option::expect_failed
             at /rustc/cf9cf7c923eb01146971429044f216a3ca905e06/library/core/src/option.rs:1260:5
   3: rustc_resolve::ModuleData::for_each_child
   4: rustc_resolve::imports::ImportResolver::finalize_imports
   5: rustc_resolve::Resolver::resolve_crate
   6: rustc_interface::passes::configure_and_expand_inner
   7: rustc_interface::passes::configure_and_expand::{{closure}}
   8: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::new
   9: rustc_interface::passes::configure_and_expand
  10: rustc_interface::queries::Queries::expansion
  11: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  12: rustc_span::with_source_map
  13: rustc_interface::interface::create_compiler_and_run
  14: rustc_span::with_session_globals

@jyn514 jyn514 added the A-resolve Area: Name/path resolution done by `rustc_resolve` specifically label Nov 17, 2020
@cjgillot cjgillot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Aug 7, 2022
@cjgillot
Copy link
Contributor

cjgillot commented Aug 7, 2022

This is fixed on recent nightly.

@TaKO8Ki TaKO8Ki self-assigned this Aug 8, 2022
TaKO8Ki added a commit to TaKO8Ki/rust that referenced this issue Aug 8, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue Aug 9, 2022
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#100163 (Refactor: remove an unnecessary string search)
 - rust-lang#100212 (Remove more Clean trait implementations)
 - rust-lang#100238 (Further improve error message for E0081)
 - rust-lang#100268 (Add regression test for rust-lang#79148)
 - rust-lang#100294 (Update Duration::as_secs doc to point to as_secs_f64/32 for including fractional part)
 - rust-lang#100303 (:arrow_up: rust-analyzer)

Failed merges:

 - rust-lang#100281 (Remove more Clean trait implementations)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 89835a0 Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macros Area: Procedural macros A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants