mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Fix #2245
This commit is contained in:
parent
0b0337d258
commit
f65a022ace
1 changed files with 9 additions and 8 deletions
|
@ -167,8 +167,8 @@ struct SuggestContext<'a, 'tcx: 'a, 'v> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
|
impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
|
||||||
fn snip(&self, e: &Expr) -> String {
|
fn snip(&self, e: &Expr) -> Option<String> {
|
||||||
snippet_opt(self.cx, e.span).expect("don't try to improve booleans created by macros")
|
snippet_opt(self.cx, e.span)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn simplify_not(&self, expr: &Expr) -> Option<String> {
|
fn simplify_not(&self, expr: &Expr) -> Option<String> {
|
||||||
|
@ -182,20 +182,20 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
|
||||||
BiLe => Some(" > "),
|
BiLe => Some(" > "),
|
||||||
BiGe => Some(" < "),
|
BiGe => Some(" < "),
|
||||||
_ => None,
|
_ => None,
|
||||||
}.map(|op| format!("{}{}{}", self.snip(lhs), op, self.snip(rhs)))
|
}.and_then(|op| Some(format!("{}{}{}", self.snip(lhs)?, op, self.snip(rhs)?)))
|
||||||
},
|
},
|
||||||
ExprMethodCall(ref path, _, ref args) if args.len() == 1 => {
|
ExprMethodCall(ref path, _, ref args) if args.len() == 1 => {
|
||||||
METHODS_WITH_NEGATION
|
METHODS_WITH_NEGATION
|
||||||
.iter().cloned()
|
.iter().cloned()
|
||||||
.flat_map(|(a, b)| vec![(a, b), (b, a)])
|
.flat_map(|(a, b)| vec![(a, b), (b, a)])
|
||||||
.find(|&(a, _)| a == path.name.as_str())
|
.find(|&(a, _)| a == path.name.as_str())
|
||||||
.map(|(_, neg_method)| format!("{}.{}()", self.snip(&args[0]), neg_method))
|
.and_then(|(_, neg_method)| Some(format!("{}.{}()", self.snip(&args[0])?, neg_method)))
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recurse(&mut self, suggestion: &Bool) {
|
fn recurse(&mut self, suggestion: &Bool) -> Option<()> {
|
||||||
use quine_mc_cluskey::Bool::*;
|
use quine_mc_cluskey::Bool::*;
|
||||||
match *suggestion {
|
match *suggestion {
|
||||||
True => {
|
True => {
|
||||||
|
@ -218,13 +218,13 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
|
||||||
self.output.push_str(&str)
|
self.output.push_str(&str)
|
||||||
} else {
|
} else {
|
||||||
self.output.push('!');
|
self.output.push('!');
|
||||||
let snip = self.snip(terminal);
|
let snip = self.snip(terminal)?;
|
||||||
self.output.push_str(&snip);
|
self.output.push_str(&snip);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
True | False | Not(_) => {
|
True | False | Not(_) => {
|
||||||
self.output.push('!');
|
self.output.push('!');
|
||||||
self.recurse(inner)
|
self.recurse(inner)?;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
And(ref v) => {
|
And(ref v) => {
|
||||||
|
@ -250,10 +250,11 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Term(n) => {
|
Term(n) => {
|
||||||
let snip = self.snip(self.terminals[n as usize]);
|
let snip = self.snip(self.terminals[n as usize])?;
|
||||||
self.output.push_str(&snip);
|
self.output.push_str(&snip);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Some(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue