Skip to content

Proposed changes to or_fun_call/unwrap_or_else_default #10080

Closed
@smoelius

Description

@smoelius

Description

I propose the following changes to or_fun_call and unwrap_or_else_default (which I would implement):

  1. Implement the missing functionality from Suggest Entry::or_default for Entry::or_insert(Default::default()) #9342, e.g., handle or_insert_with(Default::default).
  2. Merge unwrap_or_else_default into or_fun_call. At present, there is an ambiguity as to where the just mentioned new functionality should go. However, I agree with @giraffate when he wrote here that things like unwrap_or_else(Vec::new) should be handled by or_fun_call. Merging unwrap_or_else_default into or_fun_call would resolve the ambiguity.
  3. Move or_fun_call to complexity. If I understand correctly, the "false positives" described in Make it clear that or_fun_call can be a false-positive #9829 are because the suggestions don't improve performance, not that the suggestions don't apply. However, even when the suggestions don't improve performance, they still improve "code that does something simple but in a complex way."

Note that 2 and 3 are intertwined. If I have misunderstood the reasoning in #9829, it might make sense to keep unwrap_or_else_default as a separate style lint. (cc: @hrxi @llogiq)

Thoughts?

Version

No response

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions