-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Description
The PR #33460 added something, which is good, but it also introduces problems with library authors who want to provide support (or don't want to provide support) for those platforms.
In my code I have added a macro:
macro_rules! convert_to_usize {
( $val:expr, $val_type:ident ) => { {
let converted :usize = $val as usize;
if $val != converted as $val_type {
try!(Err(LibraryError::BufferNotAddressable));
}
converted
}}
}
Its very useful and nice.
Right now I only use it when the outcome of a calculation could theoretically be larger than the 32 bit address space, when converting u64 values to usize, as rust up to now only supported platforms with at least 32 bits.
Now it seems I'll have to add it to u32 -> usize conversions as well.
In order for me to do the transition some #![forbid(downcast_to_usize)]
like feature would be nice, otherwise I'd miss something.
Also that feature would help library authors who wish to not support 16 bit architectures (due to the additional maintenance burden because now they had to watch every usize downcast) to simply add such a #![forbid(downcast_to_usize)]
to their code, and it stops from compiling.
Its always better to have code not compile than having to explain things in the docs.