From e24aba2c1a8663c2ddebdae740689f8a7bdcadb7 Mon Sep 17 00:00:00 2001 From: ThibsG Date: Tue, 7 Sep 2021 11:06:50 +0200 Subject: [PATCH] Use applicability for snippets --- clippy_lints/src/methods/search_is_some.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs index b0bfe8d80e0d..ec09bfd743d0 100644 --- a/clippy_lints/src/methods/search_is_some.rs +++ b/clippy_lints/src/methods/search_is_some.rs @@ -167,6 +167,7 @@ fn get_closure_suggestion<'tcx>( next_pos: None, suggestion_start: String::new(), suggestion_end: String::new(), + applicability: Applicability::MachineApplicable, }; let fn_def_id = cx.tcx.hir().local_def_id(search_arg.hir_id); @@ -188,6 +189,7 @@ struct DerefDelegate<'a, 'tcx> { next_pos: Option, suggestion_start: String, suggestion_end: String, + applicability: Applicability, } impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { @@ -203,9 +205,9 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { } else { self.closure_span.until(span) }; - let start_snip = snippet(self.cx, start_span, ".."); + let start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability); let end_span = Span::new(span.hi(), self.closure_span.hi(), span.ctxt()); - let end_snip = snippet(self.cx, end_span, ".."); + let end_snip = snippet_with_applicability(self.cx, end_span, "..", &mut self.applicability); if cmt.place.projections.is_empty() { // handle item without any projection, that needs an explicit borrowing @@ -227,11 +229,14 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> { } else { self.closure_span.until(span) }; - let start_snip = snippet(self.cx, start_span, ".."); + let start_snip = + snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability); self.suggestion_start.push_str(&format!("{}&{}", start_snip, ident_str)); self.suggestion_end = end_snip.to_string(); self.next_pos = Some(span.hi()); + } else { + self.applicability = Applicability::Unspecified; } } return;