王奕然
王奕然

Reputation: 4059

Compile Error len is not yet stable as a const fn

I get an error from one of my dependencies bytes 0.5.2. Here a code example of the error:

pub const fn foo(foo: &'static [u8]) -> usize {
    foo.len()
}
error: `core::slice::<impl [T]>::len` is not yet stable as a const fn
 --> <source>:2:5
  |
2 |     foo.len()
  |     ^^^^^^^^^
error: aborting due to previous error
active toolchain
----------------

stable-x86_64-pc-windows-msvc (default) rustc 1.38.0 (625451e37 2019-09-23)

Upvotes: 8

Views: 3032

Answers (1)

loganfsmyth
loganfsmyth

Reputation: 161627

The 0.5.x would appear to require Rust 1.39 so the easiest option would likely be upgrading to the newest version.

The error states

core::slice::<impl [T]>::len is not yet stable as a const fn

and if you look at the release notes for 1.39 you can see that one of the entries is

str::len, [T]::len and str::as_bytes are now const functions

so this crate specifically requires >=1.39

Upvotes: 10

Related Questions