我将 watch
与 cargo
一起使用,以便快速查看编译时错误。但是,cargo build
只会在第一次构建时显示错误。
$ cargo build
Compiling clayman v0.0.1
src/core_math/vector.rs:8:5: 13:6 warning: method is never used: `New`, #[warn(dead_code)] on by default
src/core_math/vector.rs:8 pub fn New(x: i32, y: i32) -> Vector {
src/core_math/vector.rs:9 Vector {
src/core_math/vector.rs:10 x: x,
src/core_math/vector.rs:11 y: y
src/core_math/vector.rs:12 }
src/core_math/vector.rs:13 }
src/core_math/vector.rs:8:5: 13:6 warning: method `New` should have a snake case name such as `new`, #[warn(non_snake_case)] on by default
src/core_math/vector.rs:8 pub fn New(x: i32, y: i32) -> Vector {
src/core_math/vector.rs:9 Vector {
src/core_math/vector.rs:10 x: x,
src/core_math/vector.rs:11 y: y
src/core_math/vector.rs:12 }
src/core_math/vector.rs:13 }
src/main.rs:28:9: 28:10 warning: unused variable: `v`, #[warn(unused_variables)] on by default
src/main.rs:28 let v: vector::Vector;
^
$ cargo build
$
这意味着在 watch
给我一个清晰的屏幕之前,我只能看到几秒钟的警告。
有没有办法让 cargo build
总是给我警告?
最佳答案
从 Rust 1.40 开始,Cargo will cache the compiler messages .这意味着即使代码不需要重新编译,之前的警告也会被打印出来。
使用rust 1.40
% cargo build
Compiling warnings v0.1.0 (/private/tmp/warnings)
warning: unused variable: `a`
--> src/main.rs:2:9
|
2 | let a = 42;
| ^ help: consider prefixing with an underscore: `_a`
|
= note: `#[warn(unused_variables)]` on by default
Finished dev [unoptimized + debuginfo] target(s) in 1.58s
% cargo build
warning: unused variable: `a`
--> src/main.rs:2:9
|
2 | let a = 42;
| ^ help: consider prefixing with an underscore: `_a`
|
= note: `#[warn(unused_variables)]` on by default
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
使用rust 1.39
% cargo build
Compiling warnings v0.1.0 (/private/tmp/warnings)
warning: unused variable: `a`
--> src/main.rs:2:9
|
2 | let a = 42;
| ^ help: consider prefixing with an underscore: `_a`
|
= note: `#[warn(unused_variables)]` on by default
Finished dev [unoptimized + debuginfo] target(s) in 0.42s
% cargo build
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
关于rust - 是否可以让 Cargo 始终显示警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53878090/