Skip to content

ICE: panicked at 'called Option::unwrap() on a None value', compiler/rustc_resolve/src/late/diagnostics.rs:478:65 #83510

Closed
@Spadi0

Description

@Spadi0

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-proc-macrosArea: Procedural macrosA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions