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
Flatten if-let and match into one.
  • Loading branch information
m-ou-se committed Sep 27, 2022
commit 8d9a5881ea18568f014ea09ec9d2f1d0cdacff1b
33 changes: 14 additions & 19 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,26 +285,21 @@ pub fn make_format_args(
-> FormatArgPosition {
let index = match arg {
Index(index) => {
if let Some((_, arg_kind)) = args.get(index) {
match arg_kind {
FormatArgKind::Normal => {
used[index] = true;
Ok(index)
}
FormatArgKind::Named(_) => {
used[index] = true;
numeric_refences_to_named_arg.push((index, span, used_as));
Ok(index)
}
FormatArgKind::Captured(_) => {
// Doesn't exist as an explicit argument.
invalid_refs.push((index, span, used_as, kind));
Err(index)
}
match args.get(index) {
Some((_, FormatArgKind::Normal)) => {
used[index] = true;
Ok(index)
}
Some((_, FormatArgKind::Named(_))) => {
used[index] = true;
numeric_refences_to_named_arg.push((index, span, used_as));
Ok(index)
}
Some((_, FormatArgKind::Captured(_))) | None => {
// Doesn't exist as an explicit argument.
invalid_refs.push((index, span, used_as, kind));
Err(index)
}
} else {
invalid_refs.push((index, span, used_as, kind));
Err(index)
}
}
Name(name, span) => {
Expand Down