Skip to content

Commit 3933b2b

Browse files
authored
Rollup merge of #99199 - TaKO8Ki:remove-unnecessary-span-to-snippet, r=cjgillot
Refactor: remove an unnecessary `span_to_snippet` `span_suggestion_hidden` does not show the suggested code and the suggestion is used just for rustfix, so `span_to_snippet` is unnecessary here.
2 parents 68cfdbb + f65bf0b commit 3933b2b

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
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

compiler/rustc_resolve/src/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ impl<'a> Resolver<'a> {
508508
E0401,
509509
"can't use generic parameters from outer function",
510510
);
511-
err.span_label(span, "use of generic parameter from outer function".to_string());
511+
err.span_label(span, "use of generic parameter from outer function");
512512

513513
let sm = self.session.source_map();
514514
match outer_res {
@@ -990,7 +990,7 @@ impl<'a> Resolver<'a> {
990990
E0735,
991991
"generic parameters cannot use `Self` in their defaults"
992992
);
993-
err.span_label(span, "`Self` in generic parameter default".to_string());
993+
err.span_label(span, "`Self` in generic parameter default");
994994
err
995995
}
996996
ResolutionError::UnreachableLabel { name, definition_span, suggestion } => {

0 commit comments

Comments
 (0)