Skip to content

refactor: apply clippy::wrong_self_convention#6920

Closed
shulaoda wants to merge 1 commit into
rust-lang:mainfrom
shulaoda:05-23-refactor_apply_clippy_wrong_self_convention
Closed

refactor: apply clippy::wrong_self_convention#6920
shulaoda wants to merge 1 commit into
rust-lang:mainfrom
shulaoda:05-23-refactor_apply_clippy_wrong_self_convention

Conversation

@shulaoda
Copy link
Copy Markdown
Contributor

Summary

Three related fixes, all driven by clippy::wrong_self_convention. Run as a single-rule pass: cargo clippy -- -A clippy::all -W clippy::wrong_self_convention.

1. to_* methods take self instead of &self (on Copy types)

The to_* convention is "cheap reference-style conversion", which on Copy types is more natural to express by-value than as &self. No call site needs to change because Copy types are passed implicitly.

  • src/comment.rs: CommentStyle::to_str_tuplet
  • src/shape.rs: Indent::to_string, Indent::to_string_with_newline, Indent::to_string_inner, Shape::to_string_with_newline

2. Rename to_parsed_configinto_parsed_config

PartialConfig::to_parsed_config already consumes self, so by convention it should be named into_*, not to_*. The only call site (src/config/mod.rs) is updated in the same commit.

3. Rename trait IntoOverflowableItemAsOverflowableItem

IntoOverflowableItem::into_overflowable_item was misnamed: it takes &self and returns a wrapper that borrows from self (OverflowableItem<'a>). The Into*/into_* convention is reserved for consuming conversions; non-consuming, borrowing conversions should use As*/as_*.

This rename touches:

  • The trait, method, and Box<T> blanket impl in src/overflow.rs.
  • Both impl_into_overflowable_item_for_* macros and their invocations.
  • Generic bounds on rewrite_with_parens, rewrite_with_angle_brackets, rewrite_with_square_brackets, Context::new, and into_overflowable_list in src/overflow.rs.
  • Generic bounds on rewrite_array, rewrite_tuple_in_visual_indent_style, and rewrite_tuple in src/expr.rs, plus the corresponding use import.

The helper into_overflowable_list keeps its name (it transforms an Iterator<Item = &T> into Iterator<Item = OverflowableItem<'a>>); only the trait and the per-element method are renamed.

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label May 22, 2026
@ytmimi
Copy link
Copy Markdown
Contributor

ytmimi commented May 22, 2026

Going to close until we decide on which clippy lints we want to enforce in the codebase.

@ytmimi ytmimi closed this May 22, 2026
@rustbot rustbot removed the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants