tidy: Add a rule ensuring that // comments are followed by a space in Rust (#38698)

This shows up sometimes in code reviews, so it makes sense that tidy
enforces it. `rustfmt` supports this via comment normalization, but it
does many other things and is still an unstable feature (with bugs).

Testing: There are new tidy tests for this change.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-08-18 05:09:09 -07:00 committed by GitHub
parent 8ca00a3b0c
commit 8743a11ba4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
68 changed files with 169 additions and 152 deletions

View file

@ -555,6 +555,9 @@ def check_rust(file_name: str, lines: list[bytes]) -> Iterator[tuple[int, str]]:
return
for idx, line in enumerate(map(lambda line: line.decode("utf-8"), lines)):
for match in re.finditer(r"(;|\s|^)//\w", line):
yield (idx + 1, "Comments starting with `//` should also include a space")
line = re.sub(r"//.*?$|/\*.*?$|^\*.*?$", "//", line)
rules = [
# There should be any use of banned types: