Skip to content

Commit e24aba2

Browse files
committed
Use applicability for snippets
1 parent 6dca4f2 commit e24aba2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

clippy_lints/src/methods/search_is_some.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ fn get_closure_suggestion<'tcx>(
167167
next_pos: None,
168168
suggestion_start: String::new(),
169169
suggestion_end: String::new(),
170+
applicability: Applicability::MachineApplicable,
170171
};
171172

172173
let fn_def_id = cx.tcx.hir().local_def_id(search_arg.hir_id);
@@ -188,6 +189,7 @@ struct DerefDelegate<'a, 'tcx> {
188189
next_pos: Option<BytePos>,
189190
suggestion_start: String,
190191
suggestion_end: String,
192+
applicability: Applicability,
191193
}
192194

193195
impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
@@ -203,9 +205,9 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
203205
} else {
204206
self.closure_span.until(span)
205207
};
206-
let start_snip = snippet(self.cx, start_span, "..");
208+
let start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);
207209
let end_span = Span::new(span.hi(), self.closure_span.hi(), span.ctxt());
208-
let end_snip = snippet(self.cx, end_span, "..");
210+
let end_snip = snippet_with_applicability(self.cx, end_span, "..", &mut self.applicability);
209211

210212
if cmt.place.projections.is_empty() {
211213
// handle item without any projection, that needs an explicit borrowing
@@ -227,11 +229,14 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
227229
} else {
228230
self.closure_span.until(span)
229231
};
230-
let start_snip = snippet(self.cx, start_span, "..");
232+
let start_snip =
233+
snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);
231234

232235
self.suggestion_start.push_str(&format!("{}&{}", start_snip, ident_str));
233236
self.suggestion_end = end_snip.to_string();
234237
self.next_pos = Some(span.hi());
238+
} else {
239+
self.applicability = Applicability::Unspecified;
235240
}
236241
}
237242
return;

0 commit comments

Comments
 (0)