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

Can't use where clauses with tuple structs #17904

Closed
japaric opened this issue Oct 10, 2014 · 6 comments · Fixed by #20424
Closed

Can't use where clauses with tuple structs #17904

japaric opened this issue Oct 10, 2014 · 6 comments · Fixed by #20424

Comments

@japaric
Copy link
Member

japaric commented Oct 10, 2014

STR

// OK
struct Bar<T> where T: Copy {
    inner: T,
}

// Is this the right syntax?
struct Foo<T>(T) where T: Copy;  //~ error: expected `;`, found `where`

fn main() {}

Version

rustc 0.12.0-dev (10fc25a39 2014-10-09 16:04:25 -0500)

(PR 17669 on top of b08ecf7)

@ftxqxd
Copy link
Contributor

ftxqxd commented Oct 10, 2014

struct Foo<T> where T: Copy, (T);

seems to work. However, the syntax is awful, and requires a comma for disambiguation.

@japaric
Copy link
Member Author

japaric commented Dec 21, 2014

struct Foo<T> where T: Copy, (T);  //~ error: unexpected token in `where` clause

@P1start As of today nightly, that doesn't work anymore.

@nikomatsakis It seems that where clauses don't work with tuple structs anymore. Any plans to support them in the future?

@jroesch
Copy link
Member

jroesch commented Dec 23, 2014

@nikomatsakis is this the desired syntax? I'm assuming it was chosen in order to do some kind of parsing disambiguation. I am willing to submit a small patch for this, just want clarification on the syntax.

@nikomatsakis
Copy link
Contributor

hmm afaik they should work, and I would expect the syntax to be struct Foo<...>(...) where ...

@jroesch
Copy link
Member

jroesch commented Dec 24, 2014

I will track this one down and follow up with a PR.

@sfackler
Copy link
Member

You can get the current syntax to compile if the generic type bound uses the Fn trait sugar:

struct Foo<T> where T: Fn() (T);

Nominating, since we won't be able to move the where clause to after the tuple after 1.0 without breakage.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Jan 5, 2015
Fixes rust-lang#17904. All the cases that I believe we should support are detailed in the test case, let me know if there is there is any more desired behavior. cc @japaric.

r? @nikomatsakis or whoever is appropriate.
alexcrichton added a commit to alexcrichton/rust that referenced this issue Jan 6, 2015
Fixes rust-lang#17904. All the cases that I believe we should support are detailed in the test case, let me know if there is there is any more desired behavior. cc @japaric.

r? @nikomatsakis or whoever is appropriate.
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 a pull request may close this issue.

5 participants