我正在从Shing Lyu 的“Practical Rust Projects”中学习 Rust 。我现在正在尝试按照第 4 章中的步骤构建游戏。我正在 Ubuntu 18.04 LTS 上工作。
安装 Rust 和 Amethyst 命令行后,我通过amethyst new cat_volleyball. 下一步是使用cargo run --features=vulkan
. 当我这样做时,我收到下面的错误提示。你有关于如何解决这个问题的建议吗?
error[E0433]: failed to resolve: could not find `__rt` in `quote`
--> /home/alberto/.cargo/registry/src/github.com-1ecc6299db9ec823/err-derive-0.1.6/src/lib.rs:145:63
|
145 | fn display_body(s: &synstructure::Structure) -> Option<quote::__rt::TokenStream> {
| ^^^^ could not find `__rt` in `quote`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.
error: could not compile `err-derive`.
warning: build failed, waiting for other jobs to finish...
Run Code Online (Sandbox Code Playgroud)
TL;DRCargo.lock手动编辑,请检查下面的标题:How to force cargo to use yanked version of sub-dependency(正确的步骤)
发生这种情况是因为err-derive-0.1.6使用quote-1.0.2的依赖,但它的cargo.toml依赖声明如下:
[dependencies.quote]
version = "1.0.2"
Run Code Online (Sandbox Code Playgroud)
这意味着货物将采用最新的小更新,因此,如果quote-1.0.3超出则货物将使用1.0.3代替1.0.2。请检查插入符要求。这里的问题是quote-1.0.3破坏了来自quote-1.0.2. 在这种情况下报价
您可以通过强制子依赖项为您的依赖项使用兼容版本来解决此问题。此命令将执行此操作:
> cargo update -p quote --precise 1.0.2
Run Code Online (Sandbox Code Playgroud)
看起来像是quote-1.0.2从 crates.io 中提取的,所以上面的命令将不起作用,因为货物将无法在 crates.io 上找到被提取的版本。由于货物更新修改了cargo.lock我们可以手动完成。开始清洁:
Cargo.lockcargo update(这将生成最新版本Cargo.lock)Cargo.lock在 cargo.lock 中找到不兼容的包版本quote-1.0.3,它应该是这样的:
[[package]]
name = "quote"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
Run Code Online (Sandbox Code Playgroud)
然后只需将版本更改为在我们的情况下兼容的版本 "1.0.2"
[[package]]
name = "quote"
version = "1.0.2"
Run Code Online (Sandbox Code Playgroud)
这样做之后不要再次运行货物更新,它会覆盖您的更改并且您将无法编译您的项目。请记住,这是一种能够继续开发的解决方法,有一个理由要拉开 crate,不要在生产中使用它,最好等待依赖 crate 自我更新。
注意: 在某些情况下,编辑后可能会出现错误cargo.lock:
[dependencies.quote]
version = "1.0.2"
Run Code Online (Sandbox Code Playgroud)
@albus_c 通过执行以下操作修复了此问题:
后人注意:我解决了删除 rustc (
sudo apt remove rustc)的问题,并按照 Rust 网站上的建议重新安装,curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh之后一切正常。