You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tracking issue for RFC 2591: precise pattern matching on pointer size types #56354
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.
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).
I am so confused by this. I currently have code to the effect of
match0usize{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?
@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?
Activity
SergioBenitez commentedon Oct 23, 2019
Is there anything preventing the stabilization of this feature?
varkor commentedon Oct 23, 2019
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.
workingjubilee commentedon Apr 9, 2021
I believe that if
half_open_range_patternsreceive 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).roblabla commentedon Oct 4, 2022
I am so confused by this. I currently have code to the effect of
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?
workingjubilee commentedon Mar 5, 2023
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.
Nadrieril commentedon Dec 1, 2023
@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?Nadrieril commentedon Dec 4, 2023
In #118598 I propose to deprecate this feature gate in favor of half-open range patterns
Rollup merge of rust-lang#118598 - Nadrieril:remove_precise_pointer_s…
Unrolled build for rust-lang#118598