Skip to content

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

Open

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

  • ICE location: rustc_middle/src/mir/tcx.rs L88
    let answer = match *elem {
    ProjectionElem::Deref => {
    let ty = self.ty.builtin_deref(true).unwrap_or_else(|| {
    bug!("deref projection of non-dereferenceable ty {:?}", self)
    });
    PlaceTy::from_ty(ty)
    }
    ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } => {
    PlaceTy::from_ty(self.ty.builtin_index().unwrap())
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-bugCategory: This is a bug.Category: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]``#![feature(generic_const_exprs)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: This bug is tracked inside the repo by a `known-bug` test.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-incomplete-features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions