From 152987eb5461fad5cbaf012c7cf1afeacdba063b Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 4 Nov 2026 00:05:18 -0800 Subject: [PATCH] Read a wrapped macro argument as part of its member in the API signatures The nightly's rustfmt wraps ir_id!(TypeId, "t") one argument per line, so the signature script, which reads a macro call's members line by line, derived `TypeId,` where the table holds `TypeId, "t"`, and api_signatures failed with nothing public changed. A member line that is only an identifier and a comma now takes the literal on the next line with it, which reads the wrapped call as the unwrapped one did; a member with more on its line (Degradation's rows, whose prose follows on its own line) is read as before. Verified: signatures.py --check passes with the committed table unchanged, on this tree and on bc127dbec3's pre-nightly sources; metal2vulkan's api_signatures test passes on the nightly. --- scripts/api-signatures/signatures.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/api-signatures/signatures.py b/scripts/api-signatures/signatures.py index 7f28bb196..795250e1c 100644 --- a/scripts/api-signatures/signatures.py +++ b/scripts/api-signatures/signatures.py @@ -132,6 +132,7 @@ VIS = re.compile(r"^pub(\s*\([^)]*\))?\s+") KEEP_ATTRS = re.compile(r"^#\[(cfg|cfg_attr|non_exhaustive|derive|repr|must_use|deprecated|" r"track_caller|doc\(hidden)") IDENT = re.compile(r"[A-Za-z_][A-Za-z0-9_]*") +BARE_ARG = re.compile(r"[A-Za-z_][A-Za-z0-9_]*,") MACROCALL = re.compile(r"^([a-z_][a-z0-9_]*)\s*!\s*[{(\[]") MODIFIERS = ("default ", "unsafe ", "async ", 'extern "C" ', 'extern "system" ', "const ") KINDS = ("fn ", "struct ", "enum ", "trait ", "type ", "const ", "static ", "mod ", "union ") @@ -756,6 +757,11 @@ def collect(crate, names, real, home, extra=()): if nm is None: continue add("macro-decl", key(nm), it.name + "! " + nm) + # A member is a line that starts with an identifier. Where `cargo fmt` + # wrapped a call one argument per line, a member line that is only its + # identifier and a comma takes the literal on the next line with it: + # `TypeId,` then `"t"` reads as `TypeId, "t"`, as the unwrapped call did. + member = None at = it.body[0] while at < it.body[1]: eol = code.find("\n", at) @@ -767,8 +773,15 @@ def collect(crate, names, real, home, extra=()): line = norm(raw) mo = IDENT.match(line) if mo and line not in ("}", "{"): - add("macro-member", key(nm, "::" + mo.group(0)), line) + if member: + add("macro-member", *member) + member = [key(nm, "::" + mo.group(0)), line] + elif (member and BARE_ARG.fullmatch(member[1]) and not bare.strip() + and raw.lstrip().startswith(('"', "'", 'r"', "r#", 'b"'))): + member[1] += " " + norm(raw) at = eol + 1 + if member: + add("macro-member", *member) return recs, defs