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

Change mock!'s syntax for traits #205

Merged
merged 3 commits into from
Sep 7, 2020
Merged

Change mock!'s syntax for traits #205

merged 3 commits into from
Sep 7, 2020

Conversation

asomers
Copy link
Owner

@asomers asomers commented Sep 7, 2020

Previously the syntax looked like a trait definition `trait X`.  But
that's ambiguous in the case of generic traits.  It doesn't make clear
the relationship between the trait's generic parameters and the struct's
generic parameters.  And it made it impossible for a concrete struct to
implement a generic trait.

The new syntax looks like a trait impl `impl X for Y`.  That solves all
the problems with generics.  In addition, it allows `mock!` to implement
traits that aren't imported directly into the current namespace
`impl x::y::Z for Foo`.

The old syntax is deprecated, but will be supported for at least one
more release.

Fixes #119

This may allow some simplification to the code.  And it's neccessary
in order to someday allow concrete structs that implement generic traits.
Previously the syntax looked like a trait definition (trait X).  But
that's ambiguous in the case of generic traits.  It doesn't make clear
the relationship between the trait's generic parameters and the struct's
generic parameters.  And it made it impossible for a concrete struct to
implement a generic trait.

The new syntax looks like a trait impl (impl X for Y).  That solves all
the problems with generics.  In addition, it allows mock! to implement
traits that aren't imported directly into the current namespace
(impl x::y::Z for Foo).

The old syntax is deprecated, but will be supported for at least one
more release.

Fixes #119
@asomers asomers merged commit 16b4524 into master Sep 7, 2020
@asomers asomers deleted the impl_instead_of_trait branch September 7, 2020 19:48
asomers added a commit that referenced this pull request Oct 2, 2020
It's remarkable that the compiler accepts this without complaint.

Also, fix an incorrect comment from the same commit.  The
AngleBracketedGenericArguments will also be present when using automock
asomers added a commit that referenced this pull request Oct 2, 2020
Delete a weird copypasta from PR #205
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

1 participant