Description
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
- ast::NestedMetaItem - rewrite_literal refactor rewrite_literal & combine_strs_with_missing_comments #6250ast::MetaItem - rewrite_path, rewrite_literal, rewrite_with_parens refactor rewrite_array, pair, tuple, call #6248ast::Attribute - rewrite_doc_comment refactor rewrite_literal & combine_strs_with_missing_comments #6250[ast::Attribute] - rewrite_(initial)doc_comment refactor rewrite_literal & combine_strs_with_missing_comments #6250
chains.rs
- ChainItem - rewrite_paren (local change), rewrite_method_call, rewrite_comment refactor rewrite_literal & combine_strs_with_missing_comments #6250Chain - methods of ChainFormatter trait update rewrite_chain to return RewriteResult #6270
expr.rs
- ast::Expr - tons of rewrite calls impl rewrite_result for ast::Expr #6311ast::Block - rewrite_block return RewriteResult for
rewrite_block
andrewrite_closure
#6235ControlFlow - rewrite_block_with_visitor, format_expr impl rewrite_result for ControlFlow, Stmt, update rewrite_index #6291
imports.rs
- UseSegment - rewrite_nested_use_tree update rewrite functions in imports.rs #6261UseTree - UseSegment update rewrite functions in imports.rs #6261
items.rs
- ast::FieldDef Impl rewrite_result for ast nodes in items.rs #6212OpaqueTypeast::FnRetTy Impl rewrite_result for ast nodes in items.rs #6212
macros.rs
- MacroArg update macro rewrite functions to return RewriteResult #6271
rewrite_macro
matches.rs
- ArmWrapper - impl rewrite_result for ArmWrapper #6239
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
- RangeOperand refactor rewrite_array, pair, tuple, call #6248(ast) Pat - write_list, rewrite_path, rewrite_unary_prefix impl rewrite_result for Pat, TuplePatField #6262TuplePatField impl rewrite_result for Pat, TuplePatField #6262
stmt.rs
types.rs
- SegmentParam Impl rewrite_result for ast nodes in types.rs #6220PreciseCapturingArg return RewriteResult for rewrite_path & rewrite_struct_*** #6236ast::AssocItemConstraint return RewriteResult for rewrite_path & rewrite_struct_*** #6236ast::AssocConstraintKind Impl rewrite_result for ast nodes in types.rs #6220ast::WherePredicate Impl rewrite_result for ForeignItem, TraitAliasBounds, WherePredicate #6309ast::GenericArg Impl rewrite_result for ast nodes in types.rs #6220ast::AnonConst - format_expr impl rewrite_result for ast::Expr #6311ast::GenericBound Impl rewrite_result for ast nodes in types.rs #6220ast::GenericBounds Impl rewrite_result for ast nodes in types.rs #6220ast::GenericParam Impl rewrite_result for ast nodes in types.rs #6220ast::PolyTraitRef return RewriteResult for rewrite_path & rewrite_struct_*** #6236
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 commentedon Jun 22, 2024
@rustbot claim
rewrite_block
andrewrite_closure
#6235ding-young commentedon Jul 11, 2024
List of
rewrite_***
We need to complete refactoring following functions to implement
rewrite_result
forExpr
Notable functions that are widely used
combine_strs_with_missing_comments
itemize_list
,write_list
, Iterator forListItems
rewrite_comment
9 remaining items