撤消从属依赖项 - 错误 [E0433]:无法解析:无法在 `quote` 中找到 `__rt`

问题描述 投票:0回答:1

我正在从 Shing Lyu 的 “实用 Rust 项目” 学习 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...
rust rust-cargo amethyst
1个回答
6
投票

TL;DR 手动编辑

Cargo.lock
,请检查下面的标题以了解正确的步骤:如何强制货物使用子依赖项的拉取版本


为什么会出现这种情况?

因为

err-derive-0.1.6
使用
quote-1.0.2
作为依赖项,并且引用声明如下:

[dependencies.quote]
version = "1.0.2"

这意味着 Cargo 将使用最新的补丁更新,因此如果

quote-1.0.3
已退出,则 Cargo 将使用
1.0.3
而不是
1.0.2
。请检查插入符号要求。这里的问题是
quote-1.0.3
破坏了向后兼容性,
err-derive-0.1.6
使用的部分在
quote-1.0.3
中不再存在。

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

您可以通过强制子依赖项使用与您的依赖项兼容的版本来解决此问题。 这个命令就可以做到:

> cargo update -p quote --precise 1.0.2 

如何强制货物使用子依赖项的拉取版本

看起来

quote-1.0.2
已从 crates.io 中拉出,因此上面的命令将不起作用,因为 Cargo 将无法在 crates.io 上找到拉出的版本。由于货物更新修改了
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"

执行此操作后,请勿再次运行货物更新,它将覆盖您的更改,并且您将无法编译项目。请记住,这是能够继续开发的解决方法,有一个理由要撤回 crate,不要在生产中使用它,最好等待依赖的 crate 自行更新。


注意:在某些情况下,编辑后可能会出现错误

cargo.lock

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

@albus_c 通过 doing 解决了这个问题:

给后代的注释:我修复了删除 rustc 的问题 (

sudo apt remove rustc
) 并按照 Rust 网站上的建议重新安装,
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
之后一切正常。

© www.soinside.com 2019 - 2024. All rights reserved.