Open
Description
I was going to leave this as a remark on #80384, but you're apparently supposed to make separate issues instead of leaving comments on tracking issues, so here goes:
I was just playing around and couldn't even get past this simple code before getting yelled at:
const fn foo<T, const N: usize>(values: [T; N]) -> [T; N] {
let slice = values.as_slice();
let len = slice.len();
values
}
Both as_slice()
and len()
are declared as const fn
, so you'd think they'd be fine to use in another const fn
, but no:
error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
--> src/lib.rs:2:17
|
2 | let slice = values.as_slice();
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information
I don't even understand what this is trying to tell me. Issue #80384, which is the one linked, does not at all explain the source/cause of this error. I'm not working with UnsafeCell
or interior mutability here. I'm attempting to make a &[T]
from a [T; N]
.