Assignment LHS to RHS Comments handling when rewrite_assign_rhs is used
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
The places where rewrite_assign_rhsh()/_with() are used, and the comments between lhs and rhs are not handled, were identified in #4626. I submitted PRs to use rewrite_assign_rhs_with_comments() for the rewrite_assignment and format_trait cases.
For the following cases, it is not clear if and what should be done. There seem to be three options:
- Do nothing, as it is not expected that comments will be added between the lhs (
... =) and rhs in these cases. - Enhance the code to use
rewrite_assign_rhs_with_commentsinstead ofrewrite_assign_rhs.... - Only check whether all comments are included in the formatted code and if not use the original code (using
recover_comment_removed()).
Following are the relevant cases with code examples when I was able to find an example:
enum Foo {
Bar,
Baz = /* Block comment */ 123,
Quux = // Line comment
124,
}
#![feature(trait_alias)]
trait Foo =/*comment*/std::fmt::Debug + Send;
trait Bar =/*comment*/Foo + Sync;
type Kilometers =/*comment*/i32;
-
rewrite_struct_field()
Could not find an example. Per this code requires new line inside of field type. -
rewrite_opaque_impl_type()
Could not find an example. -
Static ast::ForeignItem
Could not find an example. -
Macro format_lazy_static()
Maybe this case is not relevant currently, asformat_lazy_static()is not called if thelazy_static!macro contains a comment - see here. -
ast::WherePredicate::BoundPredicate
Could not find an example. -
ast::WherePredicate::EqPredicate
Could not find an example.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the listed rewrite_assign_rhs call sites in src/formatting/items.rs, src/formatting/macros.rs, and src/formatting/types.rs, along with PR #4626. Run rustfmt on the provided examples and investigate the cases without examples. Done means each relevant case has an agreed handling strategy and comments are preserved or safely recovered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100