<*const T>::offset should be offset_arith
Closed this issue · 4 comments
According to https://www.cl.cam.ac.uk/~km569/into_the_depths_of_C.pdf,
In practice it seems to be common to transiently construct out-of-bounds pointers...
So long as they are brought back in-bounds before being used to access memory, many experts believe this will work; our survey (Question [9/15]) gave: yes: 230 (73%)
offset has the opposite behavior, where if an out of bounds pointer is created even transiently, it will create undefined behavior. I think this is incorrect and confusing, and should be changed. We should add an offset_inbounds method to access LLVM's GEPi, for optimization of iterators.
Does that reasoning actually hold, when Rust does not (IIRC) permit pointer subtraction, which is needed to make that useful?
@eternaleye offset takes an isize, so pointer subtraction is a thing in Rust.
Huh, guess I misremembered then.
This sounds more like a proposed API behavior change (that should be taken up with the libs team) to me than a question of "what is the semantics or what should it be". So I am going to close this.