在找出cargo build of the same code: spurious compile time errors?之后,我想知道如何防止这样的问题:

$ cargo new feature_merge
$ cargo add nmea
$ cargo check > /dev/null 2>&1 && echo "success"
success
$ cargo add cexpr
$ cargo check > /dev/null 2>&1 || echo "failed"
failed
$ cargo rm cexpr && cargo check > /dev/null 2>&1 && echo "success"
success

我无需修改任何代码即可删除/添加依赖项,这会影响构建结果。

问题的根源as I describedcexpr取决于nom,如下所示:
nom = {version = "^3", features = ["verbose-errors"] }

nmea描述了这种依赖关系:
nom = "3.1.0"

仅依靠nmea作为依赖项,Cargo使用一组功能构建nom,
而Cargo使用另一套功能针对nom构建cexpr和nmea。

我想要一种方法来防止错误维护我维护的nmea crate 。

我想要像"`nom` compiled with wrong features"这样的编译时错误,或强制Cargo构建nom的两个变体。

我在nmea/Cargo.toml中尝试了这样的事情:
nom = { version = "3.1.0", default-features = false }

这并没有改变。将cexpr和nmea结合使用时,仍然会出现编译时错误。

最佳答案

这是已知问题,相关链接:

cargo issue 1

cargo issue 2

cargo rfc

简短摘要:



换句话说, crate 中的每个功能都只能附加功能,
不更改API。不幸的是,没有很好的文档来描述这个问题,
而且至少在此刻还没有用于测试该不变量的自动化工具。
此特定问题与nom错误(github issue)有关,
从那里引用:

关于rust - 如何防止Cargo将相同的依赖项与不同的功能合并?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45287134/

10-12 01:29
查看更多