Rollup merge of #98668 - TaKO8Ki:avoid-many-&str-to-string-conversions, r=Dylan-DPC

Avoid some `&str` to `String` conversions with `MultiSpan::push_span_label`

This patch removes some`&str` to `String` conversions with `MultiSpan::push_span_label`.
This commit is contained in:
Matthias Krüger 2022-06-29 20:35:07 +02:00 committed by GitHub
commit d34c4ca9be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 38 additions and 66 deletions

View file

@ -194,10 +194,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
if !v.0.is_empty() {
span = v.0.clone().into();
for sp in v.0 {
span.push_span_label(
sp,
"`'static` requirement introduced here".to_string(),
);
span.push_span_label(sp, "`'static` requirement introduced here");
}
add_label = false;
}
@ -205,13 +202,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
if add_label {
span.push_span_label(
fn_decl.output.span(),
"requirement introduced by this return type".to_string(),
"requirement introduced by this return type",
);
}
span.push_span_label(
cause.span,
"because of this returned expression".to_string(),
);
span.push_span_label(cause.span, "because of this returned expression");
err.span_note(
span,
"`'static` lifetime requirement introduced by the return type",
@ -523,13 +517,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
hir_v.visit_ty(&self_ty);
for span in &traits {
let mut multi_span: MultiSpan = vec![*span].into();
multi_span.push_span_label(
*span,
"this has an implicit `'static` lifetime requirement".to_string(),
);
multi_span
.push_span_label(*span, "this has an implicit `'static` lifetime requirement");
multi_span.push_span_label(
ident.span,
"calling this method introduces the `impl`'s 'static` requirement".to_string(),
"calling this method introduces the `impl`'s 'static` requirement",
);
err.span_note(multi_span, "the used `impl` has a `'static` requirement");
err.span_suggestion_verbose(

View file

@ -128,10 +128,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
}
let mut type_param_span: MultiSpan = visitor.types.to_vec().into();
for &span in &visitor.types {
type_param_span.push_span_label(
span,
"consider borrowing this type parameter in the trait".to_string(),
);
type_param_span
.push_span_label(span, "consider borrowing this type parameter in the trait");
}
err.note(&format!("expected `{}`\n found `{}`", expected, found));

View file

@ -85,8 +85,7 @@ pub fn report_object_safety_error<'tcx>(
let has_multi_span = !multi_span.is_empty();
let mut note_span = MultiSpan::from_spans(multi_span.clone());
if let (Some(trait_span), true) = (trait_span, has_multi_span) {
note_span
.push_span_label(trait_span, "this trait cannot be made into an object...".to_string());
note_span.push_span_label(trait_span, "this trait cannot be made into an object...");
}
for (span, msg) in iter::zip(multi_span, messages) {
note_span.push_span_label(span, msg);