This issue is part of the Strict Provenance Experiment - #95228
We should make it easier for people to detect places where they are using casts instead of the "blessed" strict_provenance APIs.
@eddyb and I prototyped this out here: 93f7f06
The patch needs some cleanups, though. Quoting from elsewhere:
All lints should be made allow by default, meaning they're opt-in.
At least in the bootstrap, the compiler will complain if you allow() a lint in your code that doesn't exist. This potentially just means:
- We need to keep the experimental lint around forever even when the experiment is over
- Users can only "safely" invoke it from the command line manually, which is slightly unfortunate for anything like what I did where I used it as a FIXME/WONTFIX marker for the file.
Also due to the "Opaque Function Pointers" / "Harvard Architecture" / "AVR is cursed" issue
|
// HACK: The intermediate cast as usize is required for AVR |
|
// so that the address space of the source function pointer |
|
// is preserved in the final function pointer. |
|
// |
|
// https://github.com/avr-rust/rust/issues/143 |
|
fmt::Pointer::fmt(&(*self as usize as *const ()), f) |
I think we want the lint broken up into parts:
#[fuzzy_provenance_casts] - int-to-ptr, totally evil
#[lossy_provencance_casts] - ptr-to-int, sketchy but valid as long as you actually want .addr() semantics
#[oxford_casts] - casts that make harvard architectures sad -- fn<->ptr (name is a joke... unless...)
I can't justify discouraging fn <-> int, absent better ways to talk about fn ptrs properly.
This issue is part of the Strict Provenance Experiment - #95228
We should make it easier for people to detect places where they are using casts instead of the "blessed" strict_provenance APIs.
@eddyb and I prototyped this out here: 93f7f06
The patch needs some cleanups, though. Quoting from elsewhere:
All lints should be made allow by default, meaning they're opt-in.
At least in the bootstrap, the compiler will complain if you
allow()a lint in your code that doesn't exist. This potentially just means:Also due to the "Opaque Function Pointers" / "Harvard Architecture" / "AVR is cursed" issue
rust/library/core/src/ptr/mod.rs
Lines 1390 to 1395 in 9280445
I think we want the lint broken up into parts:
#[fuzzy_provenance_casts]- int-to-ptr, totally evil#[lossy_provencance_casts]- ptr-to-int, sketchy but valid as long as you actually want.addr()semantics#[oxford_casts]- casts that make harvard architectures sad -- fn<->ptr (name is a joke... unless...)I can't justify discouraging
fn <-> int, absent better ways to talk about fn ptrs properly.