找出大型 rust 项目(servo)中 "use"d 模块的代码

Figure out code from what module is "use"d in a large rust project (servo)

我正在尝试阅读 servo. As an example, I'm looking at this code in layout_task.rs 的代码:

use url::Url;

..我想知道这是指哪个代码(答案是rust-url)。

根据 Rust reference §6.1.2.2 Use declarations

the paths contained in use items are relative to the crate root [...]

It is also possible to use self and super at the beginning of a use item to refer to the current and direct parent modules respectively.

All rules regarding accessing declared modules in use declarations apply to both module declarations and extern crate declarations.

参考文献 (§5 Crates and source files) 没有明确说明 "crate root" 是什么,但它确实分享了:

A crate contains a tree of nested module scopes. The top level of this tree is a module that is anonymous [...] The Rust compiler is always invoked with a single source file as input, and always produces a single output crate. The processing of that source file may result in other source files being loaded as modules.

所以看来要找到当前文件(layout_task.rs)所属的crate root,我们需要弄清楚是什么源文件rustc 在构建板条箱时被调用。对于 Cargo,这是在 Cargo.toml 中指定的,默认为 src/lib.rs:

[lib]
path = "src/lib.rs"

就我而言,这里的 Cargo.toml and the lib.rs 有:

extern crate url;
pub mod layout_task;

到目前为止一切顺利。要找出 extern crate 指的是什么,我们需要再次查看 Cargo.toml

[dependencies.url]
version = "0.2"

cargo docs claim that "Dependencies from crates.io are not declared with separate sections", but apparently they can be... So we look the package up on crates.io: https://crates.io/crates/url