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

Multiple impls within a module #13

Closed
nrxus opened this issue Jan 2, 2020 · 3 comments
Closed

Multiple impls within a module #13

nrxus opened this issue Jan 2, 2020 · 3 comments

Comments

@nrxus
Copy link
Owner

nrxus commented Jan 2, 2020

#[faux::methods]creates a module with the name of the struct being mocked.

This means that if there are multiple impl blocks for the same type, two modules with the same name would be created in the same scope, hence collide, and fail to compile.

rust-lang/rust#8995 would lift the requirement of making the dummy modules and fix this but I do not see an ETA in it being done soon.

Multiple impls within the same module is rare since we do not support generics nor trait impls but once we start supporting them this issue would become more important.

Multiple impls are allowed as long as there is no more than one inherent implementation and no more than one trait implementation per trait.

The user can get around this by wrapping impls in a separate module themselves, but forcing the user to write hacks to support this library would be very subpar UX.

A possible solution would be to mock an entire module but that is a bit far from being implemented,

@nrxus
Copy link
Owner Author

nrxus commented Jan 14, 2020

Generics are now supported thanks to 9f1106f

@nrxus
Copy link
Owner Author

nrxus commented Jan 31, 2020

As part of solving #10 a decision was made to also include trait names in the name of the load bearing mod that causes the problem in this issue. This means that an user CAN have multiple impl blocks in a mod as long as no more than one is an inherent implementation impl MyStruct {}, and the rest are all for different traits: impl TraitA for MyStruct {} impl TraitB for MyStruct {} works.

@nrxus
Copy link
Owner Author

nrxus commented Sep 9, 2022

Fixed in: f694453

@nrxus nrxus closed this as completed Sep 9, 2022
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

No branches or pull requests

1 participant