[Rust] Add core single-file syntax lowering to UAST#58
Conversation
…gacy flag compatibility" This reverts commit f0956bb.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the foundational Rust parser ( Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new Rust parser for generating UAST. The implementation covers core Rust syntax for single-file analysis, including functions, structs, let bindings, assignments, and expressions. It also adds project-level analysis by discovering and parsing Cargo.toml files. The code is well-structured and includes a comprehensive set of tests, including golden file testing for stability and correctness.
My review focuses on improving error handling and ensuring correctness in the syntax lowering logic. I've identified a case where let bindings with side effects could be incorrectly dropped, and an opportunity to improve error reporting for malformed Cargo.toml files. Overall, this is a solid foundation for Rust UAST extraction.
| fn lower_single_pattern_local(local: &Local) -> Option<Value> { | ||
| let (name, explicit_type) = extract_binding_name_and_type(&local.pat)?; | ||
| let init = local | ||
| .init | ||
| .as_ref() | ||
| .and_then(|local_init| lower_expr(&local_init.expr)); | ||
| let var_type = explicit_type.map(lower_type).unwrap_or_else(dynamic_type); | ||
| let cloned = init.is_some(); | ||
| Some(variable_declaration( | ||
| identifier(name), | ||
| init, | ||
| var_type, | ||
| cloned, | ||
| false, | ||
| )) | ||
| } |
There was a problem hiding this comment.
This function currently discards let statements where no variable is bound, such as let Foo { .. } = my_func();. The use of ? on line 408 causes an early return, and the initializer expression (e.g., my_func()) is dropped from the UAST. This is incorrect if the initializer has side effects.
The initializer expression should be preserved in the UAST even if no variables are bound. You can adjust the logic to handle this case, similar to how lower_tuple_pattern_local handles empty declarations.
fn lower_single_pattern_local(local: &Local) -> Option<Value> {
if let Some((name, explicit_type)) = extract_binding_name_and_type(&local.pat) {
let init = local
.init
.as_ref()
.and_then(|local_init| lower_expr(&local_init.expr));
let var_type = explicit_type.map(lower_type).unwrap_or_else(dynamic_type);
let cloned = init.is_some();
Some(variable_declaration(
identifier(name),
init,
var_type,
cloned,
false,
))
} else {
// No bindings, but preserve initializer for side effects.
local
.init
.as_ref()
.and_then(|local_init| lower_expr(&local_init.expr))
}
}|
|
||
| let value = match toml::from_str::<toml::Value>(&content) { | ||
| Ok(v) => v, | ||
| Err(_) => return Ok(None), |
There was a problem hiding this comment.
Errors from parsing Cargo.toml files are silently ignored here. This can hide issues with malformed manifests, making it harder for users to debug their project setup. It would be better to propagate a RunError when TOML parsing fails. You could introduce a new variant to the RunError enum for this purpose, similar to how ParseSource is handled.
|
For incremental review, I’m currently managing this branch as a stacked PR in my fork (same head branch): I will keep this upstream PR aligned as changes are validated. |
[Rust] Add regression golden fixtures and README docs
[Rust] Fix control-flow lowering edge cases and add regressions
Summary
Implement core single-file Rust syntax lowering in
parser-Rustand add focused regression tests.Scope in this PR
fnstructletreturnOut of scope
if/match/for/while/loop)Validation
cargo fmtcargo test(all pass inparser-Rust)Related issues
Stacking note
This branch is stacked on top of #57.
Mirror stacked review PR (base =
feat/rust-parser-s2) is available at: