rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
95.35k stars 12.28k forks source link

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

Open cushionbadak opened 1 month ago

cushionbadak commented 1 month ago

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)

```Rust //@ 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() 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: ::projection_ty 5: ::new 6: ::new 7: ::place_into_pattern 8: ::ast_block_stmts 9: ::expr_into_dest 10: ::expr_into_dest::{closure#0} 11: ::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: ::visit_inner_body 16: ::visit_expr 17: ::visit_expr 18: rustc_middle::thir::visit::walk_block:: 19: ::visit_expr 20: ::visit_expr 21: rustc_mir_build::check_unsafety::check_unsafety [... omitted 1 frame ...] 22: ::par_body_owners::::{closure#0} 23: rustc_interface::passes::run_required_analyses 24: rustc_interface::passes::analysis [... omitted 1 frame ...] 25: >::enter::, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}> 26: rustc_interface::interface::run_compiler::, 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

cushionbadak commented 1 month ago

searched nightlies: from nightly-2023-01-01 to nightly-2024-05-30 regressed nightly: nightly-2024-02-09 searched commit range: https://github.com/rust-lang/rust/compare/8ace7ea1f7cbba7b4f031e66c54ca237a0d65de6...98aa3624be70462d6a25ed5544333e3df62f4c66 regressed commit: https://github.com/rust-lang/rust/commit/af88f7db51f6f2a1472f9279d7c7e7c822afff77

bisected with cargo-bisect-rustc v0.6.8 Host triple: x86_64-unknown-linux-gnu Reproduce with: ```bash cargo bisect-rustc --start=2023-01-01 --end=2024-05-30 --regress=ice --script=rustc --preserve -- 125801.rs ```