dead_code
编译器提供了一个 dead_code
lint,它会警告未使用的函数。可以使用属性来禁用 lint。
fn used_function() {} // `#[allow(dead_code)]` is an attribute that disables the `dead_code` lint #[allow(dead_code)] fn unused_function() {} fn noisy_unused_function() {} // FIXME ^ Add an attribute to suppress the warning fn main() { used_function(); }
请注意,在实际程序中,您应该消除死代码。在这些示例中,由于示例的交互性质,我们将在某些地方允许死代码。