Skip to content

Assignment LHS to RHS Comments handling when rewrite_assign_rhs is used #4667

Open
@davidBar-On

Description

@davidBar-On

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:

  1. Do nothing, as it is not expected that comments will be added between the lhs (... =) and rhs in these cases.
  2. Enhance the code to use rewrite_assign_rhs_with_comments instead of rewrite_assign_rhs....
  3. 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:

  1. format_variant()
enum Foo {
    Bar,
    Baz = /* Block comment */ 123,
    Quux = // Line comment
	124,
}
  1. format_trait_alias()
#![feature(trait_alias)]
trait Foo =/*comment*/std::fmt::Debug + Send;
trait Bar =/*comment*/Foo + Sync;
  1. rewrite_type()
type Kilometers =/*comment*/i32;
  1. rewrite_struct_field()
    Could not find an example. Per this code requires new line inside of field type.

  2. rewrite_opaque_impl_type()
    Could not find an example.

  3. Static ast::ForeignItem
    Could not find an example.

  4. Macro format_lazy_static()
    Maybe this case is not relevant currently, as format_lazy_static() is not called if the lazy_static! macro contains a comment - see here.

  5. ast::WherePredicate::BoundPredicate
    Could not find an example.

  6. ast::WherePredicate::EqPredicate
    Could not find an example.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions