rust-lang / rust-lang/rust

ICE: `called Option::unwrap() on a None value in rustc_middle/src/mir/tcx.rs`

Open
#125,801 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-MIR C-bug F-generic_const_exprs I-ICE P-low S-bug-has-test S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

(hand-reduced)

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

trait Foo {
    type Output;
}

impl Foo for [u8; 3] {
    type Output = [u8; 3];
}

static A: <[u8; N] as Foo>::Output = [1, 2, 3];

fn main() {
    || {
        let _ = A[1];
    };
}
(original)

//@ build-pass

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

trait Foo {
    type Output;

    fn foo() -> Self::Output;
}

impl Foo for [u8; 3] {
    type Output = [u8; 1 + 2];

    fn foo() -> [u8; 3] {
        [1u8; 3]
    }
}

fn bug<const N: usize>()
where
    [u8; N]: Foo,
    <[u8; N] as Foo>::Output: AsRef<[u8]>,
{
    <[u8; N]>::foo().as_ref();
}

fn main() {
    bug::<3>();
}


//@ build-pass
#![feature(coroutines)]

static A: <[u8; N] as Foo>::Output = [1, 2, 3, 4, 5];

fn main() {
    #[coroutine] static || {
        let u = A[{yield; 1}];
    };
    #[coroutine] static || {
        match A {
            i if { yield; true } => (),
            _ => (),
        }
    };
}

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (6f3df08aa 2024-05-30)
binary: rustc
commit-hash: 6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4
commit-date: 2024-05-30
host: x86_64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6
Error output

Command: rustc

error[E0425]: cannot find value `N` in this scope
  --> r_tcx_1F6082.rs:12:17
   |
12 | static A: <[u8; N] as Foo>::Output = [1, 2, 3];
   |                 ^ not found in this scope
Backtrace

thread 'rustc' panicked at compiler/rustc_middle/src/mir/tcx.rs:88:58:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: core::option::unwrap_failed
   4: <rustc_middle::mir::tcx::PlaceTy>::projection_ty
   5: <rustc_mir_build::build::matches::MatchPair>::new
   6: <rustc_mir_build::build::matches::FlatPat>::new
   7: <rustc_mir_build::build::Builder>::place_into_pattern
   8: <rustc_mir_build::build::Builder>::ast_block_stmts
   9: <rustc_mir_build::build::Builder>::expr_into_dest
  10: <rustc_mir_build::build::Builder>::expr_into_dest::{closure#0}
  11: <rustc_mir_build::build::Builder>::expr_into_dest
  12: rustc_mir_build::build::construct_fn
  13: rustc_mir_build::build::mir_build
  14: rustc_mir_transform::mir_built
      [... omitted 1 frame ...]
  15: <rustc_mir_build::check_unsafety::UnsafetyVisitor>::visit_inner_body
  16: <rustc_mir_build::check_unsafety::UnsafetyVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  17: <rustc_mir_build::check_unsafety::UnsafetyVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  18: rustc_middle::thir::visit::walk_block::<rustc_mir_build::check_unsafety::UnsafetyVisitor>
  19: <rustc_mir_build::check_unsafety::UnsafetyVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  20: <rustc_mir_build::check_unsafety::UnsafetyVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  21: rustc_mir_build::check_unsafety::check_unsafety
      [... omitted 1 frame ...]
  22: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  23: rustc_interface::passes::run_required_analyses
  24: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  25: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  26: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: 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: please make sure that you have updated to the latest nightly

note: please attach the file at `/Volumes/T7/workspace/240530_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-05-31T07_58_41-11292.txt` to your bug report

query stack during panic:
#0 [mir_built] building MIR for `main::{closure#0}`
#1 [check_unsafety] unsafety-checking `main`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0425`.

Note

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the hand-reduced example with rustc and reading compiler/rustc_middle/src/mir/tcx.rs at L88, using the supplied backtrace to trace PlaceTy::projection_ty through rustc_mir_build match construction. Done means this input no longer causes the compiler to panic while producing its diagnostic; the issue does not name a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.