Closed
Description
Code
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() {}
Meta
rustc --version --verbose
:
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
Error output
$ 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
Backtrace
stack backtrace:
0: std::panicking::begin_panic
1: rustc_errors::HandlerInner::bug
2: rustc_errors::Handler::bug
3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
4: rustc_middle::ty::context::tls::with_opt::{{closure}}
5: rustc_middle::ty::context::tls::with_opt
6: rustc_middle::util::bug::opt_span_bug_fmt
7: rustc_middle::util::bug::bug_fmt
8: rustc_typeck::check::fn_ctxt::FnCtxt::apply_adjustments
9: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_field
10: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
11: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
12: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
13: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
14: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_coercable_to_type
15: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
16: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
17: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
18: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
19: rustc_typeck::check::_match::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_match
20: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
21: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
22: rustc_typeck::check::fn_ctxt::FnCtxt::check_block_with_expected
23: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
24: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
25: rustc_typeck::check::fn_ctxt::FnCtxt::check_stmt
26: rustc_typeck::check::fn_ctxt::FnCtxt::check_block_with_expected
27: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
28: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
29: rustc_typeck::check::_match::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_match
30: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
31: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
32: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
33: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
34: rustc_typeck::check::fn_ctxt::FnCtxt::check_block_with_expected
35: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
36: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
37: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
38: rustc_typeck::check::check::check_fn
39: rustc_infer::infer::InferCtxtBuilder::enter
40: rustc_typeck::check::typeck
41: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCt
xt> for rustc_middle::ty::query::queries::typeck>::compute
42: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
43: rustc_data_structures::stack::ensure_sufficient_stack
44: rustc_query_system::query::plumbing::get_query_impl
45: rustc_query_system::query::plumbing::ensure_query_impl
46: rustc_typeck::check::typeck_item_bodies
47: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCt
xt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
48: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
49: rustc_data_structures::stack::ensure_sufficient_stack
50: rustc_query_system::query::plumbing::get_query_impl
51: rustc_typeck::check_crate
52: rustc_interface::passes::analysis
53: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCt
xt> for rustc_middle::ty::query::queries::analysis>::compute
54: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
55: rustc_data_structures::stack::ensure_sufficient_stack
56: rustc_query_system::query::plumbing::get_query_impl
57: rustc_interface::passes::QueryContext::enter
58: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
59: rustc_span::with_source_map
60: rustc_interface::interface::create_compiler_and_run
61: scoped_tls::ScopedKey<T>::set