Skip to main content

Module fill_arms

Module fill_arms 

Source
Expand description

#2100 slice 3: the fill-match-arms quick fix. It adds an arm for every variant (or Bool value, or the _ an unbounded literal match or an extensible enum needs) that a non-exhaustive match leaves uncovered.

The checker raises one bynk.types.non_exhaustive_match per missing witness, and one bynk.types.extensible_match_needs_wildcard when the enum may gain variants (its witness is the wildcard, _ or Some(_), that covers them). Each carries a HasPlaceholders suggestion inserting \n<witness> => <default> after the last arm, where <default> is a typed default of the arm result type (0, "", None, [], …). The suggestion is never a one-click quick fix or a fix-all candidate (both take only MachineApplicable). This module collects every suggestion on one match into one action and lays the arms out the way bynk-fmt prints them: one per line at the last arm’s indentation, each ending in ,.

The action is offered only when every witness of the match has a suggestion. A result type with no default (a record, a user sum, a refined type), a let … else match, or a multi-field witness the checker can’t write as a pattern means no action. Filling only some of the arms would still leave the match non-exhaustive.

Fill-arms rides the unfiltered lightbulb request, so it’s listed without an edit (data names the match) and the edit is computed, and re-checked (DECISION B), in codeAction/resolve.

Structs§

Target
What a listed fill-arms action’s data names, or None when the action is not one of ours.

Functions§

edits
The edits that fill the match at match_span in text, laid out as bynk-fmt prints arms. None when there is nothing to fill or the last arm’s line doesn’t allow it: the match closes on that line, or the arm shares it with other code. A bynk-fmt-canonical file stays canonical.
fillable
The match spans (the non-exhaustive diagnostics’ span) that intersect requested and have an arm suggestion for every missing witness, in source order.
listed
The listed (unresolved) action for the match at match_span: a quick fix on its diagnostics, with no edit yet. data carries what codeAction/resolve needs.
resolve
action with its versioned edit filled in.