mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #138125 - thaliaarchi:defer-alloc-printf-suggestion, r=compiler-errors
Simplify `printf` and shell format suggestions Simplify tracking `printf` and shell format suggestions. Although allocations could be deferred until after checking that they aren't already in the map, this style is simpler.
This commit is contained in:
commit
a928c15066
@ -711,11 +711,9 @@ fn report_missing_placeholders(
|
||||
};
|
||||
|
||||
let pos = sub.position();
|
||||
let sub = String::from(sub.as_str());
|
||||
if explained.contains(&sub) {
|
||||
if !explained.insert(sub.to_string()) {
|
||||
continue;
|
||||
}
|
||||
explained.insert(sub);
|
||||
|
||||
if !found_foreign {
|
||||
found_foreign = true;
|
||||
|
@ -12,14 +12,16 @@ pub(crate) mod printf {
|
||||
Escape((usize, usize)),
|
||||
}
|
||||
|
||||
impl<'a> Substitution<'a> {
|
||||
pub(crate) fn as_str(&self) -> &str {
|
||||
impl ToString for Substitution<'_> {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
Substitution::Format(fmt) => fmt.span,
|
||||
Substitution::Escape(_) => "%%",
|
||||
Substitution::Format(fmt) => fmt.span.into(),
|
||||
Substitution::Escape(_) => "%%".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Substitution<'_> {
|
||||
pub(crate) fn position(&self) -> InnerSpan {
|
||||
match self {
|
||||
Substitution::Format(fmt) => fmt.position,
|
||||
@ -627,15 +629,17 @@ pub(crate) mod shell {
|
||||
Escape((usize, usize)),
|
||||
}
|
||||
|
||||
impl Substitution<'_> {
|
||||
pub(crate) fn as_str(&self) -> String {
|
||||
impl ToString for Substitution<'_> {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
Substitution::Ordinal(n, _) => format!("${n}"),
|
||||
Substitution::Name(n, _) => format!("${n}"),
|
||||
Substitution::Escape(_) => "$$".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Substitution<'_> {
|
||||
pub(crate) fn position(&self) -> InnerSpan {
|
||||
let (Self::Ordinal(_, pos) | Self::Name(_, pos) | Self::Escape(pos)) = self;
|
||||
InnerSpan::new(pos.0, pos.1)
|
||||
|
Loading…
Reference in New Issue
Block a user