-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Borrow checking fails in case a closure appears in a const expression #81899
Comments
FWIW, replacing the function body with const CACHE: &[u32] = &const_sort(&[2, 3, 1], |a, b| a < b); // that line is a failure reason
const fn const_sort<F, const N: usize>(v: &[u32; N], mut is_less: F) -> [u32; N]
where
F: FnMut(&u32, &u32) -> bool,
{
todo!()
} |
Minimized slightly further, without const generics: const _CONST: &[u8] = &f(&[], |_| {});
const fn f<F>(_: &[u8], _: F) -> &[u8]
where
F: FnMut(&u8),
{
panic!()
} backtrace
The ICE occurs back to
By making small changes such as making the closure no longer take paramters or removing the reference at - const _CONST: &[u8] = &f(&[], |_| {});
+ const _CONST: &[u8] = f(&[], |_| {}); It errors, instead of an ICE, on stable
|
searched nightlies: from nightly-2020-08-16 to nightly-2021-02-03 edit: for this #81899 (comment) code sample bisected with cargo-bisect-rustc v0.6.0Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --test-dir=/home/matthias/vcs/github/rust_bisect/foo --start=2020-08-16 --end=2021-02-03 |
cc @lcnr |
Just to clarify, AFAICT, this issue is not due to #79135, the |
Assigning |
Issue: rust-lang/rust#81899
I'm not sure if this is identical problem or not. The error message is:
and my code is:
I need both parts or the COPY tuple for the error to trigger and I'm unsure why. And also, if I put |
Triage: No longer ICE with the latest nightly, I guess #87795 fixed it? Marking as |
…askrgr Rollup of 6 pull requests Successful merges: - rust-lang#95214 (Remove impossible panic note from `Vec::append`) - rust-lang#97411 (Print stderr consistently) - rust-lang#97453 (rename `TyKind` to `RegionKind` in comment in rustc_middle) - rust-lang#97457 (Add regression test for rust-lang#81899) - rust-lang#97458 (Modify `derive(Debug)` to use `Self` in struct literal to avoid redundant error) - rust-lang#97462 (Add more eslint rules) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The following code causes compiler panics due to the first line without which the issue isn't reproducible. Calling the function outside of a constant context emits the right compiler errors.
Code
Meta
rustc --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: