编译器 Lint 和 Clippy

Rust 编译器会生成出色的错误消息,并提供实用的内置 lint 功能。Clippy 提供了更多 lint 功能,采用按组分类方式,并可按项目灵活启用。

#[deny(clippy::cast_possible_truncation)]
fn main() {
    let mut x = 3;
    while (x < 70000) {
        x *= 2;
    }
    println!("X probably fits in a u16, right? {}", x as u16);
}
This slide should take about 3 minutes.

There are compiler lints visible here, but not clippy lints. Run clippy on the playground site to show clippy warnings. Clippy has extensive documentation of its lints, and adds new lints (including default-deny lints) all the time.

请注意,带有 help: ... 的错误或警告可以通过 cargo Fix 或编辑器进行修复。