diff --git a/README.md b/README.md index de8c15f21a..3e301855c5 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,10 @@ slower) -- these are the exact rules described in [the blogpost][post]. You can also use `-a LocationInsensitive` to use a location insensitive analysis (faster, but may yield spurious errors). -By default, `cargo run` just prints timing. If you also want to see -the results, try `--show-tuples` (which will show errors) and maybe -`-v` (to show more intermediate computations). You can supply `--help` -to get more docs. +By default, `cargo run` will print any errors found, but otherwise +just prints timing. If you also want to see successful results, try +`--show-tuples` and maybe `-v` (to show more intermediate computations). +You can supply `--help` to get more docs. ### How to generate your own inputs diff --git a/book/src/getting_started.md b/book/src/getting_started.md index 1a3520c94d..f4c6cec6fc 100644 --- a/book/src/getting_started.md +++ b/book/src/getting_started.md @@ -19,9 +19,9 @@ slower) -- these are the exact rules described in [the blogpost][post]. You can also use `-a LocationInsensitive` to use a location insensitive analysis (faster, but may yield spurious errors). -By default, `cargo run` just prints timing. If you also want to see -the results, try `--show-tuples` (which will show errors) and maybe -`-v` (to show more intermediate computations). You can supply `--help` -to get more docs. +By default, `cargo run` will print any errors found, but otherwise +just prints timing. If you also want to see successful results, try +`--show-tuples` and maybe `-v` (to show more intermediate computations). +You can supply `--help` to get more docs. [post]: http://smallcultfollowing.com/babysteps/blog/2018/04/27/an-alias-based-formulation-of-the-borrow-checker/ diff --git a/polonius-engine/src/output/mod.rs b/polonius-engine/src/output/mod.rs index b840e4bec8..cd37aeaa1f 100644 --- a/polonius-engine/src/output/mod.rs +++ b/polonius-engine/src/output/mod.rs @@ -514,6 +514,10 @@ impl Output { None => Cow::Owned(BTreeMap::default()), } } + + pub fn has_errors(&self) -> bool { + !(self.errors.is_empty() && self.move_errors.is_empty() && self.subset_errors.is_empty()) + } } /// Compares errors reported by Naive implementation with the errors diff --git a/src/cli.rs b/src/cli.rs index 2d1e23ce94..e43e3650a8 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -22,7 +22,7 @@ const PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION"); #[derive(Debug)] pub struct Options { algorithm: Algorithm, - show_tuples: bool, + show_tuples: Option, skip_timing: bool, verbose: bool, graphviz_file: Option, @@ -81,7 +81,7 @@ pub fn main(opt: Options) -> Result<(), Error> { let millis = f64::from(duration.subsec_nanos()) * 0.000_000_001_f64; println!("Time: {:0.3}s", seconds + millis); } - if opt.show_tuples { + if opt.show_tuples.unwrap_or_else(|| output.has_errors()) { dump::dump_output(&output, &output_directory, tables) .expect("Failed to write output"); } @@ -131,11 +131,11 @@ USAGE: polonius [FLAGS] [OPTIONS] ... FLAGS: - -h, --help Prints help information - --show-tuples Show output tuples on stdout - --skip-timing Do not display timing results - -V, --version Prints version information - -v, --verbose Show intermediate output tuples and not just errors + -h, --help Prints help information + --[no-]show-tuples Show output tuples on stdout, or suppress errors + --skip-timing Do not display timing results + -V, --version Prints version information + -v, --verbose Show intermediate output tuples and not just errors OPTIONS: -a [default: Naive] @@ -163,7 +163,13 @@ ARGS: // 2) parse args let options = Options { algorithm: arg_from_str(&mut args, "-a")?.unwrap_or(Algorithm::Naive), - show_tuples: args.contains("--show-tuples"), + show_tuples: if args.contains("--show-tuples") { + Some(true) + } else if args.contains("--no-show-tuples") { + Some(false) + } else { + None + }, skip_timing: args.contains("--skip-timing"), verbose: args.contains(["-v", "--verbose"]), graphviz_file: arg_from_str(&mut args, "--graphviz-file")?,