Skip to content

[GSoC24] Implement rewrite_result for AST nodes  #6206

Open
@ding-young

Description

@ding-young

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

  • OverflowableItem - rewrite_result for
    Expr, GenericParam, MacroArg, NestedMetaItem, SegmentParam
    FieldDef, TuplePatField, Ty, Pat impl rewrite_result for ControlFlow, Stmt, update rewrite_index #6291

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.

Activity

ding-young

ding-young commented on Jun 22, 2024

@ding-young
ContributorAuthor

@rustbot claim

ding-young

ding-young commented on Jul 11, 2024

@ding-young
ContributorAuthor

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

9 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GSoCGoogle Summer of Code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @ytmimi@ding-young

      Issue actions

        [GSoC24] Implement `rewrite_result` for AST nodes · Issue #6206 · rust-lang/rustfmt