Skip to content

Commit 2458ccd

Browse files
committed
Simplify printf and shell format suggestions
1 parent 30f168e commit 2458ccd

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

compiler/rustc_builtin_macros/src/format.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,9 @@ fn report_missing_placeholders(
711711
};
712712

713713
let pos = sub.position();
714-
let sub = String::from(sub.as_str());
715-
if explained.contains(&sub) {
714+
if !explained.insert(sub.to_string()) {
716715
continue;
717716
}
718-
explained.insert(sub);
719717

720718
if !found_foreign {
721719
found_foreign = true;

compiler/rustc_builtin_macros/src/format_foreign.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ pub(crate) mod printf {
1212
Escape((usize, usize)),
1313
}
1414

15-
impl<'a> Substitution<'a> {
16-
pub(crate) fn as_str(&self) -> &str {
15+
impl ToString for Substitution<'_> {
16+
fn to_string(&self) -> String {
1717
match self {
18-
Substitution::Format(fmt) => fmt.span,
19-
Substitution::Escape(_) => "%%",
18+
Substitution::Format(fmt) => fmt.span.into(),
19+
Substitution::Escape(_) => "%%".into(),
2020
}
2121
}
22+
}
2223

24+
impl Substitution<'_> {
2325
pub(crate) fn position(&self) -> InnerSpan {
2426
match self {
2527
Substitution::Format(fmt) => fmt.position,
@@ -627,15 +629,17 @@ pub(crate) mod shell {
627629
Escape((usize, usize)),
628630
}
629631

630-
impl Substitution<'_> {
631-
pub(crate) fn as_str(&self) -> String {
632+
impl ToString for Substitution<'_> {
633+
fn to_string(&self) -> String {
632634
match self {
633635
Substitution::Ordinal(n, _) => format!("${n}"),
634636
Substitution::Name(n, _) => format!("${n}"),
635637
Substitution::Escape(_) => "$$".into(),
636638
}
637639
}
640+
}
638641

642+
impl Substitution<'_> {
639643
pub(crate) fn position(&self) -> InnerSpan {
640644
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
641645
InnerSpan::new(pos.0, pos.1)

0 commit comments

Comments
 (0)