rust 如何修复使用不稳定的库功能“test”:`bench`是不稳定的自定义测试框架的一部分[重复]

wn9m85ua  于 2023-05-18  发布在  其他
关注(0)|答案(1)|浏览(302)

此问题已在此处有答案

"use of unstable library feature 'collections'" using nightly(3个答案)
3天前关闭。
当尝试使用cargo benchmark功能时,它抛出错误:

error: use of unstable library feature 'test': `bench` is a part of custom test frameworks which are unstable

    |
    |     #[bench]
    |       ^^^^^
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #64266 <https://github.com/rust-lang/rust/issues/64266>
    = note: `#[deny(soft_unstable)]` on by default
bz4sfanl

bz4sfanl1#

解决此问题的步骤:
1.使用nightly版本编译或将nightly设置为默认值:
要使用夜间版本编译:

cargo +nightly bench ...

要将夜间设置为默认值,请执行以下操作:

rustup default nightly

1.添加测试功能
为此,在根文件的顶部添加两行。(甚至高于进口)

#![feature(test)]
extern crate test;

use...

这将允许您使用#[bench]功能。

相关问题