gpt4 book ai didi

rust - 为什么用 git hash 替换依赖项的版本和路径属性会导致编译错误?

转载 作者:行者123 更新时间:2023-11-29 08:23:16 25 4
gpt4 key购买 nike

我有一个奇怪的依赖问题。以下是重现步骤:

❯ rustc -V
rustc 1.35.0-nightly (82e2f3ec2 2019-03-20)

❯ git clone https://github.com/google/tarpc.git
❯ cd tarpc/example-service

❯ cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.13s

❯ git rev-parse HEAD
06544faa5a0872d4be989451afc0a2b1e1278df4

现在我将 Cargo.toml 中的一行替换为

bincode-transport = { package = "tarpc-bincode-transport", version = "0.3", path = "../bincode-transport" }

bincode-transport = { package = "tarpc-bincode-transport", git="https://github.com/google/tarpc.git", rev="06544faa5a0872d4be989451afc0a2b1e1278df4" }

表示相同的代码库(我认为 version = 0.3 没有意义),

然后我有一个构建错误

❯ cargo build
Blocking waiting for file lock on the git checkouts
Updating git repository `https://github.com/google/tarpc.git`
Compiling tarpc-example-service v0.2.0 (tarpc/example-service)
error[E0277]: the trait bound `tarpc_bincode_transport::Transport<tokio_tcp::stream::TcpStream, _, _>: tarpc_lib::transport::Transport` is not satisfied
--> example-service/src/server.rs:45:4
|
45 | .incoming(transport)
| ^^^^^^^^ the trait `tarpc_lib::transport::Transport` is not implemented for `tarpc_bincode_transport::Transport<tokio_tcp::stream::TcpStream, _, _>`

error[E0277]: the trait bound `tarpc_bincode_transport::Transport<tokio_tcp::stream::TcpStream, _, _>: tarpc_lib::transport::Transport` is not satisfied
--> example-service/src/client.rs:20:29
|
20 | let mut client = await!(service::new_stub(client::Config::default(), transport))?;
| ^^^^^^^^^^^^^^^^^ the trait `tarpc_lib::transport::Transport` is not implemented for `tarpc_bincode_transport::Transport<tokio_tcp::stream::TcpStream, _, _>`
|
= note: required by `service::new_stub`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: Could not compile `tarpc-example-service`.
warning: build failed, waiting for other jobs to finish...
error[E0599]: no method named `respond_with` found for type `impl futures_core::stream::Stream` in the current scope
--> example-service/src/server.rs:48:4
|
48 | .respond_with(service::serve(HelloServer));
| ^^^^^^^^^^^^
|
= note: the method `respond_with` exists but the following trait bounds were not satisfied:
`&impl futures_core::stream::Stream : tarpc_lib::server::Handler<_, _, _>`
`&mut impl futures_core::stream::Stream : tarpc_lib::server::Handler<_, _, _>`
`impl futures_core::stream::Stream : tarpc_lib::server::Handler<_, _, _>`

error: aborting due to 2 previous errors

Some errors occurred: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: Could not compile `tarpc-example-service`.

cargo clean 没有帮助。这怎么可能?

最佳答案

这与 Why is a trait not implemented for a type that clearly has it implemented? 是同一个问题— 通过引入 代码的 git 版本和代码的本地版本(通过 tarpc = { path = "../tarpc"}}),你是两次编译 tarpc crate。每个的特征彼此不同,它们实际上是同一个 crate 的不同版本。

这可以使用 cargo tree -d -i 来验证:

tarpc-lib v0.2.0 (https://github.com/google/tarpc.git?rev=06544faa5a0872d4be989451afc0a2b1e1278df4#06544faa)
└── tarpc-bincode-transport v0.3.0 (https://github.com/google/tarpc.git?rev=06544faa5a0872d4be989451afc0a2b1e1278df4#06544faa)
└── tarpc-example-service v0.2.0 (/private/tmp/tarpc/example-service)

tarpc-lib v0.2.0 (/private/tmp/tarpc/rpc)
└── tarpc v0.14.1 (/private/tmp/tarpc/tarpc)
└── tarpc-example-service v0.2.0 (/private/tmp/tarpc/example-service)

tarpc-trace v0.1.0 (https://github.com/google/tarpc.git?rev=06544faa5a0872d4be989451afc0a2b1e1278df4#06544faa)
└── tarpc-lib v0.2.0 (https://github.com/google/tarpc.git?rev=06544faa5a0872d4be989451afc0a2b1e1278df4#06544faa)
└── tarpc-bincode-transport v0.3.0 (https://github.com/google/tarpc.git?rev=06544faa5a0872d4be989451afc0a2b1e1278df4#06544faa)
└── tarpc-example-service v0.2.0 (/private/tmp/tarpc/example-service)

tarpc-trace v0.1.0 (/private/tmp/tarpc/trace)
└── tarpc-lib v0.2.0 (/private/tmp/tarpc/rpc)
└── tarpc v0.14.1 (/private/tmp/tarpc/tarpc)
└── tarpc-example-service v0.2.0 (/private/tmp/tarpc/example-service)

如果你一直使用来自 git 的版本,它会起作用:

tarpc = { git = "https://github.com/google/tarpc.git", rev = "06544faa5a0872d4be989451afc0a2b1e1278df4", features = ["serde1"] }

关于rust - 为什么用 git hash 替换依赖项的版本和路径属性会导致编译错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55324285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com