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 Subslice unexpected because it isn't captured --edition=2021 #109298

Closed
matthiaskrgr opened this issue Mar 18, 2023 · 9 comments · Fixed by #109680
Closed

ICE Subslice unexpected because it isn't captured --edition=2021 #109298

matthiaskrgr opened this issue Mar 18, 2023 · 9 comments · Fixed by #109680
Assignees
Labels
A-edition-2021 Area: The 2021 edition C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Mar 18, 2023

Code

#![crate_type="lib"]
fn arr_by_ref(mut x: [(); 3]) {
    let f = || {
        let [ref y, ref mut z @ ..] = x;
    };    
    f();
}

Meta

rustc --version --verbose:

rustc 1.70.0-nightly (13afbdaa0 2023-03-17)
binary: rustc
commit-hash: 13afbdaa0655dda23d7129e59ac48f1ec88b2084
commit-date: 2023-03-17
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

Error output

rustc file.rs --edition=2021


Backtrace

```warning: unused variable: y
--> treereduce.out:4:18
|
4 | let [ref y, ref mut z @ ..] = x;
| ^ help: if this is intentional, prefix it with an underscore: `_y`
|
= note: `#[warn(unused_variables)]` on by default

warning: unused variable: z
--> treereduce.out:4:29
|
4 | let [ref y, ref mut z @ ..] = x;
| ^ help: if this is intentional, prefix it with an underscore: _z

error: internal compiler error: compiler/rustc_middle/src/ty/closure.rs:372:21: Subslice unexpected because it isn't captured

