rust-lang / rust

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

ICE: unreachable in compiler/rustc_ast/src/util/literal.rs with -Zunpretty=hir #100948

Closed matthiaskrgr closed 2 years ago

matthiaskrgr commented 2 years ago

Code

use std::iter::Iterator;

fn map<T, U, I: Iterator<T>>(fun: |T| -> U, mut iter: I) -> Vec<U> {
    let mut acc = vec![];
    for elt in iter {
        acc.push(fun(elt));
    }
    acc
}

fn main() {
    let x = map(|&x| x + 2, vec![1u,2,3].iter());
    println!("{}", x);
}

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (060e47f74 2022-08-23)
binary: rustc
commit-hash: 060e47f74a91b28c3db28d80a6a9d6841ca51026
commit-date: 2022-08-23
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0

Error output

rustc ./20108.rs -Zunpretty=hir

error: expected type, found `|`
 --> ./20108.rs:3:35
  |
3 | fn map<T, U, I: Iterator<T>>(fun: |T| -> U, mut iter: I) -> Vec<U> {
  |                                   ^ expected type

error: invalid suffix `u` for number literal
  --> ./20108.rs:12:34
   |
12 |     let x = map(|&x| x + 2, vec![1u,2,3].iter());
   |                                  ^^ invalid suffix `u`
   |
   = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)

error[E0425]: cannot find function `fun` in this scope
 --> ./20108.rs:6:18
  |
6 |         acc.push(fun(elt));
  |                  ^^^ not found in this scope
Backtrace

