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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Rust: add documentation for AST nodes #19630

wants to merge 9 commits into from

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?

```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.

Comment on lines +1551 to +1552
(x + y)
//^^^^^
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
(x + y)
//^^^^^
(x + y)
//^^^^^^^

Comment on lines +2087 to +2088
pub struct S;
//^^^
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
pub struct S;
//^^^
pub struct S;
//^^^

```
"""


@annotate(UseTree)
class _:
"""
A UseTree. For example:
A `use` tree, ie the part after the `use` keyword in a `use` statement. For example:
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 `use` tree, ie the part after the `use` keyword in a `use` statement. For example:
A `use` tree, that is, the part after the `use` keyword in a `use` statement. For example:

We're supposed to prefer "that is" to "ie" in documentation.

Comment on lines +1833 to +1834
x: i32,
y: i32,
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
x: i32,
y: i32,
x: i32,
y: i32,

Comment on lines +2048 to +2049
use std::{fs, io};
// ^^^^^^^
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
use std::{fs, io};
// ^^^^^^^
use std::{fs, io};
// ^^^^^^^^

I'm not sure if this range should include both {} or neither, but it surely should not include one but not the other. (nit)

@@ -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).

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

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!

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.

3 participants