Auto merge of #4589 - mikerite:booleans-refactor-20190925, r=phansch

Refactor `booleans`

Remove unused output from `suggest(..)`

changelog: none
This commit is contained in:
bors 2019-09-27 06:16:55 +00:00
commit bca08a65df

View file

@ -156,7 +156,6 @@ struct SuggestContext<'a, 'tcx, 'v> {
terminals: &'v [&'v Expr], terminals: &'v [&'v Expr],
cx: &'a LateContext<'a, 'tcx>, cx: &'a LateContext<'a, 'tcx>,
output: String, output: String,
simplified: bool,
} }
impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> { impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
@ -179,7 +178,6 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
Term(n) => { Term(n) => {
let terminal = self.terminals[n as usize]; let terminal = self.terminals[n as usize];
if let Some(str) = simplify_not(self.cx, terminal) { if let Some(str) = simplify_not(self.cx, terminal) {
self.simplified = true;
self.output.push_str(&str) self.output.push_str(&str)
} else { } else {
self.output.push('!'); self.output.push('!');
@ -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 {
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr]) -> (String, bool) {
let mut suggest_context = SuggestContext { let mut suggest_context = SuggestContext {
terminals, terminals,
cx, cx,
output: String::new(), output: String::new(),
simplified: false,
}; };
suggest_context.recurse(suggestion); suggest_context.recurse(suggestion);
(suggest_context.output, suggest_context.simplified) suggest_context.output
} }
fn simple_negate(b: Bool) -> Bool { fn simple_negate(b: Bool) -> Bool {
@ -383,7 +379,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
db.span_suggestion( db.span_suggestion(
e.span, e.span,
"it would look like the following", "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 // nonminimal_bool can produce minimal but
// not human readable expressions (#3141) // not human readable expressions (#3141)
Applicability::Unspecified, Applicability::Unspecified,
@ -428,7 +424,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
nonminimal_bool_lint( nonminimal_bool_lint(
improvements improvements
.into_iter() .into_iter()
.map(|suggestion| suggest(self.cx, suggestion, &h2q.terminals).0) .map(|suggestion| suggest(self.cx, suggestion, &h2q.terminals))
.collect(), .collect(),
); );
} }