Skip to content

Rust: add documentation for AST nodes #19630

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

Merged
merged 12 commits into from
Jun 4, 2025
Merged

Rust: add documentation for AST nodes #19630

merged 12 commits into from
Jun 4, 2025

Conversation

aibaars
Copy link
Contributor

@aibaars aibaars commented May 30, 2025

This pull request adds missing documentation for Rust AST nodes. Best reviewed commit-by-commit, skipping the codegen ones. The most important changed files is rust/schema/annotations.py where the missing documentation was added.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label May 30, 2025
@aibaars aibaars force-pushed the aibaars/qldoc-ast branch from 353c39f to 628a741 Compare May 30, 2025 09:41
@aibaars aibaars force-pushed the aibaars/qldoc-ast branch from 628a741 to 858e372 Compare May 30, 2025 16:58
@aibaars aibaars force-pushed the aibaars/qldoc-ast branch from 858e372 to 943dd8e Compare May 30, 2025 21:00
@aibaars aibaars force-pushed the aibaars/qldoc-ast branch from 883aa89 to ae0c547 Compare June 2, 2025 14:38
@aibaars aibaars marked this pull request as ready for review June 2, 2025 15:06
@Copilot Copilot AI review requested due to automatic review settings June 2, 2025 15:06
@aibaars aibaars requested a review from a team as a code owner June 2, 2025 15:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds detailed documentation comments for various Rust AST node classes and updates the .gitattributes to include generated test files that were previously marked as missing.

  • Enriches QLL class docs with clear descriptions and examples for associated items, inline assembly elements, array types, argument lists, and ABI specs.
  • Introduces a constructor predicate in ControlFlowGraphImpl.qll to filter out macro pattern calls.
  • Replaces MISSING_SOURCE.txt entries in .gitattributes with actual .ql test paths for inline assembly and other elements.

Reviewed Changes

Copilot reviewed 644 out of 644 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
rust/ql/lib/codeql/rust/elements/AssocTypeArg.qll Added a descriptive doc comment and example for associated type arguments.
rust/ql/lib/codeql/rust/elements/AssocItemList.qll Extended doc to mention Impl contexts; refined formatting.
rust/ql/lib/codeql/rust/elements/AssocItem.qll Updated comment to describe associated items in traits/impls with example.
rust/ql/lib/codeql/rust/elements/Asm*.qll Added docs and examples for inline assembly symbols, registers, options, etc.
rust/ql/lib/codeql/rust/elements/ArrayTypeRepr.qll Documented array type representations with example.
rust/ql/lib/codeql/rust/elements/ArgList.qll Clarified argument list usage in calls with example.
rust/ql/lib/codeql/rust/elements/Abi.qll Documented ABI specs for extern functions/blocks.
rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll Added MacroCallTree() predicate to exclude calls in macro patterns.
rust/ql/.gitattributes Replaced missing-source placeholders with actual generated .ql test entries.

| test.rs:455:13:455:25 | [match(false)] 1 \| 2 | no-match | test.rs:455:13:455:25 | one_or_two!... |
| test.rs:455:13:455:25 | [match(false)] 1 \| 2 | no-match | test.rs:456:13:456:13 | _ |
| test.rs:455:13:455:25 | [match(true)] 1 \| 2 | match | test.rs:455:13:455:25 | one_or_two!... |
| test.rs:455:13:455:25 | [match(true)] 1 \| 2 | match | test.rs:455:30:455:30 | 3 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Foo<'a>
// ^^
let text: Text<'a>;
// ^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvements to examples 👍.

| gen_arg_list.rs:5:5:5:11 | ArgList | 0 | gen_arg_list.rs:5:5:5:11 | "not yet implemented" |
| gen_arg_list.rs:7:8:7:16 | ArgList | 0 | gen_arg_list.rs:7:9:7:9 | 1 |
| gen_arg_list.rs:7:8:7:16 | ArgList | 1 | gen_arg_list.rs:7:12:7:12 | 2 |
| gen_arg_list.rs:7:8:7:16 | ArgList | 2 | gen_arg_list.rs:7:15:7:15 | 3 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we getting better test results from doc changes? Are these the tests of the example code you were talking about earlier today?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the examples in triple backticks are place in source files for QL tests. That way we can test that the examples in the docs are actually valid. The "not yet implemented" stuff comes from the expansion of the todo!() macro.

```rust
todo!()
extern "C" fn foo() {}
// ^^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New documentation 👍 (I won't claim to have picked through it with a fine-toothed comb, but it all looks good at a glance, and is certainly an improvement on all those todo!()s).

```rust
todo!()
fn foo<T, U>(t: T, u: U) {}
// ^ ^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ^ are a helpful addition in many of these examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were co-piliot's idea, and I quite like them too. Ideally we make those ^^ things inline expectation markers, so we get even stronger testing of the documentation examples. @redsun82 perhaps something for a rainy afternoon ;-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1069,9 +1142,17 @@ class _:
@annotate(ForTypeRepr)
class _:
"""
A ForTypeRepr. For example:
A higher-ranked trait bound(HRTB) type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A higher-ranked trait bound(HRTB) type.
A higher-ranked trait bound (HRTB).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped the acronym, actually not much point defining a fancy acronym if it is not used anywhere in the text

println!("{} {}!", "Hello", "world");
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```rust

redsun82
redsun82 previously approved these changes Jun 3, 2025
Copy link
Contributor

@redsun82 redsun82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, that's a very good improvement in both documentation and testing 👍

Some minor cosmetic nits, but this is really neat!

@geoffw0
Copy link
Contributor

geoffw0 commented Jun 4, 2025

My comments have all been addressed and I'm [very] happy with the PR. @redsun82 please approve if you're happy your comments have been addressed as well.

@aibaars aibaars force-pushed the aibaars/qldoc-ast branch from 58b0e41 to 39851bc Compare June 4, 2025 13:45
Copy link
Contributor

@redsun82 redsun82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot!

@aibaars aibaars merged commit 189c16b into main Jun 4, 2025
15 of 16 checks passed
@aibaars aibaars deleted the aibaars/qldoc-ast branch June 4, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants