inline format!() args up to and including rustc_middle
This commit is contained in:
parent
2e0136a131
commit
23815467a2
87 changed files with 378 additions and 437 deletions
|
@ -575,7 +575,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
|
|||
|| named_pos.contains_key(&idx)
|
||||
|| args.reg_args.contains(idx)
|
||||
{
|
||||
let msg = format!("invalid reference to argument at index {}", idx);
|
||||
let msg = format!("invalid reference to argument at index {idx}");
|
||||
let mut err = ecx.struct_span_err(span, msg);
|
||||
err.span_label(span, "from here");
|
||||
|
||||
|
@ -588,9 +588,9 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
|
|||
""
|
||||
};
|
||||
let msg = match positional_args {
|
||||
0 => format!("no {}arguments were given", positional),
|
||||
1 => format!("there is 1 {}argument", positional),
|
||||
x => format!("there are {} {}arguments", x, positional),
|
||||
0 => format!("no {positional}arguments were given"),
|
||||
1 => format!("there is 1 {positional}argument"),
|
||||
x => format!("there are {x} {positional}arguments"),
|
||||
};
|
||||
err.note(msg);
|
||||
|
||||
|
@ -624,7 +624,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
|
|||
match args.named_args.get(&Symbol::intern(name)) {
|
||||
Some(&idx) => Some(idx),
|
||||
None => {
|
||||
let msg = format!("there is no argument named `{}`", name);
|
||||
let msg = format!("there is no argument named `{name}`");
|
||||
let span = arg.position_span;
|
||||
ecx.struct_span_err(
|
||||
template_span
|
||||
|
@ -697,8 +697,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
|
|||
err.span_label(sp, msg);
|
||||
err.help(format!(
|
||||
"if this argument is intentionally unused, \
|
||||
consider using it in an asm comment: `\"/*{} */\"`",
|
||||
help_str
|
||||
consider using it in an asm comment: `\"/*{help_str} */\"`"
|
||||
));
|
||||
err.emit();
|
||||
}
|
||||
|
@ -712,8 +711,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
|
|||
}
|
||||
err.help(format!(
|
||||
"if these arguments are intentionally unused, \
|
||||
consider using them in an asm comment: `\"/*{} */\"`",
|
||||
help_str
|
||||
consider using them in an asm comment: `\"/*{help_str} */\"`"
|
||||
));
|
||||
err.emit();
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ fn cs_clone_simple(
|
|||
}
|
||||
_ => cx.span_bug(
|
||||
trait_span,
|
||||
format!("unexpected substructure in simple `derive({})`", name),
|
||||
format!("unexpected substructure in simple `derive({name})`"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
@ -178,10 +178,10 @@ fn cs_clone(
|
|||
vdata = &variant.data;
|
||||
}
|
||||
EnumTag(..) | AllFieldlessEnum(..) => {
|
||||
cx.span_bug(trait_span, format!("enum tags in `derive({})`", name,))
|
||||
cx.span_bug(trait_span, format!("enum tags in `derive({name})`",))
|
||||
}
|
||||
StaticEnum(..) | StaticStruct(..) => {
|
||||
cx.span_bug(trait_span, format!("associated function in `derive({})`", name))
|
||||
cx.span_bug(trait_span, format!("associated function in `derive({name})`"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ fn cs_clone(
|
|||
let Some(ident) = field.name else {
|
||||
cx.span_bug(
|
||||
trait_span,
|
||||
format!("unnamed field in normal struct in `derive({})`", name,),
|
||||
format!("unnamed field in normal struct in `derive({name})`",),
|
||||
);
|
||||
};
|
||||
let call = subcall(cx, field);
|
||||
|
|
|
@ -204,7 +204,7 @@ where
|
|||
let fields = fields
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, &span)| getarg(cx, span, Symbol::intern(&format!("_field{}", i)), i))
|
||||
.map(|(i, &span)| getarg(cx, span, Symbol::intern(&format!("_field{i}")), i))
|
||||
.collect();
|
||||
|
||||
cx.expr_call(trait_span, path_expr, fields)
|
||||
|
|
|
@ -173,7 +173,7 @@ fn encodable_substructure(
|
|||
for (i, &FieldInfo { name, ref self_expr, span, .. }) in fields.iter().enumerate() {
|
||||
let name = match name {
|
||||
Some(id) => id.name,
|
||||
None => Symbol::intern(&format!("_field{}", i)),
|
||||
None => Symbol::intern(&format!("_field{i}")),
|
||||
};
|
||||
let self_ref = cx.expr_addr_of(span, self_expr.clone());
|
||||
let enc =
|
||||
|
|
|
@ -1166,7 +1166,7 @@ impl<'a> MethodDef<'a> {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.skip(1)
|
||||
.map(|(arg_count, _selflike_arg)| format!("__arg{}", arg_count)),
|
||||
.map(|(arg_count, _selflike_arg)| format!("__arg{arg_count}")),
|
||||
)
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
|
@ -1181,7 +1181,7 @@ impl<'a> MethodDef<'a> {
|
|||
let get_tag_pieces = |cx: &ExtCtxt<'_>| {
|
||||
let tag_idents: Vec<_> = prefixes
|
||||
.iter()
|
||||
.map(|name| Ident::from_str_and_span(&format!("{}_tag", name), span))
|
||||
.map(|name| Ident::from_str_and_span(&format!("{name}_tag"), span))
|
||||
.collect();
|
||||
|
||||
let mut tag_exprs: Vec<_> = tag_idents
|
||||
|
@ -1521,7 +1521,7 @@ impl<'a> TraitDef<'a> {
|
|||
}
|
||||
|
||||
fn mk_pattern_ident(&self, prefix: &str, i: usize) -> Ident {
|
||||
Ident::from_str_and_span(&format!("{}_{}", prefix, i), self.span)
|
||||
Ident::from_str_and_span(&format!("{prefix}_{i}"), self.span)
|
||||
}
|
||||
|
||||
fn create_struct_pattern_fields(
|
||||
|
@ -1602,8 +1602,7 @@ impl<'a> TraitDef<'a> {
|
|||
sp,
|
||||
ast::CRATE_NODE_ID,
|
||||
format!(
|
||||
"{} slice in a packed struct that derives a built-in trait",
|
||||
ty
|
||||
"{ty} slice in a packed struct that derives a built-in trait"
|
||||
),
|
||||
rustc_lint_defs::BuiltinLintDiagnostics::ByteSliceInPackedStructWithDerive
|
||||
);
|
||||
|
|
|
@ -179,7 +179,7 @@ fn make_format_args(
|
|||
err.span_suggestion(
|
||||
unexpanded_fmt_span.shrink_to_lo(),
|
||||
"you might be missing a string literal to format with",
|
||||
format!("\"{}\", ", sugg_fmt),
|
||||
format!("\"{sugg_fmt}\", "),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
@ -668,7 +668,7 @@ fn report_invalid_references(
|
|||
let num_args_desc = match args.explicit_args().len() {
|
||||
0 => "no arguments were given".to_string(),
|
||||
1 => "there is 1 argument".to_string(),
|
||||
n => format!("there are {} arguments", n),
|
||||
n => format!("there are {n} arguments"),
|
||||
};
|
||||
|
||||
let mut e;
|
||||
|
@ -780,7 +780,7 @@ fn report_invalid_references(
|
|||
if num_placeholders == 1 {
|
||||
"is 1 argument".to_string()
|
||||
} else {
|
||||
format!("are {} arguments", num_placeholders)
|
||||
format!("are {num_placeholders} arguments")
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -811,7 +811,7 @@ fn report_invalid_references(
|
|||
};
|
||||
e = ecx.struct_span_err(
|
||||
span,
|
||||
format!("invalid reference to positional {} ({})", arg_list, num_args_desc),
|
||||
format!("invalid reference to positional {arg_list} ({num_args_desc})"),
|
||||
);
|
||||
e.note("positional arguments are zero-based");
|
||||
}
|
||||
|
|
|
@ -86,10 +86,7 @@ pub(crate) mod printf {
|
|||
'-' => c_left = true,
|
||||
'+' => c_plus = true,
|
||||
_ => {
|
||||
return Err(Some(format!(
|
||||
"the flag `{}` is unknown or unsupported",
|
||||
c
|
||||
)));
|
||||
return Err(Some(format!("the flag `{c}` is unknown or unsupported")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -268,21 +265,21 @@ pub(crate) mod printf {
|
|||
impl Num {
|
||||
fn from_str(s: &str, arg: Option<&str>) -> Self {
|
||||
if let Some(arg) = arg {
|
||||
Num::Arg(arg.parse().unwrap_or_else(|_| panic!("invalid format arg `{:?}`", arg)))
|
||||
Num::Arg(arg.parse().unwrap_or_else(|_| panic!("invalid format arg `{arg:?}`")))
|
||||
} else if s == "*" {
|
||||
Num::Next
|
||||
} else {
|
||||
Num::Num(s.parse().unwrap_or_else(|_| panic!("invalid format num `{:?}`", s)))
|
||||
Num::Num(s.parse().unwrap_or_else(|_| panic!("invalid format num `{s:?}`")))
|
||||
}
|
||||
}
|
||||
|
||||
fn translate(&self, s: &mut String) -> std::fmt::Result {
|
||||
use std::fmt::Write;
|
||||
match *self {
|
||||
Num::Num(n) => write!(s, "{}", n),
|
||||
Num::Num(n) => write!(s, "{n}"),
|
||||
Num::Arg(n) => {
|
||||
let n = n.checked_sub(1).ok_or(std::fmt::Error)?;
|
||||
write!(s, "{}$", n)
|
||||
write!(s, "{n}$")
|
||||
}
|
||||
Num::Next => write!(s, "*"),
|
||||
}
|
||||
|
@ -626,8 +623,8 @@ pub mod shell {
|
|||
impl Substitution<'_> {
|
||||
pub fn as_str(&self) -> String {
|
||||
match self {
|
||||
Substitution::Ordinal(n, _) => format!("${}", n),
|
||||
Substitution::Name(n, _) => format!("${}", n),
|
||||
Substitution::Ordinal(n, _) => format!("${n}"),
|
||||
Substitution::Name(n, _) => format!("${n}"),
|
||||
Substitution::Escape(_) => "$$".into(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ impl AllocFnFactory<'_, '_> {
|
|||
let mut abi_args = ThinVec::new();
|
||||
let mut i = 0;
|
||||
let mut mk = || {
|
||||
let name = Ident::from_str_and_span(&format!("arg{}", i), self.span);
|
||||
let name = Ident::from_str_and_span(&format!("arg{i}"), self.span);
|
||||
i += 1;
|
||||
name
|
||||
};
|
||||
|
|
|
@ -179,8 +179,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
|
|||
== prev_item.path.segments[0].ident.name
|
||||
{
|
||||
format!(
|
||||
"only one `#[{}]` attribute is allowed on any given function",
|
||||
path_str,
|
||||
"only one `#[{path_str}]` attribute is allowed on any given function",
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
|
|
|
@ -149,7 +149,7 @@ pub fn expand_include<'cx>(
|
|||
Ok(None) => {
|
||||
if self.p.token != token::Eof {
|
||||
let token = pprust::token_to_string(&self.p.token);
|
||||
let msg = format!("expected item, found `{}`", token);
|
||||
let msg = format!("expected item, found `{token}`");
|
||||
self.p.struct_span_err(self.p.token.span, msg).emit();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue