本文介绍了相同代码的货物构建:虚假编译时错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有依赖于 BB 的箱子 A 依赖于 rust-nmea 箱子.

I have crate A that depend on B and B depend on rust-nmea crate.

如果我构建 crate A 我在构建 依赖:

If I build crate A I got bunch of errors (all of them that missed use std::error::Error;) during build of rust-nmea dependency:

error[E0599]: no method named `description` found for type `nom::Err<&[u8]>` in the current scope
   --> /home/evgeniy/.cargo/registry/src/github.com-1ecc6299db9ec823/nmea-0.0.6/src/parse.rs:100:44
    |
100 |                      IError::Error(e) => e.description().to_string(),
    |                                            ^^^^^^^^^^^
    |
    = help: items from traits can only be used if the trait is in scope
    = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
            candidate #1: `use std::error::Error;`

但是如果我去 B crate 的源代码树并运行 cargo build,所有构建都没有任何错误(如果你跟着我 A 依赖于 BB 依赖于 rust-nmea),

But if I go to source tree of B crate and run cargo build,all build without any error (if you follow me A depend on B and B depend on rust-nmea),

如果去/home/evgeniy/.cargo/registry/src/github.com-1ecc6299db9ec823/nmea-0.0.6/(见编译错误)并运行cargo build 那么一切都很好.

also if go to /home/evgeniy/.cargo/registry/src/github.com-1ecc6299db9ec823/nmea-0.0.6/ (see compile error) and run cargo build then all good.

A 的货物树展示:

│   ├── chrono v0.4.0
│   │   ├── num v0.1.40
│   │   │   ├── num-integer v0.1.35
│   │   │   │   └── num-traits v0.1.40
│   │   │   ├── num-iter v0.1.34
│   │   │   │   ├── num-integer v0.1.35 (*)
│   │   │   │   └── num-traits v0.1.40 (*)
│   │   │   └── num-traits v0.1.40 (*)
│   │   └── time v0.1.38
│   │       └── libc v0.2.27
 ├── nmea v0.0.6
    │   ├── chrono v0.4.0 (*)
    │   └── nom v3.2.0
    │       └── memchr v1.0.1 (*)

以及由 cargo 缓存 rust-nmea:

├── chrono v0.4.0
│   ├── num v0.1.40
│   │   ├── num-integer v0.1.35
│   │   │   └── num-traits v0.1.40
│   │   ├── num-iter v0.1.34
│   │   │   ├── num-integer v0.1.35 (*)
│   │   │   └── num-traits v0.1.40 (*)
│   │   └── num-traits v0.1.40 (*)
│   └── time v0.1.38
│       └── libc v0.2.27
└── nom v3.2.0
    └── memchr v1.0.1
        └── libc v0.2.27 (*)

所以无论好坏都使用相同的依赖项.

so for both good and bad case used the same dependencies.

如果运行 cargo build -v -j1,我得到了两种情况下的 rustc 命令行.

If run cargo build -v -j1, I got rustc command line for both cases.

好坏的唯一区别是这部分:

The only difference for good and bad case is this part:

-L dependency=/home/evgeniy/.cargo/registry/src/github.com-1ecc6299db9ec823/nmea-0.0.6/target/debug/deps --extern chrono=/home/evgeniy/.cargo/registry/src/github.com-1ecc6299db9ec823/nmea-0.0.6/target/debug/deps/libchrono-8e9e54e691d9b988.rlib --extern nom=/home/evgeniy/.cargo/registry/src/github.com-1ecc6299db9ec823/nmea-0.0.6/target/debug/deps/libnom-b72336f662b090c1.rlib

坏情况有不同的库路径和libnom-e2ec53418967eac0.rlib 而不是libnom-b72336f662b090c1.rlib,而libchrono-8e9e54e691d9b988.rlib> 匹配.

bad case have different path to libraries and libnom-e2ec53418967eac0.rlib instead of libnom-b72336f662b090c1.rlib, while libchrono-8e9e54e691d9b988.rlib match.

板条箱 AB 是近源的,我无法将问题简化为更简单的情况.nom 未在 AB 中使用的 crate除了通过 rust-nmea.rust-nmea 使用简单,只需 nmea = 0.0.6Cargo.toml 中.没有标志之类的东西.

The crates A and B are close sourced and I can not reduce problem to more simple case. nom crates not used in A and B except via rust-nmea.rust-nmea is used in simple way, just nmea = 0.0.6 in Cargo.toml.No flags or so on things.

知道为什么使用相同标志的 crate 依赖(根本没有标志)可能产生或不产生语法错误?

Any idea why crate dependecy with the same flags (no flags at all)may produce or not produce syntax error?

推荐答案

我找到了问题的根源,crate Aceexpr 有二级依赖关系,cexprCargo.toml 中有 nom = {version = "^3", features = ["verbose-errors"] }rust-nmea 也依赖于 nom,所以我们有编译时错误.

I found source of problem,crate A has second level dependicies with cexpr,cexpr has nom = {version = "^3", features = ["verbose-errors"] } in Cargo.toml,rust-nmea also depend on nom, so we have compile time error.

这篇关于相同代码的货物构建:虚假编译时错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 16:00