Skip to content

Commit

Permalink
Rollup merge of #99199 - TaKO8Ki:remove-unnecessary-span-to-snippet, …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Dylan-DPC authored Jul 13, 2022
2 parents 68cfdbb + f65bf0b commit 3933b2b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
21 changes: 9 additions & 12 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1598,21 +1598,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let return_ty = tcx.erase_regions(return_ty);

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

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ impl<'a> Resolver<'a> {
E0401,
"can't use generic parameters from outer function",
);
err.span_label(span, "use of generic parameter from outer function".to_string());
err.span_label(span, "use of generic parameter from outer function");

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

0 comments on commit 3933b2b

Please sign in to comment.