``` thread 'rustc' panicked at 'internal error: entered unreachable code', compiler/rustc_ast/src/util/literal.rs:202:29 stack backtrace: 0: 0x7f729b6cc750 - std::backtrace_rs::backtrace::libunwind::trace::h18bb8883b170e61e at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 1: 0x7f729b6cc750 - std::backtrace_rs::backtrace::trace_unsynchronized::hfbfd04778228f53a at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f729b6cc750 - std::sys_common::backtrace::_print_fmt::hf014d9c7ceb4c50b at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/sys_common/backtrace.rs:66:5 3: 0x7f729b6cc750 - ::fmt::h0cff30d852e41e28 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/sys_common/backtrace.rs:45:22 4: 0x7f729b727a5e - core::fmt::write::hf3278c297bc3e8c3 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/core/src/fmt/mod.rs:1202:17 5: 0x7f729b6bd4d5 - std::io::Write::write_fmt::hb3fb7e9de918605f at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/io/mod.rs:1672:15 6: 0x7f729b6cf413 - std::sys_common::backtrace::_print::hb735a2b0aa8c9126 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/sys_common/backtrace.rs:48:5 7: 0x7f729b6cf413 - std::sys_common::backtrace::print::h1d481f5d3b90ee64 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/sys_common/backtrace.rs:35:9 8: 0x7f729b6cf413 - std::panicking::default_hook::{{closure}}::h3cda275262afb117 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/panicking.rs:295:22 9: 0x7f729b6cf0ff - std::panicking::default_hook::h2eba6d64b7e32862 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/panicking.rs:314:9 10: 0x7f729df1d4e4 - >::call_once::{shim:vtable#0} 11: 0x7f729b6cfc4d - std::panicking::rust_panic_with_hook::hfaad0ec4972467c1 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/panicking.rs:702:17 12: 0x7f729b6cfa61 - std::panicking::begin_panic_handler::{{closure}}::h401c5684148433ac at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/panicking.rs:586:13 13: 0x7f729b6ccc5c - std::sys_common::backtrace::__rust_end_short_backtrace::h356ecf2a7ec67271 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/sys_common/backtrace.rs:138:18 14: 0x7f729b6cf7c2 - rust_begin_unwind at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/panicking.rs:584:5 15: 0x7f729b724573 - core::panicking::panic_fmt::h9555dfef52eae25e at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/core/src/panicking.rs:142:14 16: 0x7f729b7243bd - core::panicking::panic::hbe0e36c7510ee8e3 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/core/src/panicking.rs:48:5 17: 0x7f729cf37d8f - ::to_token_lit 18: 0x7f729cf34601 - ::print_expr 19: 0x7f729cf381fc - ::commasep_cmnt::::commasep_exprs::{closure#0}, ::commasep_exprs::{closure#1}> 20: 0x7f729cf349a9 - ::print_expr 21: 0x7f729cf35a8d - ::print_expr 22: 0x7f729cf381fc - ::commasep_cmnt::::commasep_exprs::{closure#0}, ::commasep_exprs::{closure#1}> 23: 0x7f729cf348c0 - ::print_expr 24: 0x7f729cf3543b - ::print_expr 25: 0x7f729cf381fc - ::commasep_cmnt::::commasep_exprs::{closure#0}, ::commasep_exprs::{closure#1}> 26: 0x7f729cf348c0 - ::print_expr 27: 0x7f729cf3b16f - ::print_stmt 28: 0x7f729cf3a755 - ::print_block_maybe_unclosed 29: 0x7f729cf34cd4 - ::print_expr 30: 0x7f729df13b44 - ::nested 31: 0x7f729d9ac6b6 - ::print_item 32: 0x7f729df13b44 - ::nested 33: 0x7f729eb4fe3d - ::print_mod 34: 0x7f729eb4f52e - rustc_hir_pretty[541b7d9012655fc5]::print_crate 35: 0x7f729df16e70 - rustc_driver[b627559a5a77e284]::pretty::print_after_hir_lowering::{closure#1} 36: 0x7f729df16741 - rustc_driver[b627559a5a77e284]::pretty::print_after_hir_lowering 37: 0x7f729defa1ca - ::enter::> 38: 0x7f729d7d554f - ::enter::, rustc_errors[96dfb46f0b8980b]::ErrorGuaranteed>> 39: 0x7f729d7d0d5c - rustc_span[bead5e57778f0b1b]::with_source_map::, rustc_interface[bf5d5e33b83f0123]::interface::create_compiler_and_run, rustc_driver[b627559a5a77e284]::run_compiler::{closure#1}>::{closure#1}> 40: 0x7f729d7d07d2 - rustc_interface[bf5d5e33b83f0123]::interface::create_compiler_and_run::, rustc_driver[b627559a5a77e284]::run_compiler::{closure#1}> 41: 0x7f729d7cf2c1 - >::set::, rustc_driver[b627559a5a77e284]::run_compiler::{closure#1}>::{closure#0}, core[e3f13d716672aa]::result::Result<(), rustc_errors[96dfb46f0b8980b]::ErrorGuaranteed>> 42: 0x7f729d7cefaf - std[bb5449232b08fe6e]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver[b627559a5a77e284]::run_compiler::{closure#1}>::{closure#0}, core[e3f13d716672aa]::result::Result<(), rustc_errors[96dfb46f0b8980b]::ErrorGuaranteed>>::{closure#0}, core[e3f13d716672aa]::result::Result<(), rustc_errors[96dfb46f0b8980b]::ErrorGuaranteed>> 43: 0x7f729dd3c059 - <::spawn_unchecked_, rustc_driver[b627559a5a77e284]::run_compiler::{closure#1}>::{closure#0}, core[e3f13d716672aa]::result::Result<(), rustc_errors[96dfb46f0b8980b]::ErrorGuaranteed>>::{closure#0}, core[e3f13d716672aa]::result::Result<(), rustc_errors[96dfb46f0b8980b]::ErrorGuaranteed>>::{closure#1} as core[e3f13d716672aa]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 44: 0x7f729b6d97a3 - as core::ops::function::FnOnce>::call_once::hd8b4f77c73b6de54 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/alloc/src/boxed.rs:1940:9 45: 0x7f729b6d97a3 - as core::ops::function::FnOnce>::call_once::h396dcf115ad932d5 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/alloc/src/boxed.rs:1940:9 46: 0x7f729b6d97a3 - std::sys::unix::thread::Thread::new::thread_start::h004395cd09d806b0 at /rustc/060e47f74a91b28c3db28d80a6a9d6841ca51026/library/std/src/sys/unix/thread.rs:108:17 47: 0x7f729b43778d - 48: 0x7f729b4b88e4 - clone 49: 0x0 - 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.65.0-nightly (060e47f74 2022-08-23) running on x86_64-unknown-linux-gnu note: compiler flags: -Z unpretty=hir query stack during panic: end of query stack error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0425`. ```

matthiaskrgr commented 2 years ago

Reduced:

fn main() {
    1u;
}
TaKO8Ki commented 2 years ago

Regression in a1bea1551b8312b6abfbbf7d49bafac2e6ce8ee4

matthiaskrgr commented 2 years ago

The assert was added in https://github.com/rust-lang/rust/pull/100907

I MENT https://github.com/rust-lang/rust/pull/100909 (sorry, I should no do this on the phone... :roll_eyes: ) cc @nnethercote