use std::collections::BTreeMap;
// Type aliases to replace complex data types used in the original code.
pub type Data = usize;
pub type Key = String;
pub type DataRef<'c> = &'c Data;
pub struct Storage(BTreeMap<Key, Data>);
impl Storage {
pub fn list<'a>(&'a self, key: &Key) -> Vec<&Data> {
unimplemented!()
}
}
pub struct Cache<'c> {
storage: Storage,
cached_data_refs: BTreeMap<Key, DataRef<'c>>,
}
impl<'c> Cache<'c> {
pub fn data_ref_list<'a>(&'a mut self, key: &Key) {
for reference in self.storage.list(key) {
self.cached_data_refs.insert(key.clone(), reference);
// Following `if` statement is the reason for compiler crash. To trigger the crash it
// is required to:
//
// * have `let` keyword missing from `if let Some(...)` expression
// * have binding name in the `Some(...)` portion of the `if let Some()` shadow the
// name from the outer loop
//
if /*let*/ Some(reference) = self.cached_data_refs.get(key) {
unimplemented!()
}
}
}
}
fn main() {}
rustc 1.48.0-nightly (043f6d747 2020-09-25)
binary: rustc
commit-hash: 043f6d747c15068f0053a0542e9b0f17ae7f4de4
commit-date: 2020-09-25
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0
$ rustc bugtest.rs
error: internal compiler error: compiler/rustc_typeck/src/check/fn_ctxt.rs:459:25: while adjusting Expr { hir_id: HirI
d { owner: DefId(0:20 ~ bugtest[317d]::{{impl}}[1]::data_ref_list[0]), local_id: 70 }, kind: Path(Resolved(None, Path
{ span: bugtest.rs:34:42: 34:46 (#0), res: Local(HirId { owner: DefId(0:20 ~ bugtest[317d]::{{impl}}[1]::data_ref_list
[0]), local_id: 1 }), segments: [PathSegment { ident: self#0, hir_id: Some(HirId { owner: DefId(0:20 ~ bugtest[317d]::
{{impl}}[1]::data_ref_list[0]), local_id: 69 }), res: Some(Local(HirId { owner: DefId(0:20 ~ bugtest[317d]::{{impl}}[1
]::data_ref_list[0]), local_id: 1 })), args: None, infer_args: true }] })), attrs: ThinVec(None), span: bugtest.rs:34:
42: 34:46 (#0) }, can't compose [Deref(None) -> Cache<'c>] and [Deref(None) -> Cache<'c>]
thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:945: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-compil
er&template=ice.md
note: rustc 1.48.0-nightly (043f6d747 2020-09-25) running on x86_64-unknown-linux-gnu
error: aborting due to previous error
Code
Meta
rustc --version --verbose:Error output
Backtrace