Skip to content

Tracking issue for RFC 2591: precise pattern matching on pointer size types #56354

Closed

Description

@varkor

This is a tracking issue for (precise) exhaustive pattern matching on usize and isize (described in rust-lang/rfcs#2591).

Feature gate: #![feature(precise_pointer_size_matching)]

Steps:

Activity

  1. added
    T-langRelevant to the language team
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Nov 30, 2018
  2. SergioBenitez commented on Oct 23, 2019

    @SergioBenitez
    Contributor

    Is there anything preventing the stabilization of this feature?

  3. varkor commented on Oct 23, 2019

    @varkor
    ContributorAuthor

    I think we'd need an RFC, or at the very least, a detailed motivation. The problem is that pointer size types have different ranges depending on the target platform, and so there was concern that this could cause confusion. See rust-lang/rfcs#2591 (comment) and rust-lang/rfcs#2591 (comment) for details.

  4. workingjubilee commented on Apr 9, 2021

    @workingjubilee
    Member

    I believe that if half_open_range_patterns receive partial or total stabilization as discussed in #67264, it might allow for patterns that more usefully handle various cases here. This could be particularly useful when you want to match on e.g. the length of an array, Vec, or anything else that would produce an ExactSizeIterator (an example I have seen is matching against the count of arguments to a CLI).

  5. roblabla commented on Oct 4, 2022

    @roblabla
    Contributor

    I am so confused by this. I currently have code to the effect of

    match 0usize {
        0..=9 => { /* some code that only runs on small numbers */ },
        10.. => { /* some code that handles everything else */ },
    }

    This triggers this hard error. I'm... not sure I understand the rationale behind this.

    I can understand denying precise pointer matching when hardcoding numbers, but it seems to me like half-open ranges should obviously be accepted here - there is no room for any confusion or portability issues. And this isn't even a lint, so we can't #[allow] it away...

    Could half-open ranges on usize be allowed to exhaustively match?

  6. workingjubilee commented on Mar 5, 2023

    @workingjubilee
    Member

    I will write up a formal proposal for this, as I attempted to move half-open range patterns along a bit so that we could specifically have this.

  7. removed their assignment
    on Oct 15, 2023
  8. Nadrieril commented on Dec 1, 2023

    @Nadrieril
    Member

    @roblabla's example above now works as expected. Given that half-open ranges can now be used to match exhaustively on usize/isize, is this feature still useful?

  9. Nadrieril commented on Dec 4, 2023

    @Nadrieril
    Member

    In #118598 I propose to deprecate this feature gate in favor of half-open range patterns

  10. added a commit that references this issue on Dec 5, 2023
  11. added a commit that references this issue on Dec 5, 2023
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 RFCS-tracking-design-concernsStatus: There are blocking design concerns.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