Error: could not compile `math` (lib) due to 2 prevous errors

I'm trying to compile an old rust project, I've updated my rust compiler, and now this is happening:

...
Compiling env_logger v0.10.0
   Compiling dirs v2.0.2
   Compiling colored v2.0.0
   Compiling math v0.10.0
   Compiling nix v0.25.0
error[E0635]: unknown feature `drain_filter`
 --> /home/hu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/math-0.10.0/src/lib.rs:3:12
  |
3 | #![feature(drain_filter)]
  |            ^^^^^^^^^^^^

error[E0599]: no method named `drain_filter` found for struct `Vec<ContiguousIntegerSet<E>>` in the current scope
   --> /home/hu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/math-0.10.0/src/set/ordered_integer_set.rs:153:24
    |
153 |         self.intervals.drain_filter(|i| i.is_empty());
    |                        ^^^^^^^^^^^^ method not found in `Vec<ContiguousIntegerSet<E>>`

   Compiling h2 v0.3.15
   Compiling iprange v0.6.7
Some errors have detailed explanations: E0599, E0635.
For more information about an error, try `rustc --explain E0599`.
error: could not compile `math` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

Should I remove the math crate and change my code?
Is this because the feature doesn't exist anymore?

math appears to be a 2 year old crate that only works on some unspecified, out of date nightly build of the compiler.

I'd say you have three options:

  • Rewrite the code to remove the use of math.
  • Search for an older nightly compiler version that works (presumably looking at 2-ish year old versions would be a good starting point).
  • Fork the math crate, modify it to work on a recent compiler, then use that fork instead.

As an aside: I wouldn't ever depend on a library that requires nightly for exactly this reason.

4 Likes

Either that or consider filing a bug on their issue tracker and see if the maintainer will update the crate. Or pin your nightly compiler to an older build for your project with a rust-toolchain file. But replacing the crate might be apropos.

Yes, sort of. Nightly features are unstable, meaning they can change implementation details, be abandoned completely, or stabilize. In this case, the method and feature gate have been renamed: Tracking issue for Vec::extract_if and LinkedList::extract_if · Issue #43244 · rust-lang/rust (github.com)

3 Likes