Can Cargo always display warnings?

I use watchc cargoto quickly see compile-time errors. However, it cargo buildwill only show assembly errors for 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
$

This means that I only see warnings for a few seconds before watchgiving me a clear screen.

Is there any way to do cargo buildalways give me warnings?

+11
source share
4 answers

Warnings only appear when Rust recompiles your files; however, it caches as much as possible, and if something has not changed, it will gladly skip the useless compilation. There is currently no option in Cargo to force recovery.

, , touch , Cargo , :

$ cd /path/to/project/root
$ ls
Cargo.lock Cargo.toml src        target
$ cargo build
     Compiling abc v0.1.0 (file:///private/tmp/b/abc)
  src/main.rs:2:9: 2:10 warning: unused variable: 'x', #[warn(unused_variables)] on by default
  src/main.rs:2     let x: u8 = 123;
                        ^
$ cargo build
$ touch $(find src)
$ cargo build
     Compiling abc v0.1.0 (file:///private/tmp/b/abc)
  src/main.rs:2:9: 2:10 warning: unused variable: 'x', #[warn(unused_variables)] on by default
  src/main.rs:2     let x: u8 = 123;
                        ^

, , , target , , cargo clean:

$ cargo build
   Compiling abc v0.1.0 (file:///private/tmp/b/abc)
src/main.rs:2:9: 2:10 warning: unused variable: 'x', #[warn(unused_variables)] on by default
src/main.rs:2     let x: u8 = 123;
                      ^
$ cargo build
$ cargo clean
$ cargo build
   Compiling abc v0.1.0 (file:///private/tmp/b/abc)
src/main.rs:2:9: 2:10 warning: unused variable: 'x', #[warn(unused_variables)] on by default
src/main.rs:2     let x: u8 = 123;
                      ^

Vim , ! , , .

+3

, mdups.

, :

touch src/my_tra_la_la.rs && clear && clear && cargo check

clear && clear && , , .

, mod my_tra_la_la; main.rs lib.rs .

, , , src/my_tra_la_la.rs:

//! The only purpose of this file is to act as a target for the 'touch' command
//! in order to force recompilation of this otherwise meaningless file and in
//! turn to force rustc to display warnings, every time.
//!
//! touch src/my_tra_la_la.rs && clear && clear && cargo check
//!
//! Mmm...my ding ding dong

, , , - , " !" .

+1

The solution, albeit temporarily, was touchto a file that I rarely edit. In this way, I avoid the problem associated with the change this file has been changed, and also do not need to constantly clean the entire project.

In addition, I also managed to add colors (in --coloroptions --color), without using them at all watch, but simply by running the following script:

#!/bin/sh
while :
do
    script -qc "cargo build" /dev/null > .tmp
    clear
    cat .tmp
    sleep 2 # or whatever
    touch src/somefile.rs
done

The reason I write and read .tmpis because all output is displayed in one ( rustcdata rustcwhile running)

0
source

I have come across this before. I use:

cargo check
0
source

All Articles