依存クレートが依存しているクレートを調べる
はじめに
kraken_collectorで使ってるクレートの一部がwarning: the following packages contain code that will be rejected by a future version of Rust
となっていたんですが、ついに1.80系でコンパイルエラーとなったのでアップデートしようとしてます。その関係で調べた備忘録。結論cargoめっちゃ便利だった。
Warningの原因を探る
現時点のkraken_collectorをビルドした際に以下のようなwaringが出る
rustc -V
rustc 1.79.0 (129f3b996 2024-06-10)
cargo build
...
Finished `dev` profile [unoptimized + debuginfo] target(s) in 24.40s
warning: the following packages contain code that will be rejected by a future version of Rust: traitobject v0.1.0
note: to see what the problems were, use the option `--future-incompat-report`, or run `cargo report future-incompatibilities --id 1`
使っているクレートのうち、将来的にtraitobject v0.1.0
が使えなくなるということである。実際rustc version 1.80.x ではコンパイルエラーとなる。しかしこれらは直接依存クレートとして設定してないので、[dependencies]
で定義しているクレートのどれかが依存しているものだと思われる。優先的に対応したいのでtraitobjectがどのクレートが使われているのかを調べたい。
レポートを見てみる
waningに記載されているレポートを叩いてみる
cargo report future-incompatibilities --id 1
The following warnings were discovered during the build. These warnings are an
indication that the packages contain code that will become an error in a
future release of Rust. These warnings typically cover changes to close
soundness problems, unintended or undocumented behavior, or critical problems
that cannot be fixed in a backwards-compatible fashion, and are not expected
to be in wide use.
Each warning should contain a link for more information on what the warning
means and how to resolve it.
To solve this problem, you can try the following approaches:
- Some affected dependencies have newer versions available.
You may want to consider updating them to a newer version to see if the issue has been fixed.
traitobject v0.1.0 has the following newer versions available: 0.1.1
- If the issue is not solved by updating the dependencies, a fix has to be
implemented by those dependencies. You can help with that by notifying the
maintainers of this problem (e.g. by creating a bug report) or by proposing a
fix to the maintainers (e.g. by creating a pull request):
- traitobject@0.1.0
- Repository: https://github.com/reem/rust-traitobject.git
- Detailed warning command: `cargo report future-incompatibilities --id 1 --package traitobject@0.1.0`
- If waiting for an upstream fix is not an option, you can use the `[patch]`
section in `Cargo.toml` to use your own version of the dependency. For more
information, see:
https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section
The package `traitobject v0.1.0` currently triggers the following future incompatibility lints:
> warning: conflicting implementations of trait `Trait` for type `(dyn Send + Sync + 'static)`: (E0119)
> --> /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/traitobject-0.1.0/src/impls.rs:72:1
> |
> 71 | unsafe impl Trait for ::std::marker::Send + Sync { }
> | ------------------------------------------------ first implementation here
> 72 | unsafe impl Trait for ::std::marker::Send + Send + Sync { }
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn Send + Sync + 'static)`
> |
> = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
> = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
>
> warning: conflicting implementations of trait `Trait` for type `(dyn Send + Sync + 'static)`: (E0119)
> --> /Users/usr/.cargo/registry/src/index.crates.io-6f17d22bba15001f/traitobject-0.1.0/src/impls.rs:73:1
> |
> 72 | unsafe impl Trait for ::std::marker::Send + Send + Sync { }
> | ------------------------------------------------------- first implementation here
> 73 | unsafe impl Trait for ::std::marker::Sync + Send { }
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn Send + Sync + 'static)`
> |
> = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
> = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
>
> warning: conflicting implementations of trait `Trait` for type `(dyn Send + Sync + 'static)`: (E0119)
> --> /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/traitobject-0.1.0/src/impls.rs:75:1
> |
> 73 | unsafe impl Trait for ::std::marker::Sync + Send { }
> | ------------------------------------------------ first implementation here
> 74 | unsafe impl Trait for ::std::marker::Sync + Sync { }
> 75 | unsafe impl Trait for ::std::marker::Sync + Send + Sync { }
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn Send + Sync + 'static)`
> |
> = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
> = note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
>
警告についての詳細とコードレベルの解説がレポートされる。ここではtraitobjectが警告にひっかかってる理由がよくわかるが、依存関係はわからなかった。
cargo tree (解決法)
cargo treeというコマンドがあった。
cargo tree --help
-e, --edges <KINDS> The kinds of dependencies to display (features, normal, build, dev,
all, no-normal, no-build, no-dev, no-proc-macro)
-i, --invert [<SPEC>] Invert the tree direction and focus on the given package
--prune <SPEC> Prune the given package from the display of the dependency tree
--depth <DEPTH> Maximum display depth of the dependency tree
...
-i, --invert [<SPEC>] Invert the tree direction and focus on the given package
これだ。
cargo tree -i traitobject@0.1.0
traitobject v0.1.0
└── hyper v0.10.16
└── websocket v0.27.1
└── kraken_collector v2.2.1 (/Users/user/src/kraken_collector)
期待通り。kraken_collectorが使っているwebsocket@0.27.1
の依存クレートであることがわかった。
おわりに
warningの原因がわかったので対策を進めていきたい。こういう方針を合理的に決めるための分析がcargoだけでできるとかすばらしいですね。
Discussion