add suggestions to clone_on_copy

also:

* don't report clone_on_copy when reporting clone_on_double_ref
* don't suggest `((x))`
This commit is contained in:
Oliver Schneider 2016-08-08 16:43:45 +02:00
parent ac5abcf593
commit 7e67f447ce
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46
3 changed files with 34 additions and 14 deletions

View file

@ -161,7 +161,13 @@ impl<'a> Sugg<'a> {
pub fn maybe_par(self) -> Self {
match self {
Sugg::NonParen(..) => self,
Sugg::MaybeParen(sugg) | Sugg::BinOp(_, sugg) => Sugg::NonParen(format!("({})", sugg).into()),
// (x) and (x).y() both don't need additional parens
Sugg::MaybeParen(sugg) => if sugg.starts_with('(') && sugg.ends_with(')') {
Sugg::MaybeParen(sugg)
} else {
Sugg::NonParen(format!("({})", sugg).into())
},
Sugg::BinOp(_, sugg) => Sugg::NonParen(format!("({})", sugg).into()),
}
}
}