3

我尝试通过命令构建rlscargo +nightly build --release -Z unstable-options,但出现以下错误:

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

搜索后,我发现这expect_none是一个夜间功能,似乎已被删除。

所以我想也许我应该更改 rust 编译器版本来修复编译问题。如果这是正确的解决方案,我该怎么做?谁能提供一些详细的建议?

4

1 回答 1

6

使用rustup您可以管理不同的夜间版本。有关更多信息,请参阅版本指南

由于在 3 月 25 日Option::expect_none被删除,我们可以通过以下方式获得 3 月 24 日的每晚:

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

注意:该--force选项被用作组件rustfmtclippy可能会丢失。

切换到新下载的工具链:

rustup default nightly-2021-03-24

正如预期的那样,以下内容main.rs现在应该恐慌:

#![feature(option_expect_none)]

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

如果你很好奇,你可以试试这个,nightly-2021-03-26你会发现它会给你预期的错误,表明它确实被删除了:

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}>`
于 2021-04-09T16:54:07.203 回答