Skip to content

Commit 6cba515

Browse files
authored
Rollup merge of rust-lang#99718 - TaKO8Ki:avoid-&str-symbol-to-string-conversions, r=michaelwoerister
Avoid `&str`/`Symbol` to `String` conversions follow-up to rust-lang#99342 and rust-lang#98668
2 parents 0d25480 + 051e98b commit 6cba515

File tree

7 files changed

+19
-25
lines changed

7 files changed

+19
-25
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -850,13 +850,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
850850
debug!("trait spans found: {:?}", traits);
851851
for span in &traits {
852852
let mut multi_span: MultiSpan = vec![*span].into();
853-
multi_span.push_span_label(
854-
*span,
855-
"this has an implicit `'static` lifetime requirement".to_string(),
856-
);
853+
multi_span
854+
.push_span_label(*span, "this has an implicit `'static` lifetime requirement");
857855
multi_span.push_span_label(
858856
ident.span,
859-
"calling this method introduces the `impl`'s 'static` requirement".to_string(),
857+
"calling this method introduces the `impl`'s 'static` requirement",
860858
);
861859
err.span_note(multi_span, "the used `impl` has a `'static` requirement");
862860
err.span_suggestion_verbose(

Diff for: compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ fn adt_defined_here<'p, 'tcx>(
951951
let mut span: MultiSpan =
952952
if spans.is_empty() { def_span.into() } else { spans.clone().into() };
953953

954-
span.push_span_label(def_span, String::new());
954+
span.push_span_label(def_span, "");
955955
for pat in spans {
956956
span.push_span_label(pat, "not covered");
957957
}

Diff for: compiler/rustc_resolve/src/diagnostics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,7 @@ impl<'a> Resolver<'a> {
565565
} else if let Some(sp) = sm.generate_fn_name_span(span) {
566566
err.span_label(
567567
sp,
568-
"try adding a local generic parameter in this method instead"
569-
.to_string(),
568+
"try adding a local generic parameter in this method instead",
570569
);
571570
} else {
572571
err.help("try using a local generic parameter instead");

Diff for: compiler/rustc_span/src/source_map.rs

-11
Original file line numberDiff line numberDiff line change
@@ -586,17 +586,6 @@ impl SourceMap {
586586
}
587587
}
588588

589-
/// Returns whether or not this span points into a file
590-
/// in the current crate. This may be `false` for spans
591-
/// produced by a macro expansion, or for spans associated
592-
/// with the definition of an item in a foreign crate
593-
pub fn is_local_span(&self, sp: Span) -> bool {
594-
let local_begin = self.lookup_byte_offset(sp.lo());
595-
let local_end = self.lookup_byte_offset(sp.hi());
596-
// This might be a weird span that covers multiple files
597-
local_begin.sf.src.is_some() && local_end.sf.src.is_some()
598-
}
599-
600589
pub fn is_span_accessible(&self, sp: Span) -> bool {
601590
self.span_to_source(sp, |src, start_index, end_index| {
602591
Ok(src.get(start_index..end_index).is_some())

Diff for: compiler/rustc_typeck/src/astconv/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::ty;
88
use rustc_session::parse::feature_err;
99
use rustc_span::lev_distance::find_best_match_for_name;
1010
use rustc_span::symbol::{sym, Ident};
11-
use rustc_span::{Span, DUMMY_SP};
11+
use rustc_span::{Span, Symbol, DUMMY_SP};
1212

1313
use std::collections::BTreeSet;
1414

@@ -17,7 +17,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
1717
/// the type parameter's name as a placeholder.
1818
pub(crate) fn complain_about_missing_type_params(
1919
&self,
20-
missing_type_params: Vec<String>,
20+
missing_type_params: Vec<Symbol>,
2121
def_id: DefId,
2222
span: Span,
2323
empty_generic_args: bool,

Diff for: compiler/rustc_typeck/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
382382
def_id: DefId,
383383
generic_args: &'a GenericArgs<'a>,
384384
span: Span,
385-
missing_type_params: Vec<String>,
385+
missing_type_params: Vec<Symbol>,
386386
inferred_params: Vec<Span>,
387387
infer_args: bool,
388388
is_object: bool,
@@ -514,7 +514,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
514514
// defaults. This will lead to an ICE if we are not
515515
// careful!
516516
if self.default_needs_object_self(param) {
517-
self.missing_type_params.push(param.name.to_string());
517+
self.missing_type_params.push(param.name);
518518
tcx.ty_error().into()
519519
} else {
520520
// This is a default type parameter.

Diff for: compiler/rustc_typeck/src/errors.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ pub struct UnconstrainedOpaqueType {
244244
pub struct MissingTypeParams {
245245
pub span: Span,
246246
pub def_span: Span,
247-
pub missing_type_params: Vec<String>,
247+
pub missing_type_params: Vec<Symbol>,
248248
pub empty_generic_args: bool,
249249
}
250250

@@ -285,7 +285,15 @@ impl<'a> SessionDiagnostic<'a> for MissingTypeParams {
285285
err.span_suggestion(
286286
self.span,
287287
rustc_errors::fluent::typeck::suggestion,
288-
format!("{}<{}>", snippet, self.missing_type_params.join(", ")),
288+
format!(
289+
"{}<{}>",
290+
snippet,
291+
self.missing_type_params
292+
.iter()
293+
.map(|n| n.to_string())
294+
.collect::<Vec<_>>()
295+
.join(", ")
296+
),
289297
Applicability::HasPlaceholders,
290298
);
291299
suggested = true;

0 commit comments

Comments
 (0)