servoshell: Fix function_casts_as_integer lint (#43469)

Found when building with Rust 1.94. The lint itself only complains about
the direct function ptr to usize cast and recommends an intermediate `as
*const ()` cast. We also don't need provenance here, so we can also use
the more explicit .addr() cast.

Testing: Covered by compilation in CI.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender
2026-03-20 08:06:01 +01:00
committed by GitHub
parent 0149bc7f93
commit e4eca03a7b

View File

@@ -19,7 +19,7 @@ pub(crate) fn print(w: &mut dyn std::io::Write) -> Result<(), std::io::Error> {
w, w,
"{:?}", "{:?}",
Print { Print {
print_fn_address: print as usize, print_fn_address: (print as *const ()).addr(),
} }
) )
} }
@@ -30,12 +30,13 @@ pub(crate) fn print_ohos() {
log::error!( log::error!(
"{:?}", "{:?}",
Print { Print {
print_fn_address: print as usize, print_fn_address: (print as *const ()).addr(),
} }
) )
} }
struct Print { struct Print {
/// Function pointer without provenance - do not cast back and dereference.
print_fn_address: usize, print_fn_address: usize,
} }
@@ -48,7 +49,7 @@ impl fmt::Debug for Print {
let mut print_fn_frame = 0; let mut print_fn_frame = 0;
let mut frame_count = 0; let mut frame_count = 0;
backtrace::trace_unsynchronized(|frame| { backtrace::trace_unsynchronized(|frame| {
let found = frame.symbol_address() as usize == self.print_fn_address; let found = frame.symbol_address().addr() == self.print_fn_address;
if found { if found {
print_fn_frame = frame_count; print_fn_frame = frame_count;
} }