1
Fork 0

remove an unnecessary span_to_snippet

This commit is contained in:
Takayuki Maeda 2022-07-13 13:24:06 +09:00
parent 1c7b36d4db
commit 5188bdbccd

View file

@ -1598,23 +1598,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let return_ty = tcx.erase_regions(return_ty); let return_ty = tcx.erase_regions(return_ty);
// to avoid panics // to avoid panics
if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator) { if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator)
if self && self
.infcx .infcx
.type_implements_trait(iter_trait, return_ty, ty_params, self.param_env) .type_implements_trait(iter_trait, return_ty, ty_params, self.param_env)
.must_apply_modulo_regions() .must_apply_modulo_regions()
{ {
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(return_span) {
err.span_suggestion_hidden( err.span_suggestion_hidden(
return_span, return_span.shrink_to_hi(),
"use `.collect()` to allocate the iterator", "use `.collect()` to allocate the iterator",
format!("{snippet}.collect::<Vec<_>>()"), ".collect::<Vec<_>>()",
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
); );
} }
} }
}
}
Some(err) Some(err)
} }