Skip to content

Commit 5c995c7

Browse files
author
Isaac van Bakel
committed
Make Polonius report any found errors by default
It's a bit confusing that running Polonius on some Rust code that you know has a borrow error doesn't seem to actually do anything - it gives the impression that no analysis is performed by default. Of course, analysis *is* performed by default, but errors aren't reported unless you opt in (which begs the question of what exactly the tool is meant to be doing when you run it!) This changes the behaviour to print error tuples by default if any are found, for a better experience. The old behaviour can be re-enabled by using `--no-show-tuples` to suppress tuple output even if errors are present.
1 parent 0a754a9 commit 5c995c7

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ slower) -- these are the exact rules described in [the
3434
blogpost][post]. You can also use `-a LocationInsensitive` to use a
3535
location insensitive analysis (faster, but may yield spurious errors).
3636

37-
By default, `cargo run` just prints timing. If you also want to see
38-
the results, try `--show-tuples` (which will show errors) and maybe
39-
`-v` (to show more intermediate computations). You can supply `--help`
40-
to get more docs.
37+
By default, `cargo run` will print any errors found, but otherwise
38+
just prints timing. If you also want to see successful results, try
39+
`--show-tuples` and maybe `-v` (to show more intermediate computations).
40+
You can supply `--help` to get more docs.
4141

4242
### How to generate your own inputs
4343

book/src/getting_started.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ slower) -- these are the exact rules described in [the
1919
blogpost][post]. You can also use `-a LocationInsensitive` to use a
2020
location insensitive analysis (faster, but may yield spurious errors).
2121

22-
By default, `cargo run` just prints timing. If you also want to see
23-
the results, try `--show-tuples` (which will show errors) and maybe
24-
`-v` (to show more intermediate computations). You can supply `--help`
25-
to get more docs.
22+
By default, `cargo run` will print any errors found, but otherwise
23+
just prints timing. If you also want to see successful results, try
24+
`--show-tuples` and maybe `-v` (to show more intermediate computations).
25+
You can supply `--help` to get more docs.
2626

2727
[post]: http://smallcultfollowing.com/babysteps/blog/2018/04/27/an-alias-based-formulation-of-the-borrow-checker/

polonius-engine/src/output/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ impl<T: FactTypes> Output<T> {
514514
None => Cow::Owned(BTreeMap::default()),
515515
}
516516
}
517+
518+
pub fn has_errors(&self) -> bool {
519+
!(self.errors.is_empty() && self.move_errors.is_empty() && self.subset_errors.is_empty())
520+
}
517521
}
518522

519523
/// Compares errors reported by Naive implementation with the errors

src/cli.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
2222
#[derive(Debug)]
2323
pub struct Options {
2424
algorithm: Algorithm,
25-
show_tuples: bool,
25+
show_tuples: Option<bool>,
2626
skip_timing: bool,
2727
verbose: bool,
2828
graphviz_file: Option<String>,
@@ -81,7 +81,7 @@ pub fn main(opt: Options) -> Result<(), Error> {
8181
let millis = f64::from(duration.subsec_nanos()) * 0.000_000_001_f64;
8282
println!("Time: {:0.3}s", seconds + millis);
8383
}
84-
if opt.show_tuples {
84+
if opt.show_tuples.unwrap_or_else(|| output.has_errors()) {
8585
dump::dump_output(&output, &output_directory, tables)
8686
.expect("Failed to write output");
8787
}
@@ -131,11 +131,11 @@ USAGE:
131131
polonius [FLAGS] [OPTIONS] <fact_dirs>...
132132
133133
FLAGS:
134-
-h, --help Prints help information
135-
--show-tuples Show output tuples on stdout
136-
--skip-timing Do not display timing results
137-
-V, --version Prints version information
138-
-v, --verbose Show intermediate output tuples and not just errors
134+
-h, --help Prints help information
135+
--[no-]show-tuples Show output tuples on stdout, or suppress errors
136+
--skip-timing Do not display timing results
137+
-V, --version Prints version information
138+
-v, --verbose Show intermediate output tuples and not just errors
139139
140140
OPTIONS:
141141
-a <algorithm> [default: Naive]
@@ -163,7 +163,13 @@ ARGS:
163163
// 2) parse args
164164
let options = Options {
165165
algorithm: arg_from_str(&mut args, "-a")?.unwrap_or(Algorithm::Naive),
166-
show_tuples: args.contains("--show-tuples"),
166+
show_tuples: if args.contains("--show-tuples") {
167+
Some(true)
168+
} else if args.contains("--no-show-tuples") {
169+
Some(false)
170+
} else {
171+
None
172+
},
167173
skip_timing: args.contains("--skip-timing"),
168174
verbose: args.contains(["-v", "--verbose"]),
169175
graphviz_file: arg_from_str(&mut args, "--graphviz-file")?,

0 commit comments

Comments
 (0)