Skip to contentSkip to conversation

rust: restrict missing_const_for_fn to qemu_api crate

PATCH In review Paolo Bonzini 2 participants 2 messages Feb 7, 2025 – Feb 10, 2025 Rust

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: restrict missing_const_for_fn to qemu_api crate

missing_const_for_fn is not necessarily useful or good. For example in a private API you can always add const later, and in a public API it can be unnecessarily restrictive to annotate everything with const (blocking further improvements to the API).

Nevertheless, QEMU turns it on because qemu_api uses const quite aggressively and therefore it can be handy to have as much as possible annotated with const. Outside qemu_api though, not so much: devices are self contained consumers and if there is nothing that could use their functions in const contexts that were not anticipated.

Since missing_const_for_fn can be a bit noisy and trigger on trivial functions that no one would ever call in const context, do not turn it on everywhere and only keep it in qemu_api as a special case.

---
 rust/Cargo.toml          | 1 -
 rust/qemu-api/src/lib.rs | 2 ++
 2 files changed, 2 insertions(+), 1 deletion(-)
rust/Cargo.toml +0 -1
index 5b6b6ca4382..5b0cb559286 100644
@@ -52,7 +52,6 @@ empty_structs_with_brackets = "deny"
 ignored_unit_patterns = "deny"
 implicit_clone = "deny"
 macro_use_imports = "deny"
-missing_const_for_fn = "deny"
 missing_safety_doc = "deny"
 multiple_crate_versions = "deny"
 mut_mut = "deny"
rust/qemu-api/src/lib.rs +2 -0
index bfb6c6d6e42..20134d75ce5 100644
@@ -4,6 +4,8 @@
 
 #![cfg_attr(not(MESON), doc = include_str!("../README.md"))]
 
+#![deny(clippy::missing_const_for_fn)]
+
 #[rustfmt::skip]
 pub mod bindings;
 
Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Paolo Bonzini

missing_const_for_fn is not necessarily useful or good. For example in a private API you can always add const later, and in a public API it can be unnecessarily restrictive to annotate everything with const (blocking further improvements to the API).

Nevertheless, QEMU turns it on because qemu_api uses const quite aggressively and therefore it can be handy to have as much as possible annotated with const. Outside qemu_api though, not so much: devices are self contained consumers and if there is nothing that could use their functions in const contexts that were not anticipated.

Quoted 5 lines

Since missing_const_for_fn can be a bit noisy and trigger on trivial functions that no one would ever call in const context, do not turn it on everywhere and only keep it in qemu_api as a special case.