4 ms·
> A possible direction for future exploration would be to use the rustc driver API to create a custom static analysis tool that could recognize some form of syn
by wallacoloo 6y ago
> A possible direction for future exploration would be to use the rustc driver API to create a custom static analysis tool that could recognize some form of syntax for this and then check that "explicit" functions don't accidentally call "non-explicit" functions without explicit overrides, much like unsafe.
By “some form of syntax”, it could be as simple as an attribute. Those are easily consumable by rustc plugins* or even proc-macros.
#[explicit]
fn my_explicit_fn() { ... }
If traits could be implemented on functions, you could even pull it off with a proc-macro-derive: no need to use a custom rustc binary for that. Your proc-macro just scans all the function calls made within said function and then adds something like:
unsafe impl Explicit for my_explicit_fn
where
fn_called_from_my_explicit_fn: Explicit,
other_fn_called_from_my_explicit_fn: Explicit
{}
You’d need to enable the trivial trait bounds feature for something like the above to work.
Cool ideas. I’d love to see rust become flexible enough that people are able to experiment with more things like this without having to hack at rustc’s source code.
* outdated terminology, but I think conceptually you still do this sort of thing with a plugin-like system.
- deleted 6y ago[deleted]