Skip to content

Tool for checking the safety of non-exhaustive patterns #2896

@catamorphism

Description

@catamorphism
Contributor

This is definitely in the department of blue-sky, out-there projects, but I was just thinking about option::get and wondering how feasible it would be to adapt the ideas in Neil Mitchell's Catch tool (for Haskell) to Rust.

http://community.haskell.org/~ndm/catch/

In our case, this would be to verify that alt check, and maybe even functions that pattern-match on their input and unconditionally fail in one or more branches (like option::get) are being used safely (which is to say, in a way that won't cause a runtime failure). This would be one way to allow alt checks and get a safety guarantee.

Mutability would definitely complicate things, but one way out is to only provide any guarantees about immutable data (and warn in a lint pass about alt check and similar things on mutable data).

Activity

catamorphism

catamorphism commented on Jul 13, 2012

@catamorphism
ContributorAuthor

(Of course, we might just get rid of alt check... but we'll always have option::get, probably. This certainly isn't necessary, but in case someone who likes static analysis wanted to pick it up for fun...)

pnkfelix

pnkfelix commented on Jun 21, 2013

@pnkfelix
Contributor

Nominating for milestone: far future.

pnkfelix

pnkfelix commented on Jun 27, 2013

@pnkfelix
Contributor

accepted for far future

thestinger

thestinger commented on Aug 19, 2013

@thestinger
Contributor

Triage bump.

emberian

emberian commented on Jan 14, 2014

@emberian
Contributor

Visiting for triage. alt check is now known a match.

pnkfelix

pnkfelix commented on May 7, 2014

@pnkfelix
Contributor

I think we should close this ticket at this point; the language has changed quite a bit since it was written so that it is hard for an average community member to actually know what it is really asking for.

(I suppose now that we have the ability to put attributes on match arms, it would be feasible to annotate match arms, where the attribute would indicate whether we want the hypothetical tool to warn about whether they are actually reachable. But still, I think we should close this; tools like this can be added in the future, but it need not be a task that the rust team undertakes, and it does not require changes to the language nor core tools.)

ghost

ghost commented on Jul 11, 2014

@ghost

@pnkfelix Agreed. Regardless of how feasible a Rust version of Check is, it seems out of scope of the compiler. Could this be closed?

added a commit that references this issue on May 23, 2023
added a commit that references this issue on Jun 4, 2024
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

    A-frontendArea: Compiler frontend (errors, parsing and HIR)A-type-systemArea: Type systemE-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pnkfelix@catamorphism@emberian@thestinger

        Issue actions

          Tool for checking the safety of non-exhaustive patterns · Issue #2896 · rust-lang/rust