Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile Error len is not yet stable as a const fn

Tags:

rust

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)
like image 709
王奕然 Avatar asked Dec 09 '19 03:12

王奕然


People also ask

Why doesn't this expression evaluate to a constant at compile time?

An expression declared as const or constexpr didn't evaluate to a constant at compile time. The compiler must be able to determine the value of the expression at the point it's used.

Why is the compiler unable to find the type library?

The compiler could not find the specified type library. Check to make sure that you have specified the path correctly. The imported type library is corrupt, invalid, or only partially constructed. The type library could not be generated. One possible cause of this error is specifying a path to the IDL file that is longer than 126 characters.

Why does the compiler abort compilation when syntax errors occur?

The compiler detected a syntax error at the specified line. cannot recover from earlier syntax errors; aborting compilation The MIDL compiler automatically tries to recover from syntax errors by adding or removing syntactic elements. This message indicates that despite these attempts to recover, the compiler detected too many errors.

How do I recover from syntax errors in the MIDL compiler?

The MIDL compiler automatically tries to recover from syntax errors by adding or removing syntactic elements. This message indicates that despite these attempts to recover, the compiler detected too many errors. Correct the specified error (s) and recompile. The specified C pragma is not supported in MIDL. Remove the pragma from the IDL file.


1 Answers

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

like image 103
loganfsmyth Avatar answered Oct 12 '22 03:10

loganfsmyth