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

RFC: `..` in patterns #1492

Merged
merged 2 commits into from May 13, 2016

Conversation

Projects
None yet
7 participants
@petrochenkov
Copy link
Contributor

petrochenkov commented Feb 6, 2016

Permit the .. pattern fragment in more contexts.

Rendered

@petrochenkov petrochenkov force-pushed the petrochenkov:patdotdot branch from cf5dc8c to 2cd24ce Feb 6, 2016

@petrochenkov

This comment has been minimized.

Copy link
Contributor Author

petrochenkov commented Feb 6, 2016

[unresolved]: #unresolved-questions

Sublist binding syntax conflicts with possible exclusive range patterns
`begin .. end`/`begin..`/`..end`. This problem already exists for slice patterns and has to be

This comment has been minimized.

@oli-obk

oli-obk Feb 8, 2016

Contributor

Slice patterns are unstable (and buggy), and thus can easily be changed.

This comment has been minimized.

@petrochenkov

petrochenkov Feb 8, 2016

Author Contributor

Extensions proposed in this RFC are going to be unstable too and are supposed to be changed together with slice patterns if changed at all.

S(subpat1, .., subpatN)
// **NEW**: Tuple struct patterns, any position with a sublist binding.
// The binding has a tuple type.
S(subpat1, binding.., subpatN)

This comment has been minimized.

@oli-obk

oli-obk Feb 8, 2016

Contributor

these are somewhat problematic. Afaik there's no guarantee that (B, C) has the same memory layout as the last two parts of (A, B, C), so taking a slice into a tuple might not be so trivial.

This comment has been minimized.

@petrochenkov

petrochenkov Feb 8, 2016

Author Contributor

Hmm, this is an interesting observation.
It means that at least by ref bindings have to be restricted.
I'll update the RFC.

@oli-obk

This comment has been minimized.

Copy link
Contributor

oli-obk commented Feb 8, 2016

Should S(a, b, ..) be allowed for struct S(A, B); ? For structs it currently is: http://is.gd/TsMz6N .

@petrochenkov

This comment has been minimized.

Copy link
Contributor Author

petrochenkov commented Feb 8, 2016

Should S(a, b, ..) be allowed for struct S(A, B); ?

Yes, .. means 0 or more subpatterns.

@nrc nrc added the T-lang label Feb 8, 2016

@aturon aturon self-assigned this Feb 11, 2016

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Feb 11, 2016

This was pretty Always The Plan -- but we never did it because it involved work. I'm basically 👍 though I've not read the details of the RFC.

bors added a commit to rust-lang/rust that referenced this pull request Feb 17, 2016

Auto merge of #31685 - petrochenkov:patrefact2, r=eddyb
And split `PatKind::Enum` into `PatKind::TupleStruct` and `PatKind::Path`.
This is the HIR part of #31581.
This is also kind of a preparation for rust-lang/rfcs#1492.

r? @eddyb

bors added a commit to rust-lang/rust that referenced this pull request Feb 17, 2016

Auto merge of #31685 - petrochenkov:patrefact2, r=eddyb
And split `PatKind::Enum` into `PatKind::TupleStruct` and `PatKind::Path`.
This is the HIR part of #31581.
This is also kind of a preparation for rust-lang/rfcs#1492.

r? @eddyb
@petrochenkov

This comment has been minimized.

Copy link
Contributor Author

petrochenkov commented Mar 6, 2016

Implementation (without sub-list bindings): rust-lang/rust#32079

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Apr 12, 2016

Nominating for FCP.

@petrochenkov

This comment has been minimized.

Copy link
Contributor Author

petrochenkov commented Apr 27, 2016

I should probably strike out the sub-tuple bindings (a, b, c..) from this RFC given the discussion in #1582 and #376, at least for now.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 2, 2016

Hear ye, hear ye! This RFC is now entering final comment period.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 2, 2016

@petrochenkov very well... to be honest I've not read this closely, though I'm in favor of the spirit. We had decided to put this into FCP, but would you rather we wait? (We can keep your proposed edit in mind, I imagine.)

[subpat1, .., subpatN]
// Slice patterns, any of the above with a subslice binding.
// By ref bindings are allowed, slices and subslices always have compatible layouts.
[subpat1, binding.., subpatN]

This comment has been minimized.

@nikomatsakis

nikomatsakis May 12, 2016

Contributor

What does this binding mean? This feels like it overlaps with slice patterns, which (I think) still require some further RFC to "complete"? I can't remember if we postponed that work or not. :)

This comment has been minimized.

@petrochenkov

petrochenkov May 12, 2016

Author Contributor

What does this binding mean?

A subslice pattern, see above - "The binding is not actually a binding, but one more pattern ..."

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 12, 2016

I'd be (more) in favor of a variant of this that excludes all "bindings". In other words, allowing:

(pat*, .., pat*)
Foo(pat*, .., pat*)

and I'd probably prefer to exclude [] patterns which I think ought to be handled separately.

The binding forms introduce complicated semantics.

@petrochenkov

This comment has been minimized.

Copy link
Contributor Author

petrochenkov commented May 12, 2016

@nikomatsakis

I'd probably prefer to exclude [] patterns

This RFC doesn't propose any changes to slice patterns, it only uses them for analogy.

I'd be (more) in favor of a variant of this that excludes all "bindings".

With this I agree.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 12, 2016

@petrochenkov

This RFC doesn't propose any changes to slice patterns, it only uses them for analogy.

Huh. OK, I must have misread it. So much the better.

@brendanzab

This comment has been minimized.

Copy link
Member

brendanzab commented May 12, 2016

I missed that subtlety too - maybe removing the slice examples might make it clearer?

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 13, 2016

Huzzah! The @rust-lang/lang team has decided to accept this RFC. Specifically:

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented May 13, 2016

Tracking issue: rust-lang/rust#33627

If you'd like to keep following the development of this feature, please subscribe to that issue, thanks! :)

@nikomatsakis nikomatsakis merged commit 4e9e843 into rust-lang:master May 13, 2016

@petrochenkov petrochenkov deleted the petrochenkov:patdotdot branch Sep 21, 2016

critiqjo pushed a commit to critiqjo/rustdoc that referenced this pull request Dec 16, 2016

Auto merge of #31685 - petrochenkov:patrefact2, r=eddyb
And split `PatKind::Enum` into `PatKind::TupleStruct` and `PatKind::Path`.
This is the HIR part of rust-lang/rust#31581.
This is also kind of a preparation for rust-lang/rfcs#1492.

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.