Skip to content

Commit 35bce11

Browse files
authored
Rollup merge of #94955 - TaKO8Ki:use-format-args-capture-in-rustc-parse, r=Dylan-DPC
Refactor: Use `format_args_capture` in some parts of `rustc_parse`
2 parents 2bd5c44 + 896b113 commit 35bce11

File tree

4 files changed

+60
-61
lines changed

4 files changed

+60
-61
lines changed

compiler/rustc_parse/src/parser/attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'a> Parser<'a> {
139139
Ok(attr::mk_attr_from_item(item, None, style, attr_sp))
140140
} else {
141141
let token_str = pprust::token_to_string(&this.token);
142-
let msg = &format!("expected `#`, found `{}`", token_str);
142+
let msg = &format!("expected `#`, found `{token_str}`");
143143
Err(this.struct_span_err(this.token.span, msg))
144144
}
145145
})
@@ -421,7 +421,7 @@ impl<'a> Parser<'a> {
421421
}
422422

423423
let found = pprust::token_to_string(&self.token);
424-
let msg = format!("expected unsuffixed literal or identifier, found `{}`", found);
424+
let msg = format!("expected unsuffixed literal or identifier, found `{found}`");
425425
Err(self.struct_span_err(self.token.span, &msg))
426426
}
427427
}

