rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

[GSoC24] Implement `rewrite_result` for AST nodes

Open ding-young opened this issue 1 year ago • 3 comments

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

  • [x] ast::NestedMetaItem - rewrite_literal #6250
  • [x] ast::MetaItem - rewrite_path, rewrite_literal, rewrite_with_parens #6248
  • [x] ast::Attribute - rewrite_doc_comment #6250
  • [x] [ast::Attribute] - rewrite_(initial)doc_comment #6250

chains.rs

  • [x] ChainItem - rewrite_paren (local change), rewrite_method_call, rewrite_comment #6250
  • [x] Chain - methods of ChainFormatter trait #6270

expr.rs

  • [x] ast::Expr - tons of rewrite calls #6311
  • [x] ast::Block - rewrite_block #6235
  • [x] ControlFlow - rewrite_block_with_visitor, format_expr #6291

imports.rs

  • [x] UseSegment - rewrite_nested_use_tree #6261
  • [x] UseTree - UseSegment #6261

items.rs

  • [x] ast::Local #6212
  • [x] TraitAliasBound #6309
  • [x] ast::FieldDef #6212
  • [ ] OpaqueType
  • [x] ast::FnRetTy #6212
  • [x] ast::Param #6212
  • [x] ast::ForeignItem #6309

macros.rs

  • [x] ast::Item #6271
  • [x] MacroArg #6271 rewrite_macro

matches.rs

  • [x] ArmWrapper - #6239

overflow.rs

  • [x] OverflowableItem - rewrite_result for
    Expr, GenericParam, MacroArg, NestedMetaItem, SegmentParam FieldDef, TuplePatField, Ty, Pat #6291

patterns.rs

  • [x] RangeOperand #6248
  • [x] (ast) Pat - write_list, rewrite_path, rewrite_unary_prefix #6262
  • [x] (ast) PatField #6250
  • [x] TuplePatField #6262

stmt.rs

  • [x] Stmt #6291

types.rs

  • [x] SegmentParam #6220
  • [x] PreciseCapturingArg #6236
  • [x] ast::AssocItemConstraint #6236
  • [x] ast::AssocConstraintKind #6220
  • [x] ast::WherePredicate #6309
  • [x] ast::GenericArg #6220
  • [x] ast::AnonConst - format_expr #6311
  • [x] ast::Lifetime #6291
  • [x] ast::GenericBound #6220
  • [x] ast::GenericBounds #6220
  • [x] ast::GenericParam #6220
  • [x] ast::PolyTraitRef #6236
  • [x] ast::TraitRef #6236
  • [x] ast:Ty #6220

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 avatar Jun 22 '24 03:06 ding-young