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: panicked at 'called Option::unwrap() on a None value', compiler/rustc_resolve/src/late/diagnostics.rs:478:65 #83510

Closed
Spadi0 opened this issue Mar 26, 2021 · 1 comment · Fixed by #83634
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-proc-macros Area: Procedural macros A-resolve Area: Path resolution C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Spadi0
Copy link

Spadi0 commented Mar 26, 2021

With a proc_macro, an ICE occurs when generating an impl block (whether for a trait or not) that has an associated type that looks like this:

type Foo = Box<Bar> + Baz;

The type needs to be a valid (in scope) type that takes a generic parameter, with a trait/lifetime bound. Both the generic parameter and the trait/lifetime bound don't actually need to be in scope - just syntactically valid.

I only found this after a typo (Pin<Box<...>> + 'static instead of Pin<Box<... + 'static>>); this code shouldn't compile without the ICE anyway - the trait/lifetime bound is on a concrete type. As a result, I cannot foresee a situation where valid code that should compile would fail to compile as a result of this ICE.

Code

use proc_macro::TokenStream;

#[proc_macro]
pub fn cause_an_ice(_: TokenStream) -> TokenStream {
    r#"
    impl Foo {
        type Bar = Box<()> + Baz;
    }
    "#
    .parse()
    .unwrap()
}

Meta

Occurs on latest stable, beta and nightly versions.

rustc --version --verbose:

rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: aarch64-apple-darwin
release: 1.51.0
LLVM version: 11.0.1
rustc 1.52.0-beta.1 (6a1077d47 2021-03-24)
binary: rustc
commit-hash: 6a1077d47f3c87dd98f881fc456a05a4c39874bc
commit-date: 2021-03-24
host: aarch64-apple-darwin
release: 1.52.0-beta.1
LLVM version: 12.0.0
rustc 1.53.0-nightly (07e0e2ec2 2021-03-24)
binary: rustc
commit-hash: 07e0e2ec268c140e607e1ac7f49f145612d0f597
commit-date: 2021-03-24
host: aarch64-apple-darwin
release: 1.53.0-nightly
LLVM version: 12.0.0

I have also tested this on a host running x86_64-pc-windows-msvc, and the ICE also occurs on that machine as well.

Error output

   Compiling ice v0.1.0 (/Users/user/ice)
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_resolve/src/late/diagnostics.rs:478:65
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.51.0 (2fd73fabe 2021-03-23) running on aarch64-apple-darwin

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

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

query stack during panic:
end of query stack
error: could not compile `ice`

To learn more, run the command again with --verbose.
Backtrace

stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: rustc_resolve::late::diagnostics::<impl rustc_resolve::late::LateResolutionVisitor>::smart_resolve_report_errors
   4: rustc_resolve::late::LateResolutionVisitor::smart_resolve_path_fragment::{{closure}}
   5: rustc_resolve::late::LateResolutionVisitor::smart_resolve_path_fragment
   6: rustc_resolve::late::LateResolutionVisitor::smart_resolve_path
   7: <rustc_resolve::late::LateResolutionVisitor as rustc_ast::visit::Visitor>::visit_poly_trait_ref
   8: rustc_ast::visit::walk_ty
   9: <rustc_resolve::late::LateResolutionVisitor as rustc_ast::visit::Visitor>::visit_ty
  10: rustc_resolve::late::LateResolutionVisitor::with_generic_param_rib
  11: rustc_resolve::late::LateResolutionVisitor::resolve_item
  12: rustc_resolve::late::<impl rustc_resolve::Resolver>::late_resolve_crate
  13: rustc_session::utils::<impl rustc_session::session::Session>::time
  14: rustc_resolve::Resolver::resolve_crate
  15: rustc_interface::passes::configure_and_expand_inner
  16: rustc_interface::passes::configure_and_expand::{{closure}}
  17: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::new
  18: rustc_interface::passes::configure_and_expand
  19: rustc_interface::queries::Queries::expansion
  20: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  21: rustc_span::with_source_map
  22: rustc_interface::interface::create_compiler_and_run
  23: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@Spadi0 Spadi0 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 Mar 26, 2021
@jonas-schievink jonas-schievink added A-proc-macros Area: Procedural macros A-resolve Area: Path resolution I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 26, 2021
@jyn514 jyn514 added the A-diagnostics Area: Messages for errors, warnings, and lints label Mar 26, 2021
@JohnTitor
Copy link
Member

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@JohnTitor JohnTitor added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 29, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 7, 2021
Do not emit the advanced diagnostics on macros

Fixes rust-lang#83510
@bors bors closed this as completed in 2c55bac Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-proc-macros Area: Procedural macros A-resolve Area: Path resolution C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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