英文:
How to fix use of unstable library feature 'test': `bench` is a part of custom test frameworks which are unstable
问题
在尝试使用 cargo[benchmark][1]
功能时,它会抛出错误:
错误:使用不稳定的库特性 'test':`bench` 是自定义测试框架的一部分,目前不稳定
|
| #[bench]
| ^^^^^
|
= 警告:编译器先前接受了这个,但正在逐步淘汰;在将来的版本中将变为严格错误!
= 注意:有关更多信息,请参见问题 #64266 <https://github.com/rust-lang/rust/issues/64266>
= 注意:默认情况下启用 `#[deny(soft_unstable)]`
英文:
While trying to use cargobenchmark feature, it throws error:
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
答案1
得分: 2
以下是翻译好的部分:
修复此问题的步骤:
- 使用夜间版编译或将夜间版设置为默认:
使用夜间版编译:
cargo +nightly bench ...
将夜间版设置为默认:
rustup default nightly
- 添加测试特性
要做到这一点,在您的根文件顶部添加2行代码(即使在导入之前):
#![feature(test)]
extern crate test;
use...
这将允许您使用#[bench]
特性。
英文:
Steps to fix this issue:
- compile using nightly version or set nightly to default:
> To compile using nightly version:
cargo +nightly bench ...
>To set nightly as default:
rustup default nightly
- add test feature
To do this, add 2 lines to the top of your root file. (Even above imports)
#![feature(test)]
extern crate test;
use...
This will allow you to use the #[bench]
feature.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论