Uh oh!
There was an error while loading. Please reload this page.
Rust: move body skipping logic to code generation - #19559
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors how body-skipping logic is applied by moving it from the Rust extractor’s translator into the AST code generator, so that function/const/static bodies (and other designated “body” fields) are conditionally omitted during code generation for library crates.
- Remove translator-level node exclusion and introduce a simple
should_skip_bodies()check - Update the
extractor.mustachetemplate to wrap “body” fields withshould_skip_bodies() - Extend the AST generator to mark specific fields (e.g., function body) as
Bodyand generalizeFieldInfo
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| rust/extractor/src/translate/base.rs | Deleted the complex should_be_excluded(&AstNode) fn and added should_skip_bodies(); renamed should_be_excluded_attrs to should_be_excluded |
| rust/ast-generator/templates/extractor.mustache | Moved node-level exclusion into attribute-only block and added template logic to skip “body” fields |
| rust/ast-generator/src/main.rs | Introduced FieldType::Body, helper constructors, and wired up Body fields in get_additional_fields and get_fields |
Comments suppressed due to low confidence (2)
rust/extractor/src/translate/base.rs:630
- [nitpick] The name
should_be_excludedonly applies to attribute-based exclusion now. Consider renaming toshould_be_excluded_by_attrsor similar for clarity and to avoid confusion if a future node-level exclusion is needed.
pub(crate) fn should_be_excluded(&self, item: &impl ast::HasAttrs) -> bool {
rust/ast-generator/templates/extractor.mustache:38
- The global node exclusion check was moved inside the
has_attrsblock, so nodes without attributes no longer respectshould_be_excluded. Reintroduce the unconditional check before handling attributes to preserve prior behavior.
if self.should_be_excluded(node) { return None; }
Uh oh!
There was an error while loading. Please reload this page.
529b714 to
78bb41eCompareredsun82
commented
Jun 3, 2025
I'm pulling out the part about extracting |
It also contains a refactoring where
FieldInfo{ name: "xxx".to_string(), ty: FieldType::Optional("Yyy".to_string() }can now be written more succintlyFieldInfo::optional("xxx", "Yyy"), and similarly for other field types.