Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite and refactor format_args!() builtin macro. #100996

Merged
merged 14 commits into from
Sep 28, 2022
Prev Previous commit
Next Next commit
Add clarifying comments.
  • Loading branch information
m-ou-se committed Sep 27, 2022
commit c1c6e3ae7c6c1d268b1d0f608e58d74f863d572b
3 changes: 3 additions & 0 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,15 @@ pub fn make_format_args(
.iter()
.position(|arg| arg.1.ident().is_some_and(|id| id.name == name))
{
// Name found in `args`, so we resolve it to its index in that Vec.
let index = start_of_named_args + i;
if !matches!(args[index].1, FormatArgKind::Captured(_)) {
// Mark it as used, if it was an explicit argument.
used[index] = true;
}
Ok(index)
} else {
// Name not found in `args`, so we add it as an implicitly captured argument.
let span = span.unwrap_or(fmt_span);
let ident = Ident::new(name, span);
let arg = if is_literal {
Expand Down