Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Compiler errors Cargo未能编译';num';_Compiler Errors_Rust_Rust Cargo - Fatal编程技术网

Compiler errors Cargo未能编译';num';

Compiler errors Cargo未能编译';num';,compiler-errors,rust,rust-cargo,Compiler Errors,Rust,Rust Cargo,我试图在Rust中的项目中使用板条箱“num”(我对这种语言完全是新手),因此我的Cargo.toml现在是: [package] name = "hello_world" version = "0.0.1" authors = [ "Vini" ] [dependencies] time = "*" num = "*" 但当我跑步时: cargo run 我得到这个编译错误: /.cargo/registry/src/github.com-0a35038f75765ae4/num-0

我试图在Rust中的项目中使用板条箱“num”(我对这种语言完全是新手),因此我的Cargo.toml现在是:

[package]

name = "hello_world"
version = "0.0.1"
authors = [ "Vini" ]

[dependencies]

time = "*"
num = "*"
但当我跑步时:

cargo run
我得到这个编译错误:

/.cargo/registry/src/github.com-0a35038f75765ae4/num-0.0.6/src/bigint.rs:66:16: 66:19 error: expected identifier, found keyword `mod`

/.cargo/registry/src/github.com-0a35038f75765ae4/num-0.0.6/src/bigint.rs:66 use std::str::{mod, FromStr};

                                                                                           ^~~

/.cargo/registry/src/github.com-0a35038f75765ae4/num-0.0.6/src/bigint.rs:80:27: 80:28 error: expected one of `(`, `+`, `::`, `;`, `<`, or `]`, found `,`

/.cargo/registry/src/github.com-0a35038f75765ae4/num-0.0.6/src/bigint.rs:80 static ZERO_VEC: [BigDigit, ..1] = [ZERO_BIG_DIGIT];
                                                                                                      ^
Could not compile `num`.
和rust编译器:

rustc 1.2.0 (082e47636 2015-08-03)
简短的回答 您的Cargo.lock文件包含对旧版本板条箱的引用(在本例中为非常旧版本)。运行
cargo update
以获取最新版本

为什么? 构建代码时,使用Cargo.toml文件将所需的版本限制传达给Cargo。这可以让你说“至少这个版本”或“只有这个确切的版本”或“这个版本的任何错误修复”

Cargo接受您的限制和当前可用的版本,并计算最新的版本集,以适合您或告诉您是否适合。然后将所有数据保存到Cargo.lock文件中

Cargo.lock文件保持不变,这样库的版本就不会在您的控制下随意更改。您可以运行
cargo update
来重做该过程并获取最新版本


如果你正在制作一个图书馆,故事就到此结束。如果您正在生成一个二进制文件,您应该将锁文件签入到源代码管理中,因为这就是您与代码的其他用户通信的方式—确切地说应该使用什么版本。当您部署代码版本时,您可以确保在生产中使用与开发相同的版本。

我已经在文章中添加了相关信息,感谢您的关注!谢谢@Shepmaster!构建Cargo.lock再次解决了这个问题,旧版本中的“num”引用确实适用于旧版本。小说明:Cargo update更新所有板条箱,Cargo update-p板条箱升级特定板条箱,这可能更安全。
rustc 1.2.0 (082e47636 2015-08-03)