Closed
Description
I got this error on my code even though it did not have any print
in it.
Also, it seems to only happen on lib
crates.
Just a cargo check
is enough to reproduce it.
rust playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b2f77ee4a258355673f15d73bd345007
Code
use std::path::Path;
struct A {
pub func: fn(check: bool, a: &Path, b: Option<&Path>),
}
const MY_A: A = A {
func: |check, a, b| {
if check {
let _ = ();
} else if let Some(parent) = b.and_then(|p| p.parent()) {
let _ = ();
}
},
};
Meta
The bug also happens on beta
and nightly
versions of the compiler.
rustc --version --verbose
:
rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-pc-windows-msvc
release: 1.51.0
LLVM version: 11.0.1
Error output
thread 'rustc' panicked at 'print_if saw if with weird alternative', compiler\rustc_hir_pretty\src\lib.rs:1106:25
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 x86_64-pc-windows-msvc
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
Backtrace
N/A