Skip to content
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

[GSoC24] Implement rewrite_result for AST nodes #6206

Open
40 of 41 tasks
ding-young opened this issue Jun 22, 2024 · 3 comments
Open
40 of 41 tasks

[GSoC24] Implement rewrite_result for AST nodes #6206

ding-young opened this issue Jun 22, 2024 · 3 comments
Assignees
Labels
GSoC Google Summer of Code

Comments

@ding-young
Copy link
Contributor

ding-young commented Jun 22, 2024

This issue tracks the necessary tasks to implement rewrite_result for all the nodes that haverewrite implementation.

Background

Current rewrite method returns Option, which means that it gives None without any context when formatting fails. To improve tracking the context of formatting failures, we plan to add a new method rewrite_result in Rewrite trait and gradually replace rewrite with rewrite_result.

Target AST nodes

Below is the list of structs that currently implement the rewrite method. Most of these structs are rustc AST node, but it may be rustfmt representation of AST nodes (ex. Chain). Each task requires both implementing rewrite_result for that node and then modifying rewrite body with calling rewrite_result. Still, rewrite signature will remain the same and the return value of rewrite_result will be squashed into Option until we are ready to propagate Result upwards.

rewrite_*** on the right are the functions that need to be modified to implement rewrite_result for corresponding ast node.
attr.rs

chains.rs

expr.rs

imports.rs

items.rs

macros.rs

matches.rs

overflow.rs

patterns.rs

stmt.rs

types.rs

Future Tasks

Future tasks have two directions: one is propagating errors upward, and the other is generating a Result from downward that can potentially cause failure. Corresponding gh issues will be created after the tasks for this issue are done.

Reference

This issue is part of the Google Summer of Code project. For detailed description, see GSoC project page.

@ding-young
Copy link
Contributor Author

@rustbot claim

@ding-young
Copy link
Contributor Author

ding-young commented Jul 11, 2024

List of rewrite_***

We need to complete refactoring following functions to implement rewrite_result for Expr

  • rewrite_array
  • rewrite_literal
  • rewrite_call
  • rewrite_all_pairs
  • rewrite_pair
  • rewrite_unary_op
  • rewrite_struct_lit
  • rewrite_tuple
  • rewrite_let
  • rewrite_block
  • rewrite_block_with_visitor
  • rewrite_match
  • rewrite_path
  • rewrite_assignment
  • rewrite_unary_prefix
  • rewrite_unary_suffix
  • rewrite_closure
  • rewrite_chain
  • rewrite_macro
  • rewrite_index
  • rewrite_expr_addrof

Notable functions that are widely used

  • combine_strs_with_missing_comments
  • itemize_list, write_list, Iterator for ListItems
  • rewrite_comment

@ding-young
Copy link
Contributor Author

ding-young commented Sep 2, 2024

TODO for propagating errors

Update functions that format top level items to return RewriteResult

These are the list of functions that I have to update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GSoC Google Summer of Code
Projects
None yet
Development

No branches or pull requests

2 participants