Skip to content

Commit

Permalink
Auto merge of rust-lang#4589 - mikerite:booleans-refactor-20190925, r…
Browse files Browse the repository at this point in the history
…=phansch

Refactor `booleans`

Remove unused output from `suggest(..)`

changelog: none
  • Loading branch information
bors committed Sep 27, 2019
2 parents f7d7456 + 8b9415c commit bca08a6
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ struct SuggestContext<'a, 'tcx, 'v> {
terminals: &'v [&'v Expr],
cx: &'a LateContext<'a, 'tcx>,
output: String,
simplified: bool,
}

impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
Expand All @@ -179,7 +178,6 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
Term(n) => {
let terminal = self.terminals[n as usize];
if let Some(str) = simplify_not(self.cx, terminal) {
self.simplified = true;
self.output.push_str(&str)
} else {
self.output.push('!');
Expand Down Expand Up @@ -264,16 +262,14 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<String> {
}
}

// The boolean part of the return indicates whether some simplifications have been applied.
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr]) -> (String, bool) {
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr]) -> String {
let mut suggest_context = SuggestContext {
terminals,
cx,
output: String::new(),
simplified: false,
};
suggest_context.recurse(suggestion);
(suggest_context.output, suggest_context.simplified)
suggest_context.output
}

fn simple_negate(b: Bool) -> Bool {
Expand Down Expand Up @@ -383,7 +379,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
db.span_suggestion(
e.span,
"it would look like the following",
suggest(self.cx, suggestion, &h2q.terminals).0,
suggest(self.cx, suggestion, &h2q.terminals),
// nonminimal_bool can produce minimal but
// not human readable expressions (#3141)
Applicability::Unspecified,
Expand Down Expand Up @@ -428,7 +424,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
nonminimal_bool_lint(
improvements
.into_iter()
.map(|suggestion| suggest(self.cx, suggestion, &h2q.terminals).0)
.map(|suggestion| suggest(self.cx, suggestion, &h2q.terminals))
.collect(),
);
}
Expand Down

0 comments on commit bca08a6

Please sign in to comment.