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

Add overloaded operators for ptr #2122

Closed
brson opened this issue Apr 4, 2012 · 7 comments · Fixed by #7631
Closed

Add overloaded operators for ptr #2122

brson opened this issue Apr 4, 2012 · 7 comments · Fixed by #7631
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@brson
Copy link
Contributor

brson commented Apr 4, 2012

This seems like an obvious use case for operator overloading. Probably export them from core by default.

@ghost ghost assigned brson Apr 5, 2012
@eholk
Copy link
Contributor

eholk commented May 25, 2012

What operators did you have in mind? Things like + for ptr::offset?

@brson
Copy link
Contributor Author

brson commented May 26, 2012

yes, + and -

@pcwalton
Copy link
Contributor

pcwalton commented Aug 7, 2012

Not going to work right now, because operators can't be unsafe. Not sure how to change that either.

Going to close for now.

@pcwalton pcwalton closed this as completed Aug 7, 2012
@eholk
Copy link
Contributor

eholk commented Aug 7, 2012

At least for +, the operator could be "safe" with an unsafe block inside of it. You aren't going to have problems if you do pointer arithmetic until you dereference it, which would be unsafe anyway. In other words, if ptr::addr_of is safe (which is is), then it seems like pointer arithmetic is also safe.

@brson
Copy link
Contributor Author

brson commented Aug 7, 2012

Yeah, that's true. We consider arithmetic safe, but indexing and dereferencing unsafe. Just having + would be convenient.

@brson brson reopened this Aug 7, 2012
@MarkJr94
Copy link
Contributor

MarkJr94 commented Jul 6, 2013

I'm going to try on work on this. I'll add overloaded + and -. I'll use impl<T, I: Int> Add<I, *T> for T* as dbaupp suggested on IRC so that it will work with any primitive integer type.

@bstrie
Copy link
Contributor

bstrie commented Jul 15, 2013

Looks like #7631 added + and - for unsafe pointers, can this be closed?

celinval added a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Add fixme tests for rust-lang#2121 to the expected suite since the test should fail, but not crash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants