Are casts encouraged in Rust?
Are casts encouraged in Rust?
Posted Jun 29, 2025 20:29 UTC (Sun) by epilys (subscriber, #153643)In reply to: Are casts encouraged in Rust? by alx.manpages
Parent article: How to write Rust in the kernel: part 2
The good news is that if you wish to not allow them in your codebase, you can use lints like `clippy::as_conversions` and deny them globally: https://rust-lang.github.io/rust-clippy/master/#as_conversions
Posted Jul 2, 2025 17:09 UTC (Wed)
by pbonzini (subscriber, #60935)
[Link]
Posted Jul 2, 2025 20:32 UTC (Wed)
by alx.manpages (subscriber, #145117)
[Link] (1 responses)
Posted Jul 3, 2025 11:54 UTC (Thu)
by farnz (subscriber, #17727)
[Link]
There's thus a lot of design work in getting this right; it's OK if the initial solution only solves for some of these problems, as long as it doesn't block off useful bits of the design space for other solutions. I'd thus expect that we'll have a decent solution to the first problem - traits usable in const and non-const contexts if they implement a function as const fn, but only in non-const contexts if they implement it as fn - long before the other 2 get solved, because it's the lynchpin on which the other two stand - and indeed, work on this is actively happening, leading to an early design that's being pushed around until people are confident that it's a good design.
Are casts encouraged in Rust?
Are casts encouraged in Rust?
Casts are a known problem, and (AIUI) people are working to make the "as conversions" clippy lint a warn-by-default lint. There's some issues to resolve before we get there:
Casts are a known problem