Skip to content

Tracking issue for RFC 1872: exhaustive_patterns feature #51085

Open

Description

@kennytm

This tracks the exhaustive_patterns feature which allows uninhabited variant to be omitted
(bug report: #12609; relevant RFC: rust-lang/rfcs#1872).

fn safe_unwrap<T>(x: Result<T, !>) -> T {
    match x {
        Ok(y) => y,
    }
}

Activity

  1. added
    T-langRelevant to the language team
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on May 26, 2018
  2. varkor commented on Oct 16, 2018

    @varkor
    Contributor

    The lack of this feature has unintuitive consequences (e.g. #55123). I haven't seen any problems arising from it either.

    cc @rust-lang/lang: could this be put forward for stabilisation?

  3. nikomatsakis commented on Oct 16, 2018

    @nikomatsakis
    Contributor

    @varkor I am mildly reluctant until we have agreed upon the story around "never patterns" -- but I suppose given a sufficiently conservative definition of "uninhabited pattern" I'd be all right with it. Do you think you could write-up a "stabilization report" that includes examples of the tests we have and also documents the limits of what sorts of things would be considered uninhabited in stable code?

    (That said, I think "never patterns" gives us a path forward that addresses my concerns around aggressive uninhabited definitions, by just turning the "ambiguous" cases into lints in the presence of unsafe code. I'd be happier though if we had an RFC on the topic.)

  4. nikic commented on Oct 26, 2018

    @nikic
    Contributor

    The exhaustive_patterns feature currently seems to have a pretty big performance issue. Having perf top running while compiling librustc, I noticed that it spends an unreasonable amount of time inside ty::inhabitedness. Disabling exhaustive_patterns (it's not actually used in librustc/librustc_mir) shaved off ~30s (of 12min total) from stage1 compiler artifact compile time (in a totally unscientific benchmark, so take with a grain of salt).

    I would expect that this issue will resolve itself if there is a consensus to go with references never being uninhabited (ref #54125 (comment)), as the reference handling is what I believe makes this expensive (not looking through references both reduces the amount of types we need to look at, and allows us to drop the expensive hashmap and nested hashsets used to avoid unbounded recursion). If the consensus goes in the other direction, then this code should probably be optimized a bit prior to stabilization of the feature.

  5. jonas-schievink commented on May 13, 2019

    @jonas-schievink
    Contributor

    cc #51221, using this feature in let-bindings seems to ICE unless the never_type feature is also enabled

  6. Nadrieril commented on Nov 17, 2020

    @Nadrieril
    Member

    The exhaustive_patterns feature currently seems to have a pretty big performance issue. Having perf top running while compiling librustc, I noticed that it spends an unreasonable amount of time inside ty::inhabitedness.

    It is now the case that "references never are uninhabited", at least as far as is_ty_uninhabited_from is concerned. Is the performance issue still there?
    Otherwise, I expect that making is_ty_uninhabited_from into a query or something would significantly improve perf, because match checking repeatedly calls it on the same type and its subcomponents.

  7. varkor commented on Nov 19, 2020

    @varkor
    Contributor

    Is the performance issue still there?

    I suspect this requires some investigation. (Perhaps it would be sufficient to open a PR enabling the feature and do a perf run.)

  8. 49 remaining items

  9. added a commit that references this issue on Aug 6, 2024
  10. added 4 commits that reference this issue on Aug 6, 2024
  11. Nadrieril commented on Aug 10, 2024

    @Nadrieril
    Member

    min_exhaustive_patterns is now stabilized! This allows omitting empty arms when matching by-value. The other cases (behind a reference, a pointer, or inside an union) still require exhaustive_patterns.

  12. safinaskar commented on Oct 16, 2024

    @safinaskar
    Contributor

    Is this code supposed to work in the future?

    struct A(Box<A>);
    fn f(x: A) -> ! {
      match x {}
    
    // Or this:
      match x {
        !,
      }
    }

    A is uninhibited in safe code, so theoretically the code above should compile. Is this planned? (Note: I don't need this feature, this is not feature request, it is just pure curiosity.)

  13. RalfJung commented on Oct 16, 2024

    @RalfJung
    Member

    No, I am not aware of any plans trying to reason about cyclic types.

  14. added 2 commits that reference this issue on Jul 4, 2025
  15. added a commit that references this issue on Jul 5, 2025
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-exhaustiveness-checkingRelating to exhaustiveness / usefulness checking of patternsA-patternsRelating to patterns and pattern matchingB-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-exhaustive_patterns`#![feature(exhaustive_patterns)]`S-tracking-needs-summaryStatus: It's hard to tell what's been done and what hasn't! Someone should do some investigation.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions