Skip to content

Commit 4b21ad2

Browse files
authored
Rollup merge of rust-lang#99508 - TaKO8Ki:avoid-symbol-to-string-conversion-in-BuiltinLintDiagnostics, r=compiler-errors
Avoid `Symbol` to `String` conversions follow-up to rust-lang#99342
2 parents 73ef81d + 56e7777 commit 4b21ad2

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

compiler/rustc_builtin_macros/src/format.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,7 @@ fn lint_named_arguments_used_positionally(
10041004
node_id: ast::CRATE_NODE_ID,
10051005
lint_id: LintId::of(&NAMED_ARGUMENTS_USED_POSITIONALLY),
10061006
diagnostic: BuiltinLintDiagnostics::NamedArgumentUsedPositionally(
1007-
arg_span,
1008-
span,
1009-
symbol.to_string(),
1007+
arg_span, span, symbol,
10101008
),
10111009
});
10121010
}

compiler/rustc_errors/src/diagnostic.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,17 @@ impl Diagnostic {
390390
expected: DiagnosticStyledString,
391391
found: DiagnosticStyledString,
392392
) -> &mut Self {
393-
let mut msg: Vec<_> =
394-
vec![("required when trying to coerce from type `".to_string(), Style::NoStyle)];
393+
let mut msg: Vec<_> = vec![("required when trying to coerce from type `", Style::NoStyle)];
395394
msg.extend(expected.0.iter().map(|x| match *x {
396-
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
397-
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
395+
StringPart::Normal(ref s) => (s.as_str(), Style::NoStyle),
396+
StringPart::Highlighted(ref s) => (s.as_str(), Style::Highlight),
398397
}));
399-
msg.push(("` to type '".to_string(), Style::NoStyle));
398+
msg.push(("` to type '", Style::NoStyle));
400399
msg.extend(found.0.iter().map(|x| match *x {
401-
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
402-
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
400+
StringPart::Normal(ref s) => (s.as_str(), Style::NoStyle),
401+
StringPart::Highlighted(ref s) => (s.as_str(), Style::Highlight),
403402
}));
404-
msg.push(("`".to_string(), Style::NoStyle));
403+
msg.push(("`", Style::NoStyle));
405404

406405
// For now, just attach these as notes
407406
self.highlighted_note(msg);

compiler/rustc_lint_defs/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ pub enum BuiltinLintDiagnostics {
467467
/// If true, the lifetime will be fully elided.
468468
use_span: Option<(Span, bool)>,
469469
},
470-
NamedArgumentUsedPositionally(Option<Span>, Span, String),
470+
NamedArgumentUsedPositionally(Option<Span>, Span, Symbol),
471471
}
472472

473473
/// Lints that are buffered up early on in the `Session` before the

compiler/rustc_resolve/src/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2603,9 +2603,9 @@ fn show_candidates(
26032603
.skip(1)
26042604
.all(|(_, descr, _, _)| descr == descr_first)
26052605
{
2606-
descr_first.to_string()
2606+
descr_first
26072607
} else {
2608-
"item".to_string()
2608+
"item"
26092609
};
26102610
let plural_descr =
26112611
if descr.ends_with("s") { format!("{}es", descr) } else { format!("{}s", descr) };

0 commit comments

Comments
 (0)