Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upRemove uses of transmute #60
Comments
This comment has been minimized.
This comment has been minimized.
|
Do we have a good replacement of FromPrimitive by now? That is the sole reason that code exists in the first place. Must uses of transmute are unfortunately not unnessesary here but caused by limitations of rustc. Replacing them would make the code much slower and harder to read. |
This comment has been minimized.
This comment has been minimized.
|
The good replacement is to make match arms and let the optimiser get rid of it. It also help readability, contrary to what you just stated. |
This comment has been minimized.
This comment has been minimized.
|
I was referring to most uses of transmute which is not in from_u8. |
This comment has been minimized.
This comment has been minimized.
|
They all hurt readability. |
This comment has been minimized.
This comment has been minimized.
|
Which is simply not true. If you find a replacement which doesn't involve wild boxing I'm happy to make that change. As you can read from the comments I tried hard to get rid of them. |
This comment has been minimized.
This comment has been minimized.
est31
commented
Jul 21, 2017
There are a couple of crates for that: |
This comment has been minimized.
This comment has been minimized.
|
Transmutes for // This transmute just casts the lifetime away. Since Rust only
// has SESE regions, this early return cannot be worked out and
// such that the borrow region of self includes the whole block.
// The explixit lifetimes in the function signature ensure that
// this is safe.
// ### NOTE
// To check that everything is sound, return the result without
// the match (e.g. `return Ok(try!(self.next_state(buf)))`). If
// it compiles the returned lifetime is correct.
unsafe {
mem::transmute::<Decoded, Decoded>(result)
}I wonder if the upcoming non-lexical lifetimes would help with that? |
nox commentedJul 21, 2017
Most uses of
transmuteare useless and security hazards, they should be replaced by something less magical. For examples the various transmute calls infrom_u8methods can be replaced entirely by safe code.