Skip to content

Inconsistency with 1-tuples #4898

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

Closed
catamorphism opened this issue Feb 12, 2013 · 9 comments
Closed

Inconsistency with 1-tuples #4898

catamorphism opened this issue Feb 12, 2013 · 9 comments
Labels
A-grammar Area: The grammar of Rust A-parser Area: The lexing & parsing of Rust source code to an AST

Comments

@catamorphism
Copy link
Contributor

We allow patterns on 1-tuples, at least in theory:

match z {
    (x,) => { ... }
}

The parser code for 1-tuple patterns didn't quite work as intended, and I fixed that. But then I ran into the problem that I couldn't write a test because there's no way to write a 1-tuple literal or type ((x) gets parsed as x).

Is this intentional? It seems like if we're going to allow 1-tuple patterns, we should also allow 1-tuple terms (perhaps with the same (x,) syntax?)

This came up, as you might expect, because of macros: I was trying to replace structural records with tuples in the pipes code (that seemed easier than dynamically generating new struct type names) and I ran into the parser problem, which I was able to fix but not test.

@catamorphism
Copy link
Contributor Author

I am going to go ahead and implement 1-tuple literals in a branch (with the same syntax as patterns) and see how ugly it ends up making things.

@ghost ghost assigned catamorphism Feb 12, 2013
@graydon
Copy link
Contributor

graydon commented Feb 12, 2013

1-tuples strike me as a bit silly; if it's solvable inside the macro I'd prefer that. Otherwise I won't lose a ton of sleep over 1-tuples. The biggest risk to me seems to be in the grammar, concerning potential ambiguity of commas, and I imagine any such risks are already present.

@catamorphism
Copy link
Contributor Author

Still to-do: to_str and eq impls for 1-tuples (needs a snapshot). I guess we might as well...

@catamorphism
Copy link
Contributor Author

Also needing a snapshot: fix repr, and add a test to the exact_repr tests.

bors added a commit that referenced this issue Feb 19, 2013
r? @graydon - This is for greater uniformity (for example, macros that generate
tuples). rustc already supported 1-tuple patterns, but there was no
way to construct a 1-tuple term.

@graydon , as far as your comment on #4898 - it did turn out to be solvable inside the macro (since @luqmana already fixed it using structs instead), but I still think it's a good idea to allow 1-tuples, for uniformity. I don't think anyone is likely to trip over it, and I'm not too worried that it changes the amount of ambiguity.
@graydon
Copy link
Contributor

graydon commented Mar 25, 2013

looks like there is a test in for this now; is it done?

@graydon
Copy link
Contributor

graydon commented Mar 25, 2013

non-critical for 0.6, de-milestoning

@catamorphism
Copy link
Contributor Author

It's not done yet -- there were some parts waiting for a snapshot, which has happened now.

@catamorphism
Copy link
Contributor Author

Done, pending bors (#5547)

catamorphism added a commit to catamorphism/rust that referenced this issue Mar 26, 2013
@catamorphism
Copy link
Contributor Author

Done in 5011d05

@catamorphism catamorphism removed their assignment Jun 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust A-parser Area: The lexing & parsing of Rust source code to an AST
Projects
None yet
Development

No branches or pull requests

2 participants