Skip to content

Commit 6212e6b

Browse files
committed
avoid many &str to String conversions with MultiSpan::push_span_label
1 parent 0e1a6fb commit 6212e6b

File tree

17 files changed

+38
-66
lines changed

17 files changed

+38
-66
lines changed

compiler/rustc_expand/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
136136
let mut msp = MultiSpan::from_span(primary_span);
137137
for span_label in span_labels {
138138
let span = make_span(&file_text, &span_label.start, &span_label.end);
139-
msp.push_span_label(span, span_label.label.to_string());
139+
msp.push_span_label(span, span_label.label);
140140
println!("span: {:?} label: {:?}", span, span_label.label);
141141
println!("text: {:?}", source_map.span_to_snippet(span));
142142
}

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,18 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
194194
if !v.0.is_empty() {
195195
span = v.0.clone().into();
196196
for sp in v.0 {
197-
span.push_span_label(
198-
sp,
199-
"`'static` requirement introduced here".to_string(),
200-
);
197+
span.push_span_label(sp, "`'static` requirement introduced here");
201198
}
202199
add_label = false;
203200
}
204201
}
205202
if add_label {
206203
span.push_span_label(
207204
fn_decl.output.span(),
208-
"requirement introduced by this return type".to_string(),
205+
"requirement introduced by this return type",
209206
);
210207
}
211-
span.push_span_label(
212-
cause.span,
213-
"because of this returned expression".to_string(),
214-
);
208+
span.push_span_label(cause.span, "because of this returned expression");
215209
err.span_note(
216210
span,
217211
"`'static` lifetime requirement introduced by the return type",
@@ -523,13 +517,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
523517
hir_v.visit_ty(&self_ty);
524518
for span in &traits {
525519
let mut multi_span: MultiSpan = vec![*span].into();
526-
multi_span.push_span_label(
527-
*span,
528-
"this has an implicit `'static` lifetime requirement".to_string(),
529-
);
520+
multi_span
521+
.push_span_label(*span, "this has an implicit `'static` lifetime requirement");
530522
multi_span.push_span_label(
531523
ident.span,
532-
"calling this method introduces the `impl`'s 'static` requirement".to_string(),
524+
"calling this method introduces the `impl`'s 'static` requirement",
533525
);
534526
err.span_note(multi_span, "the used `impl` has a `'static` requirement");
535527
err.span_suggestion_verbose(

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
128128
}
129129
let mut type_param_span: MultiSpan = visitor.types.to_vec().into();
130130
for &span in &visitor.types {
131-
type_param_span.push_span_label(
132-
span,
133-
"consider borrowing this type parameter in the trait".to_string(),
134-
);
131+
type_param_span
132+
.push_span_label(span, "consider borrowing this type parameter in the trait");
135133
}
136134

137135
err.note(&format!("expected `{}`\n found `{}`", expected, found));

compiler/rustc_infer/src/traits/error_reporting/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ pub fn report_object_safety_error<'tcx>(
8585
let has_multi_span = !multi_span.is_empty();
8686
let mut note_span = MultiSpan::from_spans(multi_span.clone());
8787
if let (Some(trait_span), true) = (trait_span, has_multi_span) {
88-
note_span
89-
.push_span_label(trait_span, "this trait cannot be made into an object...".to_string());
88+
note_span.push_span_label(trait_span, "this trait cannot be made into an object...");
9089
}
9190
for (span, msg) in iter::zip(multi_span, messages) {
9291
note_span.push_span_label(span, msg);

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ fn adt_defined_here<'p, 'tcx>(
947947

948948
span.push_span_label(def_span, String::new());
949949
for pat in spans {
950-
span.push_span_label(pat, "not covered".to_string());
950+
span.push_span_label(pat, "not covered");
951951
}
952952
err.span_note(span, &format!("`{}` defined here", ty));
953953
}

compiler/rustc_parse/src/parser/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -887,22 +887,19 @@ impl<'a> Parser<'a> {
887887
let mut first_note = MultiSpan::from(vec![initial_semicolon]);
888888
first_note.push_span_label(
889889
initial_semicolon,
890-
"this `;` turns the preceding closure into a statement".to_string(),
890+
"this `;` turns the preceding closure into a statement",
891891
);
892892
first_note.push_span_label(
893893
closure_spans.body,
894-
"this expression is a statement because of the trailing semicolon".to_string(),
894+
"this expression is a statement because of the trailing semicolon",
895895
);
896896
expect_err.span_note(first_note, "statement found outside of a block");
897897

898898
let mut second_note = MultiSpan::from(vec![closure_spans.whole_closure]);
899-
second_note.push_span_label(
900-
closure_spans.whole_closure,
901-
"this is the parsed closure...".to_string(),
902-
);
899+
second_note.push_span_label(closure_spans.whole_closure, "this is the parsed closure...");
903900
second_note.push_span_label(
904901
following_token_span,
905-
"...but likely you meant the closure to end here".to_string(),
902+
"...but likely you meant the closure to end here",
906903
);
907904
expect_err.span_note(second_note, "the closure body may be incorrectly delimited");
908905

compiler/rustc_passes/src/check_attr.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -857,11 +857,8 @@ impl CheckAttrVisitor<'_> {
857857
if let Some((prev_inline, prev_span)) = *specified_inline {
858858
if do_inline != prev_inline {
859859
let mut spans = MultiSpan::from_spans(vec![prev_span, meta.span()]);
860-
spans.push_span_label(prev_span, String::from("this attribute..."));
861-
spans.push_span_label(
862-
meta.span(),
863-
String::from("...conflicts with this attribute"),
864-
);
860+
spans.push_span_label(prev_span, "this attribute...");
861+
spans.push_span_label(meta.span(), "...conflicts with this attribute");
865862
self.tcx
866863
.sess
867864
.struct_span_err(spans, "conflicting doc inlining attributes")

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,7 @@ fn show_candidates(
25612561
let span = source_span[local_def_id];
25622562
let span = session.source_map().guess_head_span(span);
25632563
let mut multi_span = MultiSpan::from_span(span);
2564-
multi_span.push_span_label(span, "not accessible".to_string());
2564+
multi_span.push_span_label(span, "not accessible");
25652565
err.span_note(multi_span, &msg);
25662566
} else {
25672567
err.note(&msg);

compiler/rustc_resolve/src/late/diagnostics.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,8 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
601601
};
602602
multi_span.push_span_label(sp, msg);
603603
}
604-
multi_span.push_span_label(
605-
base_error.span,
606-
"expected this type to be a trait...".to_string(),
607-
);
604+
multi_span
605+
.push_span_label(base_error.span, "expected this type to be a trait...");
608606
err.span_help(
609607
multi_span,
610608
"`+` is used to constrain a \"trait object\" type with lifetimes or \
@@ -1227,17 +1225,14 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
12271225
let mut m: MultiSpan = non_visible_spans.clone().into();
12281226
non_visible_spans
12291227
.into_iter()
1230-
.for_each(|s| m.push_span_label(s, "private field".to_string()));
1228+
.for_each(|s| m.push_span_label(s, "private field"));
12311229
err.span_note(m, "constructor is not visible here due to private fields");
12321230
}
12331231

12341232
return true;
12351233
}
12361234

1237-
err.span_label(
1238-
span,
1239-
"constructor is not visible here due to private fields".to_string(),
1240-
);
1235+
err.span_label(span, "constructor is not visible here due to private fields");
12411236
}
12421237
(
12431238
Res::Def(

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2204,8 +2204,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
22042204
_ => true,
22052205
};
22062206
if !ident.span.overlaps(span) && !same_line {
2207-
multispan
2208-
.push_span_label(ident.span, "required by a bound in this".to_string());
2207+
multispan.push_span_label(ident.span, "required by a bound in this");
22092208
}
22102209
}
22112210
let descr = format!("required by a bound in `{}`", item_name);

compiler/rustc_typeck/src/astconv/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
645645
err.emit();
646646
} else {
647647
let mut multispan = MultiSpan::from_span(span);
648-
multispan.push_span_label(span_late, note.to_string());
648+
multispan.push_span_label(span_late, note);
649649
tcx.struct_span_lint_hir(
650650
LATE_BOUND_LIFETIME_ARGUMENTS,
651651
args.args[0].id(),

compiler/rustc_typeck/src/check/_match.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
154154
ret_span.push_span_label(
155155
expr.span,
156156
"this could be implicitly returned but it is a statement, not a \
157-
tail expression"
158-
.to_owned(),
159-
);
160-
ret_span.push_span_label(
161-
ret,
162-
"the `match` arms can conform to this return type".to_owned(),
157+
tail expression",
163158
);
159+
ret_span
160+
.push_span_label(ret, "the `match` arms can conform to this return type");
164161
ret_span.push_span_label(
165162
semi_span,
166163
"the `match` is a statement because of this semicolon, consider \
167-
removing it"
168-
.to_owned(),
164+
removing it",
169165
);
170166
err.span_note(
171167
ret_span,

compiler/rustc_typeck/src/check/check.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1591,8 +1591,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) -> E
15911591
} else {
15921592
let mut multispan: MultiSpan = spans.clone().into();
15931593
for span in spans {
1594-
multispan
1595-
.push_span_label(span, "this returned value is of `!` type".to_string());
1594+
multispan.push_span_label(span, "this returned value is of `!` type");
15961595
}
15971596
err.span_note(multispan, "these returned values have a concrete \"never\" type");
15981597
}

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10341034
);
10351035
sp.push_span_label(
10361036
rcvr.span,
1037-
"you probably want to use this value after calling the method...".to_string(),
1037+
"you probably want to use this value after calling the method...",
10381038
);
10391039
err.span_note(
10401040
sp,

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,7 @@ fn label_fn_like<'tcx>(
17681768
.flat_map(|id| tcx.hir().body(id).params);
17691769

17701770
for param in params {
1771-
spans.push_span_label(param.span, String::new());
1771+
spans.push_span_label(param.span, "");
17721772
}
17731773

17741774
let def_kind = tcx.def_kind(def_id);

compiler/rustc_typeck/src/check/method/suggest.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
638638
let parent_trait_ref = data.parent_trait_pred;
639639
let path = parent_trait_ref.print_modifiers_and_trait_path();
640640
let tr_self_ty = parent_trait_ref.skip_binder().self_ty();
641-
let unsatisfied_msg = "unsatisfied trait bound introduced here".to_string();
641+
let unsatisfied_msg = "unsatisfied trait bound introduced here";
642642
let derive_msg =
643643
"unsatisfied trait bound introduced in this `derive` macro";
644644
match self.tcx.hir().get_if_local(impl_def_id) {
@@ -655,7 +655,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
655655
{
656656
let span = ident.span.ctxt().outer_expn_data().call_site;
657657
let mut spans: MultiSpan = span.into();
658-
spans.push_span_label(span, derive_msg.to_string());
658+
spans.push_span_label(span, derive_msg);
659659
let entry = spanned_predicates.entry(spans);
660660
entry.or_insert_with(|| (path, tr_self_ty, Vec::new())).2.push(p);
661661
}
@@ -678,7 +678,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
678678
{
679679
let span = self_ty.span.ctxt().outer_expn_data().call_site;
680680
let mut spans: MultiSpan = span.into();
681-
spans.push_span_label(span, derive_msg.to_string());
681+
spans.push_span_label(span, derive_msg);
682682
let entry = spanned_predicates.entry(spans);
683683
entry.or_insert_with(|| (path, tr_self_ty, Vec::new())).2.push(p);
684684
}
@@ -706,7 +706,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
706706
} else {
707707
ident.span.into()
708708
};
709-
spans.push_span_label(ident.span, "in this trait".to_string());
709+
spans.push_span_label(ident.span, "in this trait");
710710
let entry = spanned_predicates.entry(spans);
711711
entry.or_insert_with(|| (path, tr_self_ty, Vec::new())).2.push(p);
712712
}
@@ -747,9 +747,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
747747
spans.into()
748748
};
749749
if let Some(trait_ref) = of_trait {
750-
spans.push_span_label(trait_ref.path.span, String::new());
750+
spans.push_span_label(trait_ref.path.span, "");
751751
}
752-
spans.push_span_label(self_ty.span, String::new());
752+
spans.push_span_label(self_ty.span, "");
753753

754754
let entry = spanned_predicates.entry(spans);
755755
entry.or_insert_with(|| (path, tr_self_ty, Vec::new())).2.push(p);

compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
836836
.take(bound)
837837
.map(|param| {
838838
let span = self.tcx.def_span(param.def_id);
839-
spans.push_span_label(span, String::new());
839+
spans.push_span_label(span, "");
840840
param
841841
})
842842
.map(|param| format!("`{}`", param.name))

0 commit comments

Comments
 (0)