Skip to content

Commit 5188bdb

Browse files
committed
remove an unnecessary span_to_snippet
1 parent 1c7b36d commit 5188bdb

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -1598,21 +1598,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15981598
let return_ty = tcx.erase_regions(return_ty);
15991599

16001600
// to avoid panics
1601-
if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator) {
1602-
if self
1601+
if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator)
1602+
&& self
16031603
.infcx
16041604
.type_implements_trait(iter_trait, return_ty, ty_params, self.param_env)
16051605
.must_apply_modulo_regions()
1606-
{
1607-
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(return_span) {
1608-
err.span_suggestion_hidden(
1609-
return_span,
1610-
"use `.collect()` to allocate the iterator",
1611-
format!("{snippet}.collect::<Vec<_>>()"),
1612-
Applicability::MaybeIncorrect,
1613-
);
1614-
}
1615-
}
1606+
{
1607+
err.span_suggestion_hidden(
1608+
return_span.shrink_to_hi(),
1609+
"use `.collect()` to allocate the iterator",
1610+
".collect::<Vec<_>>()",
1611+
Applicability::MaybeIncorrect,
1612+
);
16161613
}
16171614
}
16181615

0 commit comments

Comments
 (0)