Skip to content

syntax: Allow 1-tuple expressions #5002

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
wants to merge 2 commits into from

Conversation

catamorphism
Copy link
Contributor

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.

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.
@mitsuhiko
Copy link
Contributor

I think there is another dependency in the repr module:

diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs
index 7f1687b..5055b7b 100644
--- a/src/libcore/repr.rs
+++ b/src/libcore/repr.rs
@@ -448,7 +448,9 @@ impl TyVisitor for ReprVisitor {
         true
     }
     fn visit_leave_tup(&self, _n_fields: uint,
-                       _sz: uint, _align: uint) -> bool {
+                       sz: uint, _align: uint) -> bool {
+        if (sz == 1)
+            self.writer.write_char(',');
         self.writer.write_char(')');
         true
     }

@catamorphism
Copy link
Contributor Author

@mitsuhiko Ah, thanks, I'll try to add a test case for that (and fix it, of course).

@catamorphism
Copy link
Contributor Author

I actually don't know how to test the change to the repr module -- I've never written any code involving visitors. Any ideas? edit: Never mind -- Graydon said "in core::repr, see the exact_test cases"

bors added a commit that referenced this pull request 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.
@bors bors closed this Feb 19, 2013
bors added a commit to rust-lang-ci/rust that referenced this pull request May 2, 2020
build: Use rustfmt from lastest nightly that contains it

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants