Closed
Description
This code triggers an internal compiler error on rustc 1.54.0:
use anyhow;
async fn main2() {
loop {
let pending: Result<Vec<()>, anyhow::Error> = Ok(vec![]);
match pending {
Ok(vec![]) => {}
Err(e) => {},
}
}
}
Try it on the Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=fba71555b1f83a0975e3722e514826ae
The error is:
error: arbitrary expressions aren't allowed in patterns
--> src/lib.rs:8:16
|
8 | Ok(vec![]) => {}
| ^^^^^^
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error: internal compiler error: compiler/rustc_mir_build/src/thir/pattern/mod.rs:559:22: not a literal: Expr { hir_id: HirId { owner: DefId(0:6 ~ playground[319e]::main2), local_id: 34 }, kind: Call(Expr { hir_id: HirId { owner: DefId(0:6 ~ playground[319e]::main2), local_id: 33 }, kind: Path(TypeRelative(Ty { hir_id: HirId { owner: DefId(0:6 ~ playground[319e]::main2), local_id: 31 }, kind: Path(Resolved(None, Path { span: /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/macros.rs:45:36: 45:52 (#5), res: Def(Struct, DefId(5:6773 ~ alloc[df14]::vec::Vec)), segments: [PathSegment { ident: $crate#5, hir_id: Some(HirId { owner: DefId(0:6 ~ playground[319e]::main2), local_id: 28 }), res: Some(Err), args: None, infer_args: true }, PathSegment { ident: vec#5, hir_id: Some(HirId { owner: DefId(0:6 ~ playground[319e]::main2), local_id: 29 }), res: Some(Def(Mod, DefId(5:5996 ~ alloc[df14]::vec))), args: None, infer_args: true }, PathSegment { ident: Vec#5, hir_id: Some(HirId { owner: DefId(0:6 ~ playground[319e]::main2), local_id: 30 }), res: Some(Err), args: None, infer_args: true }] })), span: /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/macros.rs:45:36: 45:52 (#5) }, PathSegment { ident: new#5, hir_id: Some(HirId { owner: DefId(0:6 ~ playground[319e]::main2), local_id: 32 }), res: Some(Err), args: None, infer_args: true })), span: /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/macros.rs:45:36: 45:57 (#5) }, []), span: /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/alloc/src/macros.rs:45:36: 45:59 (#5) }
--> src/lib.rs:8:16
|
8 | Ok(vec![]) => {}
| ^^^^^^
|
= note: this error: internal compiler error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
thread 'rustc' panicked at 'Box<dyn Any>', /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/compiler/rustc_errors/src/lib.rs:953:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
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.54.0 (a178d0322 2021-07-26) running on x86_64-unknown-linux-gnu
note: compiler flags: -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 --crate-type lib
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [thir_body] building THIR for `main2::{closure#0}`
#1 [mir_built] building MIR for `main2::{closure#0}`
end of query stack
error: aborting due to 2 previous errors
error: could not compile `playground`
To learn more, run the command again with --verbose.