rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
5.98k stars 878 forks source link

[GSoC24] Implement `rewrite_result` for AST nodes #6206

Open ding-young opened 3 months ago

ding-young commented 3 months ago

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 commented 3 months ago

@rustbot claim

ding-young commented 2 months ago

List of rewrite_***

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

Notable functions that are widely used

ding-young commented 3 weeks ago

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.