compiler/rustc_parse/src/parser/diagnostics.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ impl<'a> Parser<'a> {
327327
expect.clone()
328328
};
329329
(
330-
format!("expected one of {}, found {}", expect, actual),
331-
(self.prev_token.span.shrink_to_hi(), format!("expected one of {}", short_expect)),
330+
format!("expected one of {expect}, found {actual}"),
331+
(self.prev_token.span.shrink_to_hi(), format!("expected one of {short_expect}")),
332332
)
333333
} else if expected.is_empty() {
334334
(
@@ -337,8 +337,8 @@ impl<'a> Parser<'a> {
337337
)
338338
} else {
339339
(
340-
format!("expected {}, found {}", expect, actual),
341-
(self.prev_token.span.shrink_to_hi(), format!("expected {}", expect)),
340+
format!("expected {expect}, found {actual}"),
341+
(self.prev_token.span.shrink_to_hi(), format!("expected {expect}")),
342342
)
343343
};
344344
self.last_unexpected_token_span = Some(self.token.span);
@@ -421,7 +421,7 @@ impl<'a> Parser<'a> {
421421
String::new(),
422422
Applicability::MachineApplicable,
423423
);
424-
err.note(&format!("the raw string started with {} `#`s", n_hashes));
424+
err.note(&format!("the raw string started with {n_hashes} `#`s"));
425425
true
426426
}
427427
_ => false,
@@ -1191,7 +1191,7 @@ impl<'a> Parser<'a> {
11911191
_ => None,
11921192
};
11931193
if let Some(name) = previous_item_kind_name {
1194-
err.help(&format!("{} declarations are not followed by a semicolon", name));
1194+
err.help(&format!("{name} declarations are not followed by a semicolon"));
11951195
}
11961196
}
11971197
err.emit();
@@ -1226,12 +1226,12 @@ impl<'a> Parser<'a> {
12261226
"expected `{}`, found {}",
12271227
token_str,
12281228
match (&self.token.kind, self.subparser_name) {
1229-
(token::Eof, Some(origin)) => format!("end of {}", origin),
1229+
(token::Eof, Some(origin)) => format!("end of {origin}"),
12301230
_ => this_token_str,
12311231
},
12321232
);
12331233
let mut err = self.struct_span_err(sp, &msg);
1234-
let label_exp = format!("expected `{}`", token_str);
1234+
let label_exp = format!("expected `{token_str}`");
12351235
match self.recover_closing_delimiter(&[t.clone()], err) {
12361236
Err(e) => err = e,
12371237
Ok(recovered) => {
@@ -1368,7 +1368,7 @@ impl<'a> Parser<'a> {
13681368
Applicability::MachineApplicable,
13691369
);
13701370
}
1371-
err.span_suggestion(lo.shrink_to_lo(), &format!("{}you can still access the deprecated `try!()` macro using the \"raw identifier\" syntax", prefix), "r#".to_string(), Applicability::MachineApplicable);
1371+
err.span_suggestion(lo.shrink_to_lo(), &format!("{prefix}you can still access the deprecated `try!()` macro using the \"raw identifier\" syntax"), "r#".to_string(), Applicability::MachineApplicable);
13721372
err.emit();
13731373
Ok(self.mk_expr_err(lo.to(hi)))
13741374
} else {
@@ -1504,7 +1504,7 @@ impl<'a> Parser<'a> {
15041504
delim.retain(|c| c != '`');
15051505
err.span_suggestion_short(
15061506
self.prev_token.span.shrink_to_hi(),
1507-
&format!("`{}` may belong here", delim),
1507+
&format!("`{delim}` may belong here"),
15081508
delim,
15091509
Applicability::MaybeIncorrect,
15101510
);
@@ -1698,7 +1698,7 @@ impl<'a> Parser<'a> {
16981698
(
16991699
ident,
17001700
"self: ".to_string(),
1701-
format!("{}: &{}TypeName", ident, mutab),
1701+
format!("{ident}: &{mutab}TypeName"),
17021702
"_: ".to_string(),
17031703
pat.span.shrink_to_lo(),
17041704
pat.span,
@@ -1826,7 +1826,7 @@ impl<'a> Parser<'a> {
18261826
let (span, msg) = match (&self.token.kind, self.subparser_name) {
18271827
(&token::Eof, Some(origin)) => {
18281828
let sp = self.sess.source_map().next_point(self.prev_token.span);
1829-
(sp, format!("expected expression, found end of {}", origin))
1829+
(sp, format!("expected expression, found end of {origin}"))
18301830
}
18311831
_ => (
18321832
self.token.span,
@@ -1975,8 +1975,8 @@ impl<'a> Parser<'a> {
19751975
(ty_generics, self.sess.source_map().span_to_snippet(param.span()))
19761976
{
19771977
let (span, sugg) = match &generics.params[..] {
1978-
[] => (generics.span, format!("<{}>", snippet)),
1979-
[.., generic] => (generic.span().shrink_to_hi(), format!(", {}", snippet)),
1978+
[] => (generics.span, format!("<{snippet}>")),
1979+
[.., generic] => (generic.span().shrink_to_hi(), format!(", {snippet}")),
19801980
};
19811981
err.multipart_suggestion(
19821982
"`const` parameters must be declared for the `impl`",

compiler/rustc_parse/src/parser/expr.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'a> Parser<'a> {
223223
AssocOp::NotEqual => "!=",
224224
_ => unreachable!(),
225225
};
226-
self.struct_span_err(sp, &format!("invalid comparison operator `{}=`", sugg))
226+
self.struct_span_err(sp, &format!("invalid comparison operator `{sugg}=`"))
227227
.span_suggestion_short(
228228
sp,
229229
&format!("`{s}=` is not a valid comparison operator, use `{s}`", s = sugg),
@@ -441,10 +441,10 @@ impl<'a> Parser<'a> {
441441

442442
/// Error on `and` and `or` suggesting `&&` and `||` respectively.
443443
fn error_bad_logical_op(&self, bad: &str, good: &str, english: &str) {
444-
self.struct_span_err(self.token.span, &format!("`{}` is not a logical operator", bad))
444+
self.struct_span_err(self.token.span, &format!("`{bad}` is not a logical operator"))
445445
.span_suggestion_short(
446446
self.token.span,
447-
&format!("use `{}` to perform logical {}", good, english),
447+
&format!("use `{good}` to perform logical {english}"),
448448
good.to_string(),
449449
Applicability::MachineApplicable,
450450
)
@@ -766,9 +766,9 @@ impl<'a> Parser<'a> {
766766
self.look_ahead(1, |t| t.span).to(span_after_type),
767767
"interpreted as generic arguments",
768768
)
769-
.span_label(self.token.span, format!("not interpreted as {}", op_noun))
769+
.span_label(self.token.span, format!("not interpreted as {op_noun}"))
770770
.multipart_suggestion(
771-
&format!("try {} the cast value", op_verb),
771+
&format!("try {op_verb} the cast value"),
772772
vec![
773773
(expr.span.shrink_to_lo(), "(".to_string()),
774774
(expr.span.shrink_to_hi(), ")".to_string()),
@@ -970,7 +970,7 @@ impl<'a> Parser<'a> {
970970
fn error_unexpected_after_dot(&self) {
971971
// FIXME Could factor this out into non_fatal_unexpected or something.
972972
let actual = pprust::token_to_string(&self.token);
973-
self.struct_span_err(self.token.span, &format!("unexpected token: `{}`", actual)).emit();
973+
self.struct_span_err(self.token.span, &format!("unexpected token: `{actual}`")).emit();
974974
}
975975

976976
// We need an identifier or integer, but the next token is a float.
@@ -1151,15 +1151,15 @@ impl<'a> Parser<'a> {
11511151
mem::replace(err, replacement_err).cancel();
11521152

11531153
err.multipart_suggestion(
1154-
&format!("if `{}` is a struct, use braces as delimiters", name),
1154+
&format!("if `{name}` is a struct, use braces as delimiters"),
11551155
vec![
11561156
(open_paren, " { ".to_string()),
11571157
(close_paren, " }".to_string()),
11581158
],
11591159
Applicability::MaybeIncorrect,
11601160
);
11611161
err.multipart_suggestion(
1162-
&format!("if `{}` is a function, use the arguments directly", name),
1162+
&format!("if `{name}` is a function, use the arguments directly"),
11631163
fields
11641164
.into_iter()
11651165
.map(|field| (field.span.until(field.expr.span), String::new()))
@@ -1776,9 +1776,9 @@ impl<'a> Parser<'a> {
17761776
)
17771777
.emit();
17781778
} else {
1779-
let msg = format!("invalid suffix `{}` for number literal", suf);
1779+
let msg = format!("invalid suffix `{suf}` for number literal");
17801780
self.struct_span_err(span, &msg)
1781-
.span_label(span, format!("invalid suffix `{}`", suf))
1781+
.span_label(span, format!("invalid suffix `{suf}`"))
17821782
.help("the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)")
17831783
.emit();
17841784
}
@@ -1791,9 +1791,9 @@ impl<'a> Parser<'a> {
17911791
let msg = format!("invalid width `{}` for float literal", &suf[1..]);
17921792
self.struct_span_err(span, &msg).help("valid widths are 32 and 64").emit();
17931793
} else {
1794-
let msg = format!("invalid suffix `{}` for float literal", suf);
1794+
let msg = format!("invalid suffix `{suf}` for float literal");
17951795
self.struct_span_err(span, &msg)
1796-
.span_label(span, format!("invalid suffix `{}`", suf))
1796+
.span_label(span, format!("invalid suffix `{suf}`"))
17971797
.help("valid suffixes are `f32` and `f64`")
17981798
.emit();
17991799
}
@@ -1805,7 +1805,7 @@ impl<'a> Parser<'a> {
18051805
2 => "binary",
18061806
_ => unreachable!(),
18071807
};
1808-
self.struct_span_err(span, &format!("{} float literal is not supported", descr))
1808+
self.struct_span_err(span, &format!("{descr} float literal is not supported"))
18091809
.span_label(span, "not supported")
18101810
.emit();
18111811
}
@@ -1825,7 +1825,7 @@ impl<'a> Parser<'a> {
18251825
let mut err = self
18261826
.sess
18271827
.span_diagnostic
1828-
.struct_span_warn(sp, &format!("suffixes on {} are invalid", kind));
1828+
.struct_span_warn(sp, &format!("suffixes on {kind} are invalid"));
18291829
err.note(&format!(
18301830
"`{}` is *temporarily* accepted on tuple index fields as it was \
18311831
incorrectly accepted on stable for a few releases",
@@ -1842,10 +1842,10 @@ impl<'a> Parser<'a> {
18421842
);
18431843
err
18441844
} else {
1845-
self.struct_span_err(sp, &format!("suffixes on {} are invalid", kind))
1845+
self.struct_span_err(sp, &format!("suffixes on {kind} are invalid"))
18461846
.forget_guarantee()
18471847
};
1848-
err.span_label(sp, format!("invalid suffix `{}`", suf));
1848+
err.span_label(sp, format!("invalid suffix `{suf}`"));
18491849
err.emit();
18501850
}
18511851
}
@@ -2211,7 +2211,7 @@ impl<'a> Parser<'a> {
22112211
let ctx = if is_ctx_else { "else" } else { "if" };
22122212
self.struct_span_err(last, "outer attributes are not allowed on `if` and `else` branches")
22132213
.span_label(branch_span, "the attributes are attached to this branch")
2214-
.span_label(ctx_span, format!("the branch belongs to this `{}`", ctx))
2214+
.span_label(ctx_span, format!("the branch belongs to this `{ctx}`"))
22152215
.span_suggestion(
22162216
span,
22172217
"remove the attributes",
@@ -2391,7 +2391,7 @@ impl<'a> Parser<'a> {
23912391
err.span_label(arrow_span, "while parsing the `match` arm starting here");
23922392
if stmts.len() > 1 {
23932393
err.multipart_suggestion(
2394-
&format!("surround the statement{} with a body", s),
2394+
&format!("surround the statement{s} with a body"),
23952395
vec![
23962396
(span.shrink_to_lo(), "{ ".to_string()),
23972397
(span.shrink_to_hi(), " }".to_string()),

0 commit comments

Comments
 (0)