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 during migration to Rust 2021, crate: stm32h7xx-hal #87426

Closed
hargoniX opened this issue Jul 24, 2021 · 3 comments · Fixed by #87554
Closed

ICE during migration to Rust 2021, crate: stm32h7xx-hal #87426

hargoniX opened this issue Jul 24, 2021 · 3 comments · Fixed by #87554
Assignees
Labels
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) ❄️ 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

@hargoniX
Copy link
Member

hargoniX commented Jul 24, 2021

Code

Regarding a minimal example I am afraid I'm not quite able to provide one, this bug occured when i was migrating
https://github.com/stm32-rs/stm32h7xx-hal to Rust 2021 as part of the testing efforts. The branch/PR with the
Rust 2021 modifications can be found here stm32-rs/stm32h7xx-hal#236. I did cfgment all
modules except the ones that are required to trigger the bug out: https://github.com/stm32-rs/stm32h7xx-hal/blob/rust2021/src/lib.rs#L250-L253. And removed most code and modules from the rcc module: https://github.com/stm32-rs/stm32h7xx-hal/blob/rust2021/src/rcc/mod.rs#L144-L155, nailing the bug down to src/rcc/pll.rs (as the error message suggested). Then i minized further in pll.rs (its 200 lines now, the rest is just tests) And I was in fact able to pin point the panic to this piece of code:
https://github.com/stm32-rs/stm32h7xx-hal/blob/rust2021/src/rcc/pll.rs#L95-L104, if I comment it out the ICE doesn't occur anymore so I would guess that this is what the compiler is having issues with.

Meta

rustc --version --verbose:

rustc 1.55.0-nightly (67b03007c 2021-07-23)
binary: rustc
commit-hash: 67b03007cf40f2331892d5b0f65d2917ac3603d5
commit-date: 2021-07-23
host: x86_64-unknown-linux-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1

Error output

Compilation command I used was: cargo +nightly build --features=rt,stm32h743

<warnings about unused variables because of my minimization>

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 (67b03007c 2021-07-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 -C link-arg=-Tlink.x --crate-type lib

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

query stack during panic:
#0 [mir_built] building MIR for `rcc::pll::<impl at src/rcc/pll.rs:189:1: 199:2>::pll1_setup::{closure#1}`
#1 [unsafety_check_result] unsafety-checking `rcc::pll::<impl at src/rcc/pll.rs:189:1: 199:2>::pll1_setup::{closure#1}`
end of query stack
warning: `stm32h7xx-hal` (lib) generated 5 warnings
error: could not compile `stm32h7xx-hal`; 5 warnings emitted

Backtrace

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_mir_build/src/build/matches/mod.rs:1685:53
stack backtrace:
   0: rust_begin_unwind
             at /rustc/67b03007cf40f2331892d5b0f65d2917ac3603d5/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/67b03007cf40f2331892d5b0f65d2917ac3603d5/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/67b03007cf40f2331892d5b0f65d2917ac3603d5/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::expr::as_temp::<impl rustc_mir_build::build::Builder>::as_temp_inner
  10: rustc_mir_build::build::expr::as_place::<impl rustc_mir_build::build::Builder>::expr_as_place
  11: rustc_mir_build::build::expr::as_place::<impl rustc_mir_build::build::Builder>::expr_as_place
  12: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  13: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  14: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  15: rustc_mir_build::build::block::<impl rustc_mir_build::build::Builder>::ast_block_stmts
  16: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  17: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  18: rustc_mir_build::build::expr::as_temp::<impl rustc_mir_build::build::Builder>::as_temp_inner
  19: rustc_mir_build::build::expr::as_place::<impl rustc_mir_build::build::Builder>::expr_as_place
  20: rustc_mir_build::build::expr::as_place::<impl rustc_mir_build::build::Builder>::expr_as_place
  21: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  22: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  23: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  24: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  25: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  26: rustc_mir_build::build::construct_fn
  27: rustc_infer::infer::InferCtxtBuilder::enter
  28: rustc_mir_build::build::mir_built
  29: rustc_query_system::query::plumbing::get_query_impl
  30: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_built
  31: rustc_mir::transform::check_unsafety::unsafety_check_result
  32: core::ops::function::FnOnce::call_once
  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::query::plumbing::get_query_impl
  37: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_const
  38: rustc_mir::transform::mir_promoted
  39: rustc_query_system::query::plumbing::get_query_impl
  40: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_promoted
  41: rustc_mir::borrow_check::mir_borrowck
  42: core::ops::function::FnOnce::call_once
  43: rustc_query_system::query::plumbing::get_query_impl
  44: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  45: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  46: rustc_interface::passes::analysis
  47: rustc_query_system::query::plumbing::get_query_impl
  48: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  49: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  50: rustc_span::with_source_map
  51: rustc_interface::interface::create_compiler_and_run
  52: 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.55.0-nightly (67b03007c 2021-07-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 -C link-arg=-Tlink.x --crate-type lib

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

query stack during panic:
#0 [mir_built] building MIR for `rcc::pll::<impl at src/rcc/pll.rs:189:1: 199:2>::pll1_setup::{closure#1}`
#1 [unsafety_check_result] unsafety-checking `rcc::pll::<impl at src/rcc/pll.rs:189:1: 199:2>::pll1_setup::{closure#1}`
#2 [mir_const] processing MIR for `rcc::pll::<impl at src/rcc/pll.rs:189:1: 199:2>::pll1_setup::{closure#1}`
#3 [mir_promoted] processing `rcc::pll::<impl at src/rcc/pll.rs:189:1: 199:2>::pll1_setup::{closure#1}`
#4 [mir_borrowck] borrow-checking `rcc::pll::<impl at src/rcc/pll.rs:189:1: 199:2>::pll1_setup::{closure#1}`
#5 [analysis] running analysis passes on this crate
end of query stack

@hargoniX hargoniX 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 24, 2021
@jyn514 jyn514 added A-edition-2021 Area: The 2021 edition requires-nightly This issue requires a nightly compiler in some way. labels Jul 24, 2021
@ehuss
Copy link
Contributor

ehuss commented Jul 24, 2021

Thanks for the report! Here's a somewhat minimized reproduction:

pub fn foo() {
    let ref_x_ck = 123;
    let _y = || match ref_x_ck {
        2_000_000..=3_999_999 => {}
        _ => {}
    };
}

@ehuss
Copy link
Contributor

ehuss commented Jul 24, 2021

cc @rust-lang/wg-rfc-2229

@roxelo
Copy link
Member

roxelo commented Jul 24, 2021

@rustbot claim

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 29, 2021
…matsakis

2229: Discr should be read when PatKind is Range

This PR fixes an issue related to pattern matching in closures when Edition 2021 is enabled.

- If any of the patterns the discr is being matched on is `PatKind::Range` then the discr should be read

r? `@nikomatsakis`

Closes rust-lang#87426
fee1-dead added a commit to fee1-dead-contrib/rust that referenced this issue Jul 29, 2021
…matsakis

2229: Discr should be read when PatKind is Range

This PR fixes an issue related to pattern matching in closures when Edition 2021 is enabled.

- If any of the patterns the discr is being matched on is `PatKind::Range` then the discr should be read

r? ``@nikomatsakis``

Closes rust-lang#87426
@bors bors closed this as completed in aaef1a1 Jul 30, 2021
bors bot added a commit to stm32-rs/stm32h7xx-hal that referenced this issue Jan 3, 2022
236: Migrate to Rust 2021 as part of the public testing r=richardeoin a=hargoniX

Migration to Rust 2021 as part of the public testing.

We did actually catch one ICE bug with this \o/: rust-lang/rust#87426

Co-authored-by: Henrik Böving <[email protected]>
Co-authored-by: Richard Meadows <[email protected]>
bors bot added a commit to stm32-rs/stm32h7xx-hal that referenced this issue Jan 3, 2022
236: Migrate to Rust 2021 as part of the public testing r=richardeoin a=hargoniX

Migration to Rust 2021 as part of the public testing.

We did actually catch one ICE bug with this \o/: rust-lang/rust#87426

305: remove release mode requirement from USB examples r=richardeoin a=newAM

This was fixed in usb-device: rust-embedded-community/usb-device#41

Co-authored-by: Henrik Böving <[email protected]>
Co-authored-by: Richard Meadows <[email protected]>
Co-authored-by: Alex Martens <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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) ❄️ 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