From 61657c4d04967e9ede4664aebdfd60c1aaeb21f0 Mon Sep 17 00:00:00 2001 From: Zyad Hassan <88045115+zhassan-aws@users.noreply.github.com> Date: Thu, 16 Jan 2025 15:30:23 -0800 Subject: [PATCH] Use fully-qualified name for size_of (#3838) Add `core::mem::` prefix to all uses of `size_of`. Background: in some cases, I get errors of the form: ``` Compiling kani_core v0.58.0 (https://github.com/model-checking/kani#35015dce) error[E0425]: cannot find function `size_of` in this scope --> /home/ubuntu/.cargo/git/checkouts/kani-0ce0dacf5e98886d/35015dc/library/kani/src/lib.rs:54:1 | 54 | kani_core::kani_lib!(kani); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope | = help: consider importing one of these items: core::mem::size_of crate::core_path::intrinsics::size_of crate::core_path::mem::size_of std::mem::size_of = note: this error originates in the macro `kani_core::ptr_generator` which comes from the expansion of the macro `kani_core::kani_lib` (in Nightly builds, run with -Z macro-backtrace for more info) ``` when adding the Kani library as a dependency. Adding `core::mem::` fixes those issues. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --- library/kani_core/src/arbitrary/pointer.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/kani_core/src/arbitrary/pointer.rs b/library/kani_core/src/arbitrary/pointer.rs index 0e987b1260c6..2222e31b2f0b 100644 --- a/library/kani_core/src/arbitrary/pointer.rs +++ b/library/kani_core/src/arbitrary/pointer.rs @@ -265,7 +265,7 @@ macro_rules! ptr_generator { let ptr = match status { AllocationStatus::Dangling => { // Generate potentially unaligned pointer. - let offset = kani::any_where(|b: &usize| *b < size_of::()); + let offset = kani::any_where(|b: &usize| *b < core::mem::size_of::()); crate::ptr::NonNull::::dangling().as_ptr().wrapping_add(offset) } AllocationStatus::DeadObject => { @@ -279,7 +279,7 @@ macro_rules! ptr_generator { AllocationStatus::OutOfBounds => { // Generate potentially unaligned pointer. let buf_ptr = addr_of_mut!(self.buf) as *mut u8; - let offset = kani::any_where(|b: &usize| *b < size_of::()); + let offset = kani::any_where(|b: &usize| *b < core::mem::size_of::()); unsafe { buf_ptr.add(Self::BUF_LEN - offset) as *mut T } } }; @@ -331,7 +331,7 @@ macro_rules! ptr_generator { "Cannot generate in-bounds object of the requested type. Buffer is not big enough." ); let buf_ptr = addr_of_mut!(self.buf) as *mut u8; - let offset = kani::any_where(|b: &usize| *b <= Self::BUF_LEN - size_of::()); + let offset = kani::any_where(|b: &usize| *b <= Self::BUF_LEN - core::mem::size_of::()); let ptr = unsafe { buf_ptr.add(offset) as *mut T }; let is_initialized = kani::any(); if is_initialized { @@ -356,8 +356,8 @@ macro_rules! ptr_generator_fn { () => { /// Create a pointer generator that fits at least `N` elements of type `T`. pub fn pointer_generator() - -> PointerGenerator<{ size_of::() * NUM_ELTS }> { - PointerGenerator::<{ size_of::() * NUM_ELTS }>::new() + -> PointerGenerator<{ core::mem::size_of::() * NUM_ELTS }> { + PointerGenerator::<{ core::mem::size_of::() * NUM_ELTS }>::new() } }; }