Skip to content

unowned_variable_capture fires for unowned(unsafe) captures #6817

Closed

Description

@lukaskollmer

the unowned_variable_capture rule currently fires not only for unowned captures, but also for unowned(unsafe) captures.

IMO this is excessive, as the unsafe addition already makes clear the programmer's intent to trade safety for performance here, and guarantee that the captured value's lifetime will exceed that of the closure.

suggestion: unowned_variable_capture should fire only for unowned captures, but not for unowned(unsafe) ones.

looking at the rule's documentation, it seems like this should be the behaviour anyway, as the "triggering examples" section lists only unowned captures but no unowned(unsafe) ones.

Activity

  1. SimplyDanny commented on Jul 10, 2026

    @SimplyDanny
    Collaborator

    unowned(unsafe) is a new feature the rule hasn't considered yet. It should probably be handled with a new option that either makes the rule check or ignore it.

  2. added
    enhancement
    good first issue
    on Jul 10, 2026
  3. lukaskollmer commented on Jul 10, 2026

    @lukaskollmer
    Author

    @SimplyDanny it's not particularly new; it has been around since the very beginning i believe.

    imo the way this should be handled it to add an option to the rule, to control whether it also covers unowned(unsafe) captures (and have that default to false)

  4. Yurii201811 commented on Jul 13, 2026

    @Yurii201811
    Contributor

    I am working on this following the configuration approach discussed here: ignore unowned(unsafe) by default and add an opt-in include_unsafe setting, with rule examples and changelog coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions