Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
904 views
in Technique[技术] by (71.8m points)

rust - Is it possible to have Cargo always show warnings?

I'm using watch with cargo, in order to quickly see compile time errors. However, cargo build will only show errors when building the first time.

$ 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
$

Which means I only get to see the warnings for a few seconds before watch gives me a clear screen.

Is there any way to make cargo build always give me the warnings?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As of Rust 1.40, Cargo will cache the compiler messages. This means that even if the code doesn't need to be compiled again, the previous warnings will be printed out.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...