refactor: apply clippy::wrong_self_convention#6920
Closed
shulaoda wants to merge 1 commit into
Closed
Conversation
Contributor
|
Going to close until we decide on which clippy lints we want to enforce in the codebase. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 takeselfinstead of&self(onCopytypes)The
to_*convention is "cheap reference-style conversion", which onCopytypes is more natural to express by-value than as&self. No call site needs to change becauseCopytypes are passed implicitly.src/comment.rs:CommentStyle::to_str_tupletsrc/shape.rs:Indent::to_string,Indent::to_string_with_newline,Indent::to_string_inner,Shape::to_string_with_newline2. Rename
to_parsed_config→into_parsed_configPartialConfig::to_parsed_configalready consumesself, so by convention it should be namedinto_*, notto_*. The only call site (src/config/mod.rs) is updated in the same commit.3. Rename trait
IntoOverflowableItem→AsOverflowableItemIntoOverflowableItem::into_overflowable_itemwas misnamed: it takes&selfand returns a wrapper that borrows fromself(OverflowableItem<'a>). TheInto*/into_*convention is reserved for consuming conversions; non-consuming, borrowing conversions should useAs*/as_*.This rename touches:
Box<T>blanket impl insrc/overflow.rs.impl_into_overflowable_item_for_*macros and their invocations.rewrite_with_parens,rewrite_with_angle_brackets,rewrite_with_square_brackets,Context::new, andinto_overflowable_listinsrc/overflow.rs.rewrite_array,rewrite_tuple_in_visual_indent_style, andrewrite_tupleinsrc/expr.rs, plus the correspondinguseimport.The helper
into_overflowable_listkeeps its name (it transforms anIterator<Item = &T>intoIterator<Item = OverflowableItem<'a>>); only the trait and the per-element method are renamed.