thread 'rustc' panicked at 'Box', /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/compiler/rustc_errors/src/lib.rs:1644:9
stack backtrace:
0: 0x7f177a96739a - std::backtrace_rs::backtrace::libunwind::trace::h84d2711f38e4d049
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
1: 0x7f177a96739a - std::backtrace_rs::backtrace::trace_unsynchronized::h07f6ebc5344709db
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x7f177a96739a - std::sys_common::backtrace::_print_fmt::h05a29271ab24b307
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/std/src/sys_common/backtrace.rs:65:5
3: 0x7f177a96739a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2badcaa62266c6d2
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/std/src/sys_common/backtrace.rs:44:22
4: 0x7f177a9ca9be - core::fmt::write::h029bd029dcf67de1
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/core/src/fmt/mod.rs:1254:17
5: 0x7f177a95a225 - std::io::Write::write_fmt::h80e1934b9bd451b8
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/std/src/io/mod.rs:1684:15
6: 0x7f177a967165 - std::sys_common::backtrace::_print::hd15e10f9274c89b0
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/std/src/sys_common/backtrace.rs:47:5
7: 0x7f177a967165 - std::sys_common::backtrace::print::h170965e4e66b5ee4
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/std/src/sys_common/backtrace.rs:34:9
8: 0x7f177a969edf - std::panicking::default_hook::{{closure}}::h0164004bb09e0366
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/std/src/panicking.rs:271:22
9: 0x7f177a969c1b - std::panicking::default_hook::h5e2940911ec5582f
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/std/src/panicking.rs:290:9
10: 0x7f177dbf2415 - rustc_driver_impl[bad2ed848d64dbdc]::DEFAULT_HOOK::{closure#0}::{closure#0}
11: 0x7f177a96a71d - <alloc::boxed::Box<F,A> as core::ops::function::Fn>::call::h0f3cc38fa49d6ba4
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/alloc/src/boxed.rs:2002:9
12: 0x7f177a96a71d - std::panicking::rust_panic_with_hook::h591d1df500c4db69
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/std/src/panicking.rs:696:13
13: 0x7f177e12aef1 - std[b4247acdb72724ff]::panicking::begin_panic::<rustc_errors[48bb1377a0478866]::ExplicitBug>::{closure#0}
14: 0x7f177e128996 - std[b4247acdb72724ff]::sys_common::backtrace::__rust_end_short_backtrace::<std[b4247acdb72724ff]::panicking::begin_panic<rustc_errors[48bb1377a0478866]::ExplicitBug>::{closure#0}, !>
15: 0x7f177e13ec96 - std[b4247acdb72724ff]::panicking::begin_panic::<rustc_errors[48bb1377a0478866]::ExplicitBug>
16: 0x7f177e1a10d6 - std[b4247acdb72724ff]::panic::panic_any::<rustc_errors[48bb1377a0478866]::ExplicitBug>
17: 0x7f177e19e896 - <rustc_errors[48bb1377a0478866]::HandlerInner>::bug::<&alloc[c5857ad37805d36e]::string::String>
18: 0x7f177e19e560 - <rustc_errors[48bb1377a0478866]::Handler>::bug::<&alloc[c5857ad37805d36e]::string::String>
19: 0x7f177e19684b - rustc_middle[eaf6378de1cdbfa8]::util::bug::opt_span_bug_fmt::<rustc_span[4d522547309d7b79]::span_encoding::Span>::{closure#0}
20: 0x7f177e19529a - rustc_middle[eaf6378de1cdbfa8]::ty::context::tls::with_opt::<rustc_middle[eaf6378de1cdbfa8]::util::bug::opt_span_bug_fmt<rustc_span[4d522547309d7b79]::span_encoding::Span>::{closure#0}, !>::{closure#0}
21: 0x7f177e195266 - rustc_middle[eaf6378de1cdbfa8]::ty::context::tls::with_context_opt::<rustc_middle[eaf6378de1cdbfa8]::ty::context::tls::with_opt<rustc_middle[eaf6378de1cdbfa8]::util::bug::opt_span_bug_fmt<rustc_span[4d522547309d7b79]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
22: 0x7f177e196796 - rustc_middle[eaf6378de1cdbfa8]::util::bug::opt_span_bug_fmt::<rustc_span[4d522547309d7b79]::span_encoding::Span>
23: 0x7f177c2874e3 - rustc_middle[eaf6378de1cdbfa8]::util::bug::bug_fmt
24: 0x7f177e1ab891 - rustc_middle[eaf6378de1cdbfa8]::ty::closure::place_to_string_for_capture
25: 0x7f177d8f01fa - <rustc_borrowck[3b5de70414a05ac6]::MirBorrowckCtxt>::show_mutating_upvar
26: 0x7f177c5a35a8 - <rustc_borrowck[3b5de70414a05ac6]::MirBorrowckCtxt>::report_mutability_error
27: 0x7f177c59baaf - <rustc_borrowck[3b5de70414a05ac6]::MirBorrowckCtxt>::access_place
28: 0x7f177c58707c - <rustc_borrowck[3b5de70414a05ac6]::MirBorrowckCtxt as rustc_mir_dataflow[60696dcf57ac1f12]::framework::visitor::ResultsVisitor>::visit_statement_before_primary_effect
29: 0x7f177c9829de - rustc_mir_dataflow[60696dcf57ac1f12]::framework::visitor::visit_results::<rustc_borrowck[3b5de70414a05ac6]::dataflow::BorrowckAnalyses<rustc_index[f2328b8185c300]::bit_set::BitSet<rustc_borrowck[3b5de70414a05ac6]::dataflow::BorrowIndex>, rustc_index[f2328b8185c300]::bit_set::ChunkedBitSet<rustc_mir_dataflow[60696dcf57ac1f12]::move_paths::MovePathIndex>, rustc_index[f2328b8185c300]::bit_set::ChunkedBitSet<rustc_mir_dataflow[60696dcf57ac1f12]::move_paths::InitIndex>>, rustc_borrowck[3b5de70414a05ac6]::dataflow::BorrowckAnalyses<rustc_mir_dataflow[60696dcf57ac1f12]::framework::engine::Results<rustc_borrowck[3b5de70414a05ac6]::dataflow::Borrows>, rustc_mir_dataflow[60696dcf57ac1f12]::framework::engine::Results<rustc_mir_dataflow[60696dcf57ac1f12]::impls::MaybeUninitializedPlaces>, rustc_mir_dataflow[60696dcf57ac1f12]::framework::engine::Results<rustc_mir_dataflow[60696dcf57ac1f12]::impls::EverInitializedPlaces>>, core[9847d4a2e8a02df2]::iter::adapters::map::Map<rustc_middle[eaf6378de1cdbfa8]::mir::traversal::ReversePostorderIter, rustc_borrowck[3b5de70414a05ac6]::do_mir_borrowck::{closure#2}>, rustc_borrowck[3b5de70414a05ac6]::MirBorrowckCtxt>
30: 0x7f177c933632 - rustc_borrowck[3b5de70414a05ac6]::do_mir_borrowck
31: 0x7f177c92c2be - rustc_borrowck[3b5de70414a05ac6]::mir_borrowck
32: 0x7f177cb8d296 - rustc_query_system[3b264ab6e948b942]::query::plumbing::try_execute_query::<rustc_query_impl[1cc93b35ef872c79]::queries::mir_borrowck, rustc_query_impl[1cc93b35ef872c79]::plumbing::QueryCtxt>
33: 0x7f177bf473b2 - rustc_data_structures[8426954b093953dd]::sync::par_for_each_in::<&[rustc_span[4d522547309d7b79]::def_id::LocalDefId], <rustc_middle[eaf6378de1cdbfa8]::hir::map::Map>::par_body_owners<rustc_interface[dde792dfc5bb5edd]::passes::analysis::{closure#2}::{closure#0}>::{closure#0}>
34: 0x7f177bf46fde - <rustc_session[8656a7a78cf578e4]::session::Session>::time::<(), rustc_interface[dde792dfc5bb5edd]::passes::analysis::{closure#2}>
35: 0x7f177bf46780 - rustc_interface[dde792dfc5bb5edd]::passes::analysis
36: 0x7f177d411aec - rustc_query_system[3b264ab6e948b942]::query::plumbing::try_execute_query::<rustc_query_impl[1cc93b35ef872c79]::queries::analysis, rustc_query_impl[1cc93b35ef872c79]::plumbing::QueryCtxt>
37: 0x7f177d4117e0 - <rustc_query_impl[1cc93b35ef872c79]::Queries as rustc_middle[eaf6378de1cdbfa8]::ty::query::QueryEngine>::analysis
38: 0x7f177d26e109 - <rustc_middle[eaf6378de1cdbfa8]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[bad2ed848d64dbdc]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[9847d4a2e8a02df2]::result::Result<(), rustc_span[4d522547309d7b79]::ErrorGuaranteed>>
39: 0x7f177cdf852d - <rustc_interface[dde792dfc5bb5edd]::interface::Compiler>::enter::<rustc_driver_impl[bad2ed848d64dbdc]::run_compiler::{closure#1}::{closure#2}, core[9847d4a2e8a02df2]::result::Result<core[9847d4a2e8a02df2]::option::Option<rustc_interface[dde792dfc5bb5edd]::queries::Linker>, rustc_span[4d522547309d7b79]::ErrorGuaranteed>>
40: 0x7f177cdf6630 - rustc_span[4d522547309d7b79]::with_source_map::<core[9847d4a2e8a02df2]::result::Result<(), rustc_span[4d522547309d7b79]::ErrorGuaranteed>, rustc_interface[dde792dfc5bb5edd]::interface::run_compiler<core[9847d4a2e8a02df2]::result::Result<(), rustc_span[4d522547309d7b79]::ErrorGuaranteed>, rustc_driver_impl[bad2ed848d64dbdc]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
41: 0x7f177cdf5bd9 - std[b4247acdb72724ff]::sys_common::backtrace::_rust_begin_short_backtrace::<rustc_interface[dde792dfc5bb5edd]::util::run_in_thread_pool_with_globals<rustc_interface[dde792dfc5bb5edd]::interface::run_compiler<core[9847d4a2e8a02df2]::result::Result<(), rustc_span[4d522547309d7b79]::ErrorGuaranteed>, rustc_driver_impl[bad2ed848d64dbdc]::run_compiler::{closure#1}>::{closure#0}, core[9847d4a2e8a02df2]::result::Result<(), rustc_span[4d522547309d7b79]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9847d4a2e8a02df2]::result::Result<(), rustc_span[4d522547309d7b79]::ErrorGuaranteed>>
42: 0x7f177d4e6afa - <<std[b4247acdb72724ff]::thread::Builder>::spawn_unchecked
<rustc_interface[dde792dfc5bb5edd]::util::run_in_thread_pool_with_globals<rustc_interface[dde792dfc5bb5edd]::interface::run_compiler<core[9847d4a2e8a02df2]::result::Result<(), rustc_span[4d522547309d7b79]::ErrorGuaranteed>, rustc_driver_impl[bad2ed848d64dbdc]::run_compiler::{closure#1}>::{closure#0}, core[9847d4a2e8a02df2]::result::Result<(), rustc_span[4d522547309d7b79]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9847d4a2e8a02df2]::result::Result<(), rustc_span[4d522547309d7b79]::ErrorGuaranteed>>::{closure#1} as core[9847d4a2e8a02df2]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
43: 0x7f177a9745f3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce>::call_once::h51bca2043facf7d3
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/alloc/src/boxed.rs:1988:9
44: 0x7f177a9745f3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce>::call_once::h365da710d54db7ab
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/alloc/src/boxed.rs:1988:9
45: 0x7f177a9745f3 - std::sys::unix::thread::Thread::new::thread_start::hb322f3a535acf0fe
at /rustc/13afbdaa0655dda23d7129e59ac48f1ec88b2084/library/std/src/sys/unix/thread.rs:108:17
46: 0x7f177a706bb5 -
47: 0x7f177a788d90 -
48: 0x0 -

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.70.0-nightly (13afbda 2023-03-17) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking arr_by_ref
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 2 warnings emitted


</p>
</details>


<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"clubby789"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->
@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. A-edition-2021 Area: The 2021 edition labels Mar 18, 2023
@Noratrieb
Copy link
Member

Probably fixed by #108705 (@clubby789)

@matthiaskrgr
Copy link
Member Author

searched nightlies: from nightly-2022-12-30 to nightly-2023-03-18
regressed nightly: nightly-2023-01-01
searched commit range: ce85c98...574b64a
regressed commit: 247e44e

bisected with cargo-bisect-rustc v0.6.5

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

cargo bisect-rustc --script=/home/matthias/vcs/github/rust_bisect/script.sh --test-dir=/home/matthias/vcs/github/rust_bisect/foo

Regression in rust-lang-ci@e3e79ed

same as #109297 ..?

@Noratrieb
Copy link
Member

You should update your cargo-bisect-rustc version to make it bisect the contents of rollups as well^^

@matthiaskrgr
Copy link
Member Author

I already have the git version installed :o

@matthiaskrgr
Copy link
Member Author

Note that we don't have the artifacts for all rollups. I think it requires a perf bisection to be run on the pr or something?

@matthiaskrgr
Copy link
Member Author

Regression in nightly-2021-09-01

found 9 bors merge commits in the specified range
  commit[0] 2021-08-30UTC: Auto merge of #88466 - sexxi-goose:issue-88372, r=nikomatsakis
  commit[1] 2021-08-30UTC: Auto merge of #88369 - lcnr:cec-rename, r=oli-obk
  commit[2] 2021-08-31UTC: Auto merge of #88100 - HTG-YT:edition2021-compopt-stabilization, r=m-ou-se
  commit[3] 2021-08-31UTC: Auto merge of #88414 - Aaron1011:guess-foreign-head-span, r=estebank
  commit[4] 2021-08-31UTC: Auto merge of #88467 - sexxi-goose:issue-88431, r=nikomatsakis
  commit[5] 2021-08-31UTC: Auto merge of #88491 - RalfJung:miri, r=RalfJung
  commit[6] 2021-08-31UTC: Auto merge of #88527 - m-ou-se:rollup-az6xtc5, r=m-ou-se
  commit[7] 2021-08-31UTC: Auto merge of #88535 - m-ou-se:rollup-jeusxbo, r=m-ou-se
  commit[8] 2021-08-31UTC: Auto merge of #88506 - Mark-Simulacrum:fix-rlibs, r=ehuss
ERROR: no CI builds available between 5d6804469d80aaf26f98090ae016af45e267f58f and 29ef6cf1637aa8317f8911f93f14e18d404c1b0e within last 167 days

@Noratrieb
Copy link
Member

Ah, the rollup predates unrolled builds.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 21, 2023
@clubby789
Copy link
Contributor

clubby789 commented Mar 27, 2023

I think this is a different issue, it's not fixed by that PR anyway. I'll try and investigate anyway

@rustbot claim


The ICE occurs while trying to report this error

error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
 --> poc.rs:6:5
  |
4 |         let [ref y, ref mut z @ ..] = x;
  |                                       - calling `f` requires mutable binding due to mutable borrow of `x`
5 |     };
6 |     f();
  |     ^ cannot borrow as mutable
  |
help: consider changing this to be mutable
  |
3 |     let mut f = || {
  |     

Changing to let [ref mut b @ ..] = x; fails earlier: compiler/rustc_middle/src/ty/closure.rs:178:25: Unexpected projection Subslice in captured place

@clubby789
Copy link
Contributor

Actually this can be reduced further -

pub fn capture_slice(x: [u8; 3]) {
    || {
        let [_x @ ..] = x;
    };
}

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. glacier ICE tracked in rust-lang/glacier. 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.

4 participants