Closed
Description
Code
mod m {
pub struct S { foo: i32 }
impl S {
pub fn foo(&self) -> i32 { 42 }
}
}
fn bar(s: &m::S) {
|| s.foo() + s.foo;
}
fn main() {}
Meta
rustc --version --verbose
:
rustc 1.56.0 (09c42c458 2021-10-18)
binary: rustc
commit-hash: 09c42c45858d5f3aedfa670698275303a3d19afa
commit-date: 2021-10-18
host: x86_64-unknown-linux-gnu
release: 1.56.0
LLVM version: 13.0.0
Also checked beta and nightly at https://play.rust-lang.org:
rustc 1.57.0-beta.2 (7e4c9eebd 2021-10-22) running on x86_64-unknown-linux-gnu
rustc 1.58.0-nightly (ff0e14829 2021-10-31) running on x86_64-unknown-linux-gnu
Error output
error[E0616]: field `foo` of struct `S` is private
--> bug.rs:9:18
|
9 | || s.foo() + s.foo;
| ^^^ private field
|
help: a method `foo` also exists, call it with parentheses
|
9 | || s.foo() + s.foo();
| ++
error: internal compiler error: compiler/rustc_typeck/src/check/upvar.rs:641:30: ProjectionKinds Deref and Field were mismatched: (Field(0, 0), Deref)
thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1147: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.56.0 (09c42c458 2021-10-18) running on x86_64-unknown-linux-gnu
query stack during panic:
#0 [typeck] type-checking `bar`
#1 [typeck] type-checking `bar::{closure#0}`
end of query stack
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0616`.
Backtrace
thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1147:9
stack backtrace:
0: std::panicking::begin_panic
1: std::panic::panic_any
2: rustc_errors::HandlerInner::bug
3: rustc_errors::Handler::bug
4: rustc_middle::ty::context::tls::with_opt
5: rustc_middle::util::bug::opt_span_bug_fmt
6: rustc_middle::util::bug::bug_fmt
7: alloc::slice::<impl [T]>::sort_by::{{closure}}
8: alloc::slice::merge_sort
9: rustc_typeck::check::upvar::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::compute_min_captures
10: rustc_typeck::check::upvar::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::analyze_closure
11: <rustc_typeck::check::upvar::InferBorrowKindVisitor as rustc_hir::intravisit::Visitor>::visit_expr
12: rustc_hir::intravisit::walk_expr
13: <rustc_typeck::check::upvar::InferBorrowKindVisitor as rustc_hir::intravisit::Visitor>::visit_expr
14: rustc_typeck::check::upvar::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::closure_analyze
15: rustc_infer::infer::InferCtxtBuilder::enter
16: rustc_typeck::check::typeck
17: rustc_query_system::query::plumbing::get_query_impl
18: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
19: rustc_typeck::check::typeck
20: rustc_query_system::query::plumbing::get_query_impl
21: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
22: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
23: rustc_typeck::check::typeck_item_bodies
24: rustc_query_system::query::plumbing::get_query_impl
25: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
26: rustc_session::utils::<impl rustc_session::session::Session>::time
27: rustc_typeck::check_crate
28: rustc_interface::passes::analysis
29: rustc_query_system::query::plumbing::get_query_impl
30: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
31: rustc_interface::passes::QueryContext::enter
32: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
33: rustc_span::with_source_map
34: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.