rust 和紫 Crystal - 错误 [E0433] : failed to resolve: could not find `__rt` in `quote`

标签 rust amethyst

我正在从 "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...

最佳答案

TL;DR 手动编辑 Cargo.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"

这意味着 cargo 将使用最新的次要更新,因此如果 quote-1.0.3 已发布,则 cargo 将使用 1.0.3 而不是 1.0.2 。请查看caret-requirement .这里的问题是 quote-1.0.3 破坏了来自 quote-1.0.2 的向后兼容性。在这种情况下引用

如何强制cargo使用特定版本的子依赖

您可以通过强制子依赖项为您的依赖项使用兼容版本来解决此问题。 此命令将执行此操作:

> cargo update -p quote --precise 1.0.2 

如何强制 cargo 使用 yanked 版本的子依赖

看起来 quote-1.0.2 是从 crates.io 中提取的,所以上面的命令将不起作用,因为 cargo 将无法在 crates.io 上找到提取的版本。由于 cargo update 修改了 cargo.lock 我们可以手动完成。开始清理:

  1. 移除 Cargo.lock
  2. 运行cargo update(这将生成最新版本Cargo.lock)
  3. 编辑 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)",
]

然后只需将版本更改为兼容版本,在我们的例子中是 "1.0.2"

[[package]]
name = "quote"
version = "1.0.2"

之后不要再次运行 cargo update,它会覆盖你的更改,你将无法编译你的项目。请记住,这是一种能够继续开发的解决方法,有理由抽出包装箱,不要在生产中使用它,最好等待依赖的包装箱自行更新。


注意:在某些情况下,您可能会在编辑 cargo.lock 后遇到错误:

error: Found argument 'Cargo.lock' which wasn't expected, or isn't valid in this context

@albus_c 通过 doing 修复了这个问题:

A note for posterity: I fixed the issue removing rustc (sudo apt remove rustc) and reinstalled as recommended on the Rust website, curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh After that everything worked fine.

关于 rust 和紫 Crystal - 错误 [E0433] : failed to resolve: could not find `__rt` in `quote` ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60576277/

相关文章:

rust - 如何在Rust SPECS中读取组件并写入具有相同组件的新实体?

rust - Amethyst 的 Loader 找不到 Assets 文件

rust - 如何用 nightly Rust 解析 float ?

rust - 如何延长 Rust 中迭代器适配器内临时变量的生命周期?

rust - 如何在 Warp 中创建变量路径?

rust - 无法设置按钮颜色

rust - 紫晶 rust : 'Cannot insert multiple systems with the same name ("parent_hierarchy_system") when running pong tutorial

random - 从标准正态分布生成随机 float 并乘以另一个 float

memory-management - 如何将某些堆内存的所有权转移出函数?