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

huangapple go评论78阅读模式
英文:

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

以下是翻译好的部分:

修复此问题的步骤:

  1. 使用夜间版编译或将夜间版设置为默认:

使用夜间版编译:

cargo +nightly bench ...

将夜间版设置为默认:

rustup default nightly
  1. 添加测试特性

要做到这一点,在您的根文件顶部添加2行代码(即使在导入之前):

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

use...

这将允许您使用#[bench]特性。

英文:

Steps to fix this issue:

  1. 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
  1. 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.

huangapple
  • 本文由 发表于 2023年5月13日 17:57:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76242130.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定