4

I tried to build rls by the command cargo +nightly build --release -Z unstable-options, but got the following errors:

error[E0599]: no method named `expect_none` found for enum `Option<Fingerprint>` in the current scope
    --> /Users/cjw/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_span-705.0.0/src/lib.rs:2003:48
     |
2003 |                 cache[index].replace(sub_hash).expect_none("Cache slot was filled");
     |                                                ^^^^^^^^^^^ method not found in `Option<Fingerprint>`

After searching it, I found that expect_none is a nightly feature and seemingly has been removed.

So I think maybe I should change the rust compiler version to fix the compilation problem. If this is the correct solution, how could I do it? Can anyone provide some detail suggestions?

Jw C
  • 171
  • 2
  • 6

1 Answers1

9

Using rustup you can manage different nightly versions. See The Edition Guide for more.

As Option::expect_none was removed on March 25th, we can get the nightly for March 24th in the following way:

rustup toolchain install nightly-2021-03-24 --force

Note: the --force option was used as the components rustfmt and clippy might be missing.

Switch to the newly downloaded toolchain:

rustup default nightly-2021-03-24

The following main.rs should now panic, as expected:

#![feature(option_expect_none)]

fn main() {
    let value = Some(42);
    value.expect_none("The answer");
}

If you're curious, you could try this with nightly-2021-03-26 and you'll find that it will give you the expected error, indicating it was indeed removed:

error[E0599]: no method named `expect_none` found for enum `Option<{integer}>` in the current scope
 --> src/main.rs:5:11
  |
5 |     value.expect_none("Expected none!");
  |           ^^^^^^^^^^^ method not found in `Option<{integer}>`
Jason
  • 4,905
  • 1
  • 30
  • 38
  • 2
    Thanks for your answer. I also have to change the compile instruction from `cargo +nightly build --release -Z unstable-options` to `cargo build --release -Z unstable-options` to make it works. – Jw C Apr 10 '21 at 03:18
  • Aren't you think that install the `nightly` toolchain using `--force` flag` is not a good idea, please let me know that if you have tested this – Emad Baqeri Sep 10 '22 at 11:50