Skip to content

Commit

Permalink
Fix the wrong use of snippet_with_applicability
Browse files Browse the repository at this point in the history
This includes a workaround of the issue rust-lang#5822,
the cause of this little mistake.
  • Loading branch information
rail-rain committed Aug 26, 2020
1 parent 64c4bb0 commit edc05da
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions clippy_lints/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,14 @@ impl EarlyLintPass for Write {
if let (Some(fmt_str), expr) = self.check_tts(cx, mac.args.inner_tokens(), true) {
if fmt_str.symbol == Symbol::intern("") {
let mut applicability = Applicability::MachineApplicable;
let suggestion = expr.map_or_else(
|| {
applicability = Applicability::HasPlaceholders;
Cow::Borrowed("v")
},
|e| snippet_with_applicability(cx, e.span, "v", &mut Applicability::MachineApplicable),
);
// FIXME: remove this `#[allow(...)]` once the issue #5822 gets fixed
#[allow(clippy::option_if_let_else)]
let suggestion = if let Some(e) = expr {
snippet_with_applicability(cx, e.span, "v", &mut applicability)
} else {
applicability = Applicability::HasPlaceholders;
Cow::Borrowed("v")
};

span_lint_and_sugg(
cx,
Expand Down

0 comments on commit edc05da

Please sign in to comment.