Jw C
Jw C

Reputation: 324

Change nightly Rust version?

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?

Upvotes: 4

Views: 9458

Answers (1)

Jason
Jason

Reputation: 5575

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}>`

Upvotes: 10

Related Questions