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

Handle unary minus #1

Closed
lfairy opened this Issue Apr 2, 2015 · 2 comments

Comments

Projects
None yet
1 participant
@lfairy
Copy link
Owner

lfairy commented Apr 2, 2015

-a can be translated to 0.wrapping_sub(a), but that causes a type error as the 0 is ambiguous.

One workaround is 0i32.wrapping_sub(a), where i32 is replaced with the type of a. But that requires us to know the type of the expression in advance, which is impossible with macros as they run before type inference.

I think we should simply disallow unary minus altogether.

@lfairy

This comment has been minimized.

Copy link
Owner Author

lfairy commented Apr 2, 2015

One solution could be to use Zero::zero(), but I think that still causes ambiguity.

@lfairy

This comment has been minimized.

Copy link
Owner Author

lfairy commented Apr 2, 2015

I just realized we can translate -x to x.wrapping_mul(-1) instead. This side-steps the ambiguity problem because the literal is now on the right-hand side. I'll try this solution tomorrow.

@lfairy lfairy closed this in c702218 Apr 3, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.