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

ICE with capture_disjoint_fields during match MIR building #87097

Closed
DropDemBits opened this issue Jul 13, 2021 · 4 comments · Fixed by #87161
Closed

ICE with capture_disjoint_fields during match MIR building #87097

DropDemBits opened this issue Jul 13, 2021 · 4 comments · Fixed by #87161
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DropDemBits
Copy link
Contributor

Nightly only, since it depends on the capture_disjoint_fields feature gate.
Without the capture_disjoint_fields feature gate, the code compiles without an ICE.

f5d8117c3 2021-03-16 is the first nightly with the ICE.
Still occurs on the latest nightly (955b9c0d4 2021-07-12 at the time of writing).

Code

#![feature(capture_disjoint_fields)]
  
enum Variant {
    A,
    B,
}

struct A {
    field: Variant,
}

fn main() {
    let here = A { field: Variant::A };
    let out_ref = &here.field;

    || match out_ref {
        Variant::A => (),
        Variant::B => (),
    };
}

ICE still occurs when out_ref is substituted with here.field, e.g.

|| match here.field {
    Variant::A => (),
    Variant::B => (),
};

Meta

rustc +nightly --version --verbose:

rustc 1.55.0-nightly (955b9c0d4 2021-07-12)
binary: rustc
commit-hash: 955b9c0d4cd9176b53f518e01cbe175545c69947
commit-date: 2021-07-12
host: x86_64-unknown-linux-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1

rustc +bisector-ci-f5d8117c338a788bd24abec733fd143dfceb25a0-x86_64-unknown-linux-gnu --version --verbose:

rustc 1.52.0-nightly (f5d8117c3 2021-03-16)
binary: rustc
commit-hash: f5d8117c338a788bd24abec733fd143dfceb25a0
commit-date: 2021-03-16
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 12.0.0

Error output

    Checking ice-2021-07-13-0000 v0.1.0 (/path/to/ice-2021-07-13-0000)
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(capture_disjoint_fields)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information

warning: unused variable: `out_ref`
  --> src/main.rs:14:9
   |
14 |     let out_ref = &here.field;
   |         ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_out_ref`
   |
   = note: `#[warn(unused_variables)]` on by default

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_mir_build/src/build/matches/mod.rs:1685:53
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.55.0-nightly (955b9c0d4 2021-07-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_built] building MIR for `main::{closure#0}`
#1 [unsafety_check_result] unsafety-checking `main::{closure#0}`
end of query stack
warning: 2 warnings emitted

error: could not compile `ice-2021-07-13-0000`
Backtrace

   0: rust_begin_unwind
             at /rustc/955b9c0d4cd9176b53f518e01cbe175545c69947/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/955b9c0d4cd9176b53f518e01cbe175545c69947/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/955b9c0d4cd9176b53f518e01cbe175545c69947/library/core/src/panicking.rs:50:5
   3: rustc_mir_build::build::matches::<impl rustc_mir_build::build::Builder>::bind_and_guard_matched_candidate
   4: rustc_mir_build::build::matches::<impl rustc_mir_build::build::Builder>::bind_pattern
   5: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
   6: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
   7: alloc::vec::source_iter_marker::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter
   8: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
   9: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  10: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  11: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  12: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  13: rustc_mir_build::build::construct_fn
  14: rustc_infer::infer::InferCtxtBuilder::enter
  15: rustc_mir_build::build::mir_built
  16: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  17: rustc_data_structures::stack::ensure_sufficient_stack
  18: rustc_query_system::query::plumbing::get_query_impl
  19: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_built
  20: rustc_mir::transform::check_unsafety::unsafety_check_result
  21: core::ops::function::FnOnce::call_once
  22: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  23: rustc_data_structures::stack::ensure_sufficient_stack
  24: rustc_query_system::query::plumbing::force_query_with_job
  25: rustc_query_system::query::plumbing::get_query_impl
  26: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::unsafety_check_result
  27: <rustc_mir::transform::check_unsafety::UnsafetyChecker as rustc_middle::mir::visit::Visitor>::visit_rvalue
  28: rustc_mir::transform::check_unsafety::unsafety_check_result
  29: core::ops::function::FnOnce::call_once
  30: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  31: rustc_data_structures::stack::ensure_sufficient_stack
  32: rustc_query_system::query::plumbing::force_query_with_job
  33: rustc_query_system::query::plumbing::get_query_impl
  34: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::unsafety_check_result
  35: rustc_mir::transform::mir_const
  36: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  37: rustc_data_structures::stack::ensure_sufficient_stack
  38: rustc_query_system::query::plumbing::get_query_impl
  39: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_const
  40: rustc_mir::transform::mir_promoted
  41: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  42: rustc_data_structures::stack::ensure_sufficient_stack
  43: rustc_query_system::query::plumbing::get_query_impl
  44: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_promoted
  45: rustc_mir::borrow_check::mir_borrowck
  46: core::ops::function::FnOnce::call_once
  47: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  48: rustc_data_structures::stack::ensure_sufficient_stack
  49: rustc_query_system::query::plumbing::force_query_with_job
  50: rustc_query_system::query::plumbing::get_query_impl
  51: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  52: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  53: rustc_interface::passes::analysis
  54: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  55: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  56: rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task
  57: rustc_data_structures::stack::ensure_sufficient_stack
  58: rustc_query_system::query::plumbing::force_query_with_job
  59: rustc_query_system::query::plumbing::get_query_impl
  60: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  61: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  62: rustc_span::with_source_map
  63: rustc_interface::interface::create_compiler_and_run
  64: scoped_tls::ScopedKey<T>::set

@DropDemBits DropDemBits 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 Jul 13, 2021
@jackh726 jackh726 added the requires-nightly This issue requires a nightly compiler in some way. label Jul 14, 2021
@jackh726
Copy link
Member

cc @arora-aman

@arora-aman
Copy link
Member

  • @roxelo can you take a look please

@roxelo
Copy link
Member

roxelo commented Jul 14, 2021

I started looking into the issue and I think it spans from failing to resolve the upvars here when the feature is enabled: try_upvars_resolved fails which leads to the pre_binding_block field of the Candidate to not be assigned as the assignment of this field is being done here

@roxelo
Copy link
Member

roxelo commented Jul 15, 2021

The underlying issue is that currently the compiler does not realize, for the above example, that the discriminant should be read. We incorrectly assumed here that

  1. variants would only be of type Adt when they could be of other types like Ref
  2. that we should be looking at the place.base_ty when we actually want to look at place.ty()

Working on a fix

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) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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.

4 participants