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

More flexible and robust deriving code #6267

Closed
wants to merge 5 commits into from

Conversation

huonw
Copy link
Member

@huonw huonw commented May 6, 2013

This "finishes" the generic deriving code (which I started in #5640), in the sense it supports everything that I can think of being useful. (Including lifetimes and type parameters on methods and traits, arguments and return values of (almost) any type, static methods.)

It closes #6149, but met with #6257, so the following doesn't work:

#[deriving(TotalEq)]
struct Foo<'self>(&'self int);

(It only fails for TotalOrd, TotalEq and Clone, since they are the only ones that call a method directly on sub-elements of the type, which means that the auto-deref interferes with the pointer.)

It also makes Rand (chooses a random variant, fills the fields with random values, including recursively for recursive types) and ToStr (x.to_str() is the same as fmt!("%?", x)) derivable, as well as converting IterBytes to the generic code (which made the code 2.5x shorter, more robust and added support for tuple structs).

({En,De}codable are trickier, so I'll convert them over later.)

huonw added 4 commits May 7, 2013 01:33
… traits.

This adds support for static methods, and arguments of most types, traits with
type parameters, methods with type parameters (and lifetimes for both), as well
as making the code more robust to support deriving on types with lifetimes (i.e.
'self).
The former fills each field of a struct or enum variant with a random
value (and picks a random enum variant). The latter makes the .to_str
method have the same output as fmt!("%?", ..).
@huonw
Copy link
Member Author

huonw commented May 6, 2013

This patch means that the following are deriving-able: Clone, Eq, Ord, TotalEq, TotalOrd, Rand, ToStr, Encodable, Decodable and IterBytes.

I feel like this feature should be added to the documentation somewhere given it doesn't appear at all. I'm willing to do so, but I have no idea where it should go (in the manual presumably, but which section?).

@huonw
Copy link
Member Author

huonw commented May 7, 2013

@pcwalton I just xfail-fast'd the tests that failed on Windows. (I'm not sure if this is the correct thing to do, but they pass perfectly on Linux for me.)

@nikomatsakis
Copy link
Contributor

The problem is that the checkfast procedure does not generate a use core at the top of the combined program that it generates. This is not really a concern of this PR in particular, but it'd be simple enough to fix. I am inclined to think, as a separate issue, that use core ought to be in the prelude. In any case, rather than JUST xfail-fasting them, can we put a comment as well explaining why? Potentially we could open an issue for this problem as well.

bors added a commit that referenced this pull request May 8, 2013
…omatsakis

This "finishes" the generic deriving code (which I started in #5640), in the sense it supports everything that I can think of being useful. (Including lifetimes and type parameters on methods and traits, arguments and return values of (almost) any type, static methods.)

It closes #6149, but met with #6257, so the following doesn't work:
```rust
#[deriving(TotalEq)]
struct Foo<'self>(&'self int);
```
(It only fails for `TotalOrd`, `TotalEq` and `Clone`, since they are the only ones that call a method directly on sub-elements of the type, which means that the auto-deref interferes with the pointer.)

It also makes `Rand` (chooses a random variant, fills the fields with random values, including recursively for recursive types) and `ToStr` (`x.to_str()` is the same as `fmt!("%?", x)`) derivable, as well as converting IterBytes to the generic code (which made the code 2.5x shorter, more robust and added support for tuple structs).

({En,De}codable are trickier, so I'll convert them over later.)
@bors bors closed this May 8, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 20, 2020
Fix or_fun_call for index operator

changelog: Fix or_fun_call for index operator

Fixes rust-lang#6266
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.

None yet

4 participants