diff options
| author | ThibsG <thibsg@pm.me> | 2021-09-07 11:06:50 +0200 |
|---|---|---|
| committer | ThibsG <thibsg@pm.me> | 2021-11-20 09:40:11 +0100 |
| commit | e24aba2c1a8663c2ddebdae740689f8a7bdcadb7 (patch) | |
| tree | 71009674788e499be3a201beeff20a7c008224c1 | |
| parent | 6dca4f261d01584aac507379649458fbaf04d4c8 (diff) | |
| download | rust-e24aba2c1a8663c2ddebdae740689f8a7bdcadb7.tar.gz rust-e24aba2c1a8663c2ddebdae740689f8a7bdcadb7.zip | |
Use applicability for snippets
| -rw-r--r-- | clippy_lints/src/methods/search_is_some.rs | 11 |
1 files 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 b0bfe8d80e0..ec09bfd743d 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<BytePos>, 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; |
