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: error with const in 2021 closure capture #87988

Closed
ehuss opened this issue Aug 12, 2021 · 1 comment · Fixed by #87996
Closed

ICE: error with const in 2021 closure capture #87988

ehuss opened this issue Aug 12, 2021 · 1 comment · Fixed by #87996
Assignees
Labels
A-closures Area: Closures (`|…| { … }`) A-edition-2021 Area: The 2021 edition 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.

Comments

@ehuss
Copy link
Contributor

ehuss commented Aug 12, 2021

The following ICE was found migrating rusb 0.8.1 to 2021. I believe it (or something similar) was found in object 0.26.0 and curl 0.4.38.

cc #87426 which was an error on the same line, though I think the cause is slightly different.

Note that I think this is also triggering an incorrect unsued lint for the event parameter (the actual code uses the parameter).

Code

const LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED: i32 = 0x01;
const LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT: i32 = 0x02;

pub fn hotplug_callback(event: i32) {
    let _ = || {
        match event {
            LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED => (),
            LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT => (),
            _ => (),
        };
    };
}

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (ccffcafd5 2021-08-11)
binary: rustc
commit-hash: ccffcafd55e58f769d4b0efc0064bf65e76998e4
commit-date: 2021-08-11
host: x86_64-apple-darwin
release: 1.56.0-nightly
LLVM version: 12.0.1

Error output

warning: unused variable: `event`
 --> src/lib.rs:4:25
  |
4 | pub fn hotplug_callback(event: i32) {
  |                         ^^^^^ help: if this is intentional, prefix it with an underscore: `_event`
  |
  = 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
Backtrace

stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   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::expr::as_temp::<impl rustc_mir_build::build::Builder>::as_temp_inner
  10: rustc_mir_build::build::expr::stmt::<impl rustc_mir_build::build::Builder>::stmt_expr
  11: rustc_mir_build::build::expr::stmt::<impl rustc_mir_build::build::Builder>::stmt_expr
  12: rustc_mir_build::build::block::<impl rustc_mir_build::build::Builder>::ast_block_stmts
  13: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  14: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  15: rustc_data_structures::stack::ensure_sufficient_stack
  16: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  17: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  18: rustc_data_structures::stack::ensure_sufficient_stack
  19: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  20: rustc_mir_build::build::construct_fn
  21: rustc_infer::infer::InferCtxtBuilder::enter
  22: rustc_mir_build::build::mir_built
  23: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  24: rustc_data_structures::stack::ensure_sufficient_stack
  25: rustc_query_system::query::plumbing::get_query_impl
  26: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_built
  27: rustc_mir::transform::check_unsafety::unsafety_check_result
  28: core::ops::function::FnOnce::call_once
  29: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  30: rustc_data_structures::stack::ensure_sufficient_stack
  31: rustc_query_system::query::plumbing::force_query_with_job
  32: rustc_query_system::query::plumbing::get_query_impl
  33: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::unsafety_check_result
  34: <rustc_mir::transform::check_unsafety::UnsafetyChecker as rustc_middle::mir::visit::Visitor>::visit_rvalue
  35: rustc_mir::transform::check_unsafety::unsafety_check_result
  36: core::ops::function::FnOnce::call_once
  37: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  38: rustc_data_structures::stack::ensure_sufficient_stack
  39: rustc_query_system::query::plumbing::force_query_with_job
  40: rustc_query_system::query::plumbing::get_query_impl
  41: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::unsafety_check_result
  42: rustc_mir::transform::mir_const
  43: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  44: rustc_data_structures::stack::ensure_sufficient_stack
  45: rustc_query_system::query::plumbing::get_query_impl
  46: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_const
  47: rustc_mir::transform::mir_promoted
  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_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_promoted
  52: rustc_mir::borrow_check::mir_borrowck
  53: core::ops::function::FnOnce::call_once
  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::force_query_with_job
  57: rustc_query_system::query::plumbing::get_query_impl
  58: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  59: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  60: rustc_interface::passes::analysis
  61: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  62: rustc_data_structures::stack::ensure_sufficient_stack
  63: rustc_query_system::query::plumbing::force_query_with_job
  64: rustc_query_system::query::plumbing::get_query_impl
  65: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  66: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  67: rustc_span::with_source_map
  68: rustc_interface::interface::create_compiler_and_run
  69: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.56.0-nightly (ccffcafd5 2021-08-11) running on x86_64-apple-darwin

note: compiler flags: -Z unstable-options -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type lib

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

query stack during panic:
#0 [mir_built] building MIR for `hotplug_callback::{closure#0}`
#1 [unsafety_check_result] unsafety-checking `hotplug_callback::{closure#0}`
#2 [unsafety_check_result] unsafety-checking `hotplug_callback`
#3 [mir_const] processing MIR for `hotplug_callback`
#4 [mir_promoted] processing `hotplug_callback`
#5 [mir_borrowck] borrow-checking `hotplug_callback`
#6 [analysis] running analysis passes on this crate
end of query stack

cc @rust-lang/wg-rfc-2229

@ehuss ehuss added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-closures Area: Closures (`|…| { … }`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-edition-2021 Area: The 2021 edition labels Aug 12, 2021
@roxelo
Copy link
Member

roxelo commented Aug 13, 2021

@rustbot claim

camsteffen added a commit to camsteffen/rust that referenced this issue Aug 19, 2021
RFC2229 Add missing edge case

Closes rust-lang#87988

This PR fixes an ICE where a match discriminant is not being read when expected. This ICE was the result of a missing edge case which assumed that if a pattern is of type `PatKind::TupleStruct(..) | PatKind::Path(..) | PatKind::Struct(..) | PatKind::Tuple(..)` then a place could only be a multi variant if the place is of type kind Adt.
@bors bors closed this as completed in ebedfed Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-edition-2021 Area: The 2021 edition 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants