Is it possible to disable Rust's lifetime elision on a per-file basis, maybe with an #[attribute]
?
I'm learning about lifetimes and I think this might help.
Is it possible to disable Rust's lifetime elision on a per-file basis, maybe with an #[attribute]
?
I'm learning about lifetimes and I think this might help.
Copyright © 2021 Jogjafile Inc.
No.
The best alternative I can offer is to request a Clippy feature that is the opposite of
needless_lifetimes
and then enable it. I don't know if such a request would be wanted by other people though.In the meantime, you could enable that lint and manually make sure that it fires for every function.
For reference, there are only 3 rules:
For what it's worth, before Rust 1.0, these 3 lifetime elision rules didn't exist, there was only the first. However, something like 87% of all functions and methods in the standard library that used references were covered by the 3 elision rules, which is why they were adopted. Lifetime elision is the common case.