【问题标题】:Change nightly Rust version?更改夜间 Rust 版本?
【发布时间】:2021-07-05 12:12:04
【问题描述】:

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

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 编译器版本来修复编译问题。如果这是正确的解决方案,我该怎么做?谁能提供一些详细的建议?

【问题讨论】:

    标签: rust build rust-cargo rls


    【解决方案1】:

    使用rustup,您可以管理不同的夜间版本。请参阅The Edition Guide 了解更多信息。

    由于Option::expect_noneremoved on March 25th,我们可以通过以下方式获得 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}>`
    

    【讨论】:

    • 感谢您的回答。我还必须将编译指令从 cargo +nightly build --release -Z unstable-options 更改为 cargo build --release -Z unstable-options 才能使其正常工作。
    猜你喜欢
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 2013-03-15
    • 1970-01-01
    相关资源
    最近更新 更多