Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilise exhaustive integer pattern matching #2591

Merged
merged 6 commits into from
Nov 30, 2018

Conversation

varkor
Copy link
Member

@varkor varkor commented Nov 10, 2018

Extend Rust's pattern matching exhaustiveness checks to cover the integer types: u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize and char.

Rendered.

fn matcher_full(x: u8) {
  match x { // ok
    0 ..= 31 => { /* ... */ }
    32 => { /* ... */ }
    33 ..= 255 => { /* ... */ }
  }
}

fn matcher_incomplete(x: u8) {
  match x { //~ ERROR: non-exhaustive patterns: `32u8..=255u8` not covered
    0 ..= 31 => { /* ... */ }
  }
}

This feature has already been implemented behind the feature flag exhaustive_integer_patterns, so this RFC is viewed as a motion to stabilise the feature. See rust-lang/rust#50912 (comment) for the previous motion to (unstably) approve this feature.

@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the RFC. label Nov 10, 2018
@Centril Centril changed the title Exhaustive integer pattern matching Stabilize Exhaustive integer pattern matching Nov 10, 2018
@hanna-kruppe

This comment has been minimized.

@varkor varkor changed the title Stabilize Exhaustive integer pattern matching Stabilise exhaustive integer pattern matching Nov 10, 2018
Also update examples to not rely on `exclusive_range_pattern`.
@Centril
Copy link
Contributor

Centril commented Nov 10, 2018

@rfcbot fcp merge

Feature name: #![feature(exhaustive_integer_patterns)]
Version target: 1.32 (2019-01-18)
Tracking issue: rust-lang/rust#50907

The feature exhaustive_integer_patterns feature has baked in the nightly compiler for approximately 12 weeks which is sufficient amount of time. Originally, the feature did not pass through an RFC but it was accepted by an FCP-merge over at rust-lang/rust#50912 (comment).

This RFC serves as:

  • An introduction for people who were unaware of this new capability,
  • A stabilization report,
  • As assurance that the proper RFC process is followed.

Given the clear motivation in improving code correctness and to fix bugs in the language, I propose that we accept this RFC and stabilize exhaustive_integer_patterns as per the stabilization report given in this RFC. Once this RFC is accepted, and if no further issues are found, the feature will move to immediate stabilization without further delay.

@rfcbot
Copy link
Collaborator

rfcbot commented Nov 10, 2018

Team member @Centril has proposed to merge this. The next step is review by the rest of the tagged teams:

Concerns:

Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. labels Nov 10, 2018
@scottmcm
Copy link
Member

I love the more specific error messages that come with this!

@StyMaar

This comment has been minimized.

@eddyb

This comment has been minimized.

@hanna-kruppe

This comment has been minimized.

@RalfJung

This comment has been minimized.

@StyMaar

This comment has been minimized.

@hanna-kruppe

This comment has been minimized.

@RalfJung

This comment has been minimized.

@hanna-kruppe

This comment has been minimized.

@Centril
Copy link
Contributor

Centril commented Nov 14, 2018

@rfcbot concern isize-usize-exhaustiveness

Seems like a valid concern re. usize and isize for reasons aforementioned (e.g. in #2591 (comment)); I'd like to see RFC amended to extract assumptions about the max value of usize and min+max values of isize out to a separate feature gate exhaustive_usize_patterns as a conservative choice that can be changed in the future if so desired. The extraction can be done as part of the stabilization PR.

@Centril Centril self-assigned this Nov 14, 2018
@Centril
Copy link
Contributor

Centril commented Nov 19, 2018

@varkor Thoughts on / mind making the adjustments per #2591 (comment)?

@varkor
Copy link
Member Author

varkor commented Nov 19, 2018

Exhaustive integer pattern matching will be very much complimented by #947, so it's probably ripe time to start a new RFC for open-ended range patterns.

@Centril
Copy link
Contributor

Centril commented Nov 20, 2018

Given the latest changes...

@rfcbot resolve isize-usize-exhaustiveness

@rfcbot
Copy link
Collaborator

rfcbot commented Nov 20, 2018

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. and removed proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. labels Nov 20, 2018
@Centril Centril added A-patterns Pattern matching related proposals & ideas A-primitive Primitive types related proposals & ideas A-exhaustiveness Proposals relating to exhaustiveness of pattern matching. labels Nov 22, 2018
@rfcbot rfcbot added the finished-final-comment-period The final comment period is finished for this RFC. label Nov 30, 2018
@rfcbot
Copy link
Collaborator

rfcbot commented Nov 30, 2018

The final comment period, with a disposition to merge, as per the review above, is now complete.

@rfcbot rfcbot removed the final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. label Nov 30, 2018
@Centril Centril merged commit 58cf090 into rust-lang:master Nov 30, 2018
@Centril
Copy link
Contributor

Centril commented Nov 30, 2018

🎉 Huzzah! This RFC has been merged! 🎉

Tracking issue: rust-lang/rust#50907
Stabilization PR: rust-lang/rust#56362

@varkor varkor deleted the exhaustive-integer-pattern-matching branch November 30, 2018 23:19
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Dec 6, 2018
…-patterns, r=nikomatsakis

Stabilise exhaustive integer patterns

This is dependent on the FCP for rust-lang/rfcs#2591 being completed, but that should happen tomorrow, so there's little harm in opening this PR early.

Closes rust-lang#50907.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exhaustiveness Proposals relating to exhaustiveness of pattern matching. A-patterns Pattern matching related proposals & ideas A-primitive Primitive types related proposals & ideas disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this RFC. T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants