Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typecheck panics feat. a closure and a struct with a private field and a public method #90483

Closed
skatbude opened this issue Nov 1, 2021 · 4 comments · Fixed by #90508
Closed
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@skatbude
Copy link

skatbude commented Nov 1, 2021

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.

@skatbude skatbude added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 1, 2021
@skatbude skatbude changed the title Typecheck panics feat. a closure and a struct with a private field and a public method with the same name Typecheck panics feat. a closure and a struct with a private field and a public method Nov 1, 2021
@SNCPlay42
Copy link
Contributor

This does not panic on 1.55. Also, it panics on 1.56 regardless of which edition is used.

@rustbot label regression-from-stable-to-stable

@rustbot rustbot added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Nov 2, 2021
@SNCPlay42
Copy link
Contributor

searched nightlies: from nightly-2021-07-23 to nightly-2021-11-02
regressed nightly: nightly-2021-09-26
searched commit range: 7342213...addb4da
regressed commit: 6867dd2

bisected with cargo-bisect-rustc v0.6.1

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --preserve --start=2021-07-23 --regress=ice -- check 

From this rollup, #89208 looks relevant, and it landed in 1.56 via backport.

@nbdd0121
Copy link
Contributor

nbdd0121 commented Nov 2, 2021

@rustbot claim

@camelid camelid added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Nov 2, 2021
@camelid
Copy link
Member

camelid commented Nov 2, 2021

Assigning priority as discussed in the prioritization working group.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 6, 2021
Apply adjustments for field expression even if inaccessible

The adjustments are used later by ExprUseVisitor to build Place projections and without adjustments it can produce invalid result.

Fix rust-lang#90483

`@rustbot` label: T-compiler
@bors bors closed this as completed in 4c49db3 Nov 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants