-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: fix <X as Y>
path extraction
#18847
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
Conversation
This works around a quirk in rust-analyzer's AST generation machinery, where for an `<X as Y>` path there might be no way to directly get `Y` from the path segment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Overview
This PR fixes the extraction of types from <X as Y>
paths in the Rust extractor. It introduces a dedicated function in the translator to isolate type and trait extraction logic and updates the corresponding schema and AST generation.
- Introduces extract_types_from_path_segment in the Translator to emit type and trait representations for path segments.
- Removes direct emission of type information from the PathSegment in generated output.
- Updates the annotations and AST generator to align with the new type extraction strategy.
Reviewed Changes
File | Description |
---|---|
rust/extractor/src/translate/base.rs | Adds a dedicated function to extract type and trait info from path segments. |
rust/schema/annotations.py | Updates the PathSegment annotation to include type_repr and trait_type_repr. |
rust/ast-generator/src/main.rs | Refactors field extraction for several nodes and skips type-related fields for PathSegment. |
rust/extractor/src/translate/generated.rs | Removes direct emission of type_repr and path_type for PathSegment. |
Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
rust/extractor/src/translate/base.rs:606
- The code relies on the order of children() when extracting the type and trait nodes. Consider explicitly filtering nodes by their kind to ensure the correct type is extracted regardless of order.
if let Some(t) = type_refs.next().and_then(ast::Type::cast).and_then(|t| self.emit_type(t))
rust/ast-generator/src/main.rs:347
- [nitpick] It might help to add a clarifying comment explaining why fields with method names 'ty' or 'path_type' for PathSegment are skipped, to aid future maintainers.
| ("PathSegment", "ty" | "path_type") // these are broken, handling them manually
Tip: Copilot code review supports C#, Go, Java, JavaScript, Markdown, Python, Ruby and TypeScript, with more languages coming soon. Learn more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks for looking into this.
ping after merge @hvitved 🙂 |
This works around a quirk in rust-analyzer's AST generation machinery, where for an
<X as Y>
path there might be no way to directly getY
from the path segment.This also renames that property from
getPathType
togetTraitTypeRepr
.