Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e10a8f6
add loop-invariants and harnesses
thanhnguyen-aws Jul 28, 2025
8f02ac9
format fix
thanhnguyen-aws Jul 28, 2025
617804e
fix harness name
thanhnguyen-aws Jul 28, 2025
dcf1882
add crate::kani
thanhnguyen-aws Jul 29, 2025
5ccddc7
fix format
thanhnguyen-aws Jul 29, 2025
4844377
fix format
thanhnguyen-aws Jul 29, 2025
ce54852
fix invariant
thanhnguyen-aws Jul 29, 2025
9bd7cc2
fix invariant
thanhnguyen-aws Jul 29, 2025
da0761a
add quantifiers to loop invariant
thanhnguyen-aws Aug 1, 2025
67098c5
add im port kani
thanhnguyen-aws Aug 4, 2025
abda27a
add cfg kani
thanhnguyen-aws Aug 4, 2025
55e641f
Merge branch 'main' into memchrinvariant
thanhnguyen-aws Aug 11, 2025
864098f
add -Z quantifiers
thanhnguyen-aws Aug 15, 2025
98e10c4
Merge branch 'memchrinvariant' of https://github.com/thanhnguyen-aws/…
thanhnguyen-aws Aug 15, 2025
ab64f85
Make forall compile
tautschnig Aug 15, 2025
b701f3a
Fix formatting, make flux happy
tautschnig Aug 15, 2025
e5515d6
change unwind to solver(cvc5)
thanhnguyen-aws Aug 18, 2025
b4a38b9
Merge branch 'main' into memchrinvariant
thanhnguyen-aws Aug 18, 2025
a96b095
change unwind to solver(cvc5)
thanhnguyen-aws Aug 18, 2025
fac264f
Merge branch 'memchrinvariant' of https://github.com/thanhnguyen-aws/…
thanhnguyen-aws Aug 18, 2025
e411051
add target_arch cfg
thanhnguyen-aws Aug 18, 2025
c090506
Merge subtree update for toolchain nightly-2025-08-18 (#467)
github-actions[bot] Aug 19, 2025
1780de6
Merge branch 'main' into memchrinvariant
thanhnguyen-aws Aug 19, 2025
c2631f2
Merge subtree update for toolchain nightly-2025-08-19 (#471)
github-actions[bot] Aug 19, 2025
ca49535
Update Kani Metrics (#469)
github-actions[bot] Aug 19, 2025
c357e47
using quantifiers in CStr
thanhnguyen-aws Aug 19, 2025
be834b0
Merge branch 'memchrinvariant' of https://github.com/thanhnguyen-aws/…
thanhnguyen-aws Aug 19, 2025
b24e668
add import forall
thanhnguyen-aws Aug 19, 2025
797b38e
fix typo
thanhnguyen-aws Aug 19, 2025
7fda174
fix format
thanhnguyen-aws Aug 19, 2025
1231f86
VeriFast solution for Challenge 5 (linked_list.rs) (#238)
btj Aug 20, 2025
c753437
temporarily disable is_safe check for CStr
thanhnguyen-aws Aug 20, 2025
f2db5e4
temporarily disable is_safe check for CStr
thanhnguyen-aws Aug 20, 2025
5ea263a
temporarily disable is_safe check for CStr
thanhnguyen-aws Aug 20, 2025
2a203c5
Merge subtree update for toolchain nightly-2025-08-20 (#476)
github-actions[bot] Aug 21, 2025
92d5e64
Merge branch 'main' into memchrinvariant
tautschnig Aug 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/flux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
FIXPOINT_VERSION: "556104ba5508891c357b0bdf819ce706e93d9349"
FLUX_VERSION: "ebafb8d0ca32d8c0fcd2a0cfef6b1b4bd4dc4a6f"
FLUX_VERSION: "a17246965a8752e3d3d4e3559865311048bb61f7"

jobs:
check-flux-on-core:
Expand Down
5 changes: 3 additions & 2 deletions doc/src/challenges/0005-linked-list.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Challenge 5: Verify functions iterating over inductive data type: `linked_list`

- **Status:** Open
- **Status:** Resolved
- **Tracking Issue:** [#29](https://github.com/model-checking/verify-rust-std/issues/29)
- **Start date:** *2024/07/01*
- **End date:** *2025/04/10*
- **End date:** *2025/08/12*
- **Reward:** *5,000 USD*
- **Contributors:** [Bart Jacobs](https://github.com/btj)

-------------------

Expand Down
6 changes: 2 additions & 4 deletions library/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Default> Default for Box<T> {
/// Creates a `Box<T>`, with the `Default` value for T.
/// Creates a `Box<T>`, with the `Default` value for `T`.
#[inline]
fn default() -> Self {
let mut x: Box<mem::MaybeUninit<T>> = Box::new_uninit();
Expand All @@ -1695,6 +1695,7 @@ impl<T: Default> Default for Box<T> {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Box<[T]> {
/// Creates an empty `[T]` inside a `Box`.
#[inline]
fn default() -> Self {
let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling();
Expand All @@ -1716,6 +1717,19 @@ impl Default for Box<str> {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "pin_default_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T> Default for Pin<Box<T>>
where
T: ?Sized,
Box<T>: Default,
{
#[inline]
fn default() -> Self {
Box::into_pin(Box::<T>::default())
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT;
/// ]);
/// ```
///
/// ## `Entry` API
///
/// `BTreeMap` implements an [`Entry API`], which allows for complex
/// methods of getting, setting, updating and removing keys and their values:
///
Expand Down
16 changes: 8 additions & 8 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ impl From<&CStr> for CString {
}
}

#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]
impl PartialEq<CStr> for CString {
#[inline]
fn eq(&self, other: &CStr) -> bool {
Expand All @@ -1112,7 +1112,7 @@ impl PartialEq<CStr> for CString {
}
}

#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]
impl PartialEq<&CStr> for CString {
#[inline]
fn eq(&self, other: &&CStr) -> bool {
Expand All @@ -1126,7 +1126,7 @@ impl PartialEq<&CStr> for CString {
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]
impl PartialEq<Cow<'_, CStr>> for CString {
#[inline]
fn eq(&self, other: &Cow<'_, CStr>) -> bool {
Expand Down Expand Up @@ -1221,7 +1221,7 @@ impl CStr {
}
}

#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]
impl PartialEq<CString> for CStr {
#[inline]
fn eq(&self, other: &CString) -> bool {
Expand All @@ -1235,7 +1235,7 @@ impl PartialEq<CString> for CStr {
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]
impl PartialEq<Cow<'_, Self>> for CStr {
#[inline]
fn eq(&self, other: &Cow<'_, Self>) -> bool {
Expand All @@ -1249,7 +1249,7 @@ impl PartialEq<Cow<'_, Self>> for CStr {
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]
impl PartialEq<CStr> for Cow<'_, CStr> {
#[inline]
fn eq(&self, other: &CStr) -> bool {
Expand All @@ -1263,7 +1263,7 @@ impl PartialEq<CStr> for Cow<'_, CStr> {
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]
impl PartialEq<&CStr> for Cow<'_, CStr> {
#[inline]
fn eq(&self, other: &&CStr) -> bool {
Expand All @@ -1277,7 +1277,7 @@ impl PartialEq<&CStr> for Cow<'_, CStr> {
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "c_string_eq_c_str", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "c_string_eq_c_str", since = "1.90.0")]
impl PartialEq<CString> for Cow<'_, CStr> {
#[inline]
fn eq(&self, other: &CString) -> bool {
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
#![feature(async_iterator)]
#![feature(bstr)]
#![feature(bstr_internals)]
#![feature(cast_maybe_uninit)]
#![feature(char_internals)]
#![feature(char_max_len)]
#![feature(clone_to_uninit)]
Expand Down
19 changes: 16 additions & 3 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,7 @@ impl<T: Default> Default for Rc<T> {
/// assert_eq!(*x, 0);
/// ```
#[inline]
fn default() -> Rc<T> {
fn default() -> Self {
unsafe {
Self::from_inner(
Box::leak(Box::write(
Expand All @@ -2373,7 +2373,7 @@ impl<T: Default> Default for Rc<T> {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "more_rc_default_impls", since = "1.80.0")]
impl Default for Rc<str> {
/// Creates an empty str inside an Rc
/// Creates an empty `str` inside an `Rc`.
///
/// This may or may not share an allocation with other Rcs on the same thread.
#[inline]
Expand All @@ -2387,7 +2387,7 @@ impl Default for Rc<str> {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "more_rc_default_impls", since = "1.80.0")]
impl<T> Default for Rc<[T]> {
/// Creates an empty `[T]` inside an Rc
/// Creates an empty `[T]` inside an `Rc`.
///
/// This may or may not share an allocation with other Rcs on the same thread.
#[inline]
Expand All @@ -2397,6 +2397,19 @@ impl<T> Default for Rc<[T]> {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "pin_default_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T> Default for Pin<Rc<T>>
where
T: ?Sized,
Rc<T>: Default,
{
#[inline]
fn default() -> Self {
unsafe { Pin::new_unchecked(Rc::<T>::default()) }
}
}

#[stable(feature = "rust1", since = "1.0.0")]
trait RcEqIdent<T: ?Sized + PartialEq, A: Allocator> {
fn eq(&self, other: &Rc<T, A>) -> bool;
Expand Down
13 changes: 13 additions & 0 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3654,6 +3654,19 @@ impl<T> Default for Arc<[T]> {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "pin_default_impls", since = "CURRENT_RUSTC_VERSION")]
impl<T> Default for Pin<Arc<T>>
where
T: ?Sized,
Arc<T>: Default,
{
#[inline]
fn default() -> Self {
unsafe { Pin::new_unchecked(Arc::<T>::default()) }
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + Hash, A: Allocator> Hash for Arc<T, A> {
fn hash<H: Hasher>(&self, state: &mut H) {
Expand Down
74 changes: 62 additions & 12 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,27 @@
//! v[1] = v[1] + 5;
//! ```
//!
//! # Memory layout
//!
//! When the type is non-zero-sized and the capacity is nonzero, [`Vec`] uses the [`Global`]
//! allocator for its allocation. It is valid to convert both ways between such a [`Vec`] and a raw
//! pointer allocated with the [`Global`] allocator, provided that the [`Layout`] used with the
//! allocator is correct for a sequence of `capacity` elements of the type, and the first `len`
//! values pointed to by the raw pointer are valid. More precisely, a `ptr: *mut T` that has been
//! allocated with the [`Global`] allocator with [`Layout::array::<T>(capacity)`][Layout::array] may
//! be converted into a vec using
//! [`Vec::<T>::from_raw_parts(ptr, len, capacity)`](Vec::from_raw_parts). Conversely, the memory
//! backing a `value: *mut T` obtained from [`Vec::<T>::as_mut_ptr`] may be deallocated using the
//! [`Global`] allocator with the same layout.
//!
//! For zero-sized types (ZSTs), or when the capacity is zero, the `Vec` pointer must be non-null
//! and sufficiently aligned. The recommended way to build a `Vec` of ZSTs if [`vec!`] cannot be
//! used is to use [`ptr::NonNull::dangling`].
//!
//! [`push`]: Vec::push
//! [`ptr::NonNull::dangling`]: NonNull::dangling
//! [`Layout`]: crate::alloc::Layout
//! [Layout::array]: crate::alloc::Layout::array

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down Expand Up @@ -523,18 +543,23 @@ impl<T> Vec<T> {
/// This is highly unsafe, due to the number of invariants that aren't
/// checked:
///
/// * `ptr` must have been allocated using the global allocator, such as via
/// the [`alloc::alloc`] function.
/// * `T` needs to have the same alignment as what `ptr` was allocated with.
/// * If `T` is not a zero-sized type and the capacity is nonzero, `ptr` must have
/// been allocated using the global allocator, such as via the [`alloc::alloc`]
/// function. If `T` is a zero-sized type or the capacity is zero, `ptr` need
/// only be non-null and aligned.
/// * `T` needs to have the same alignment as what `ptr` was allocated with,
/// if the pointer is required to be allocated.
/// (`T` having a less strict alignment is not sufficient, the alignment really
/// needs to be equal to satisfy the [`dealloc`] requirement that memory must be
/// allocated and deallocated with the same layout.)
/// * The size of `T` times the `capacity` (ie. the allocated size in bytes) needs
/// to be the same size as the pointer was allocated with. (Because similar to
/// alignment, [`dealloc`] must be called with the same layout `size`.)
/// * The size of `T` times the `capacity` (ie. the allocated size in bytes), if
/// nonzero, needs to be the same size as the pointer was allocated with.
/// (Because similar to alignment, [`dealloc`] must be called with the same
/// layout `size`.)
/// * `length` needs to be less than or equal to `capacity`.
/// * The first `length` values must be properly initialized values of type `T`.
/// * `capacity` needs to be the capacity that the pointer was allocated with.
/// * `capacity` needs to be the capacity that the pointer was allocated with,
/// if the pointer is required to be allocated.
/// * The allocated size in bytes must be no larger than `isize::MAX`.
/// See the safety documentation of [`pointer::offset`].
///
Expand Down Expand Up @@ -770,12 +795,16 @@ impl<T> Vec<T> {
/// order as the arguments to [`from_raw_parts`].
///
/// After calling this function, the caller is responsible for the
/// memory previously managed by the `Vec`. The only way to do
/// this is to convert the raw pointer, length, and capacity back
/// into a `Vec` with the [`from_raw_parts`] function, allowing
/// the destructor to perform the cleanup.
/// memory previously managed by the `Vec`. Most often, one does
/// this by converting the raw pointer, length, and capacity back
/// into a `Vec` with the [`from_raw_parts`] function; more generally,
/// if `T` is non-zero-sized and the capacity is nonzero, one may use
/// any method that calls [`dealloc`] with a layout of
/// `Layout::array::<T>(capacity)`; if `T` is zero-sized or the
/// capacity is zero, nothing needs to be done.
///
/// [`from_raw_parts`]: Vec::from_raw_parts
/// [`dealloc`]: crate::alloc::GlobalAlloc::dealloc
///
/// # Examples
///
Expand Down Expand Up @@ -1755,6 +1784,12 @@ impl<T, A: Allocator> Vec<T, A> {
/// may still invalidate this pointer.
/// See the second example below for how this guarantee can be used.
///
/// The method also guarantees that, as long as `T` is not zero-sized and the capacity is
/// nonzero, the pointer may be passed into [`dealloc`] with a layout of
/// `Layout::array::<T>(capacity)` in order to deallocate the backing memory. If this is done,
/// be careful not to run the destructor of the `Vec`, as dropping it will result in
/// double-frees. Wrapping the `Vec` in a [`ManuallyDrop`] is the typical way to achieve this.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -1787,9 +1822,24 @@ impl<T, A: Allocator> Vec<T, A> {
/// }
/// ```
///
/// Deallocating a vector using [`Box`] (which uses [`dealloc`] internally):
///
/// ```
/// use std::mem::{ManuallyDrop, MaybeUninit};
///
/// let mut v = ManuallyDrop::new(vec![0, 1, 2]);
/// let ptr = v.as_mut_ptr();
/// let capacity = v.capacity();
/// let slice_ptr: *mut [MaybeUninit<i32>] =
/// std::ptr::slice_from_raw_parts_mut(ptr.cast(), capacity);
/// drop(unsafe { Box::from_raw(slice_ptr) });
/// ```
///
/// [`as_mut_ptr`]: Vec::as_mut_ptr
/// [`as_ptr`]: Vec::as_ptr
/// [`as_non_null`]: Vec::as_non_null
/// [`dealloc`]: crate::alloc::GlobalAlloc::dealloc
/// [`ManuallyDrop`]: core::mem::ManuallyDrop
#[stable(feature = "vec_as_ptr", since = "1.37.0")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")]
#[rustc_never_returns_null_ptr]
Expand Down Expand Up @@ -3126,7 +3176,7 @@ impl<T, A: Allocator> Vec<T, A> {
// - but the allocation extends out to `self.buf.capacity()` elements, possibly
// uninitialized
let spare_ptr = unsafe { ptr.add(self.len) };
let spare_ptr = spare_ptr.cast::<MaybeUninit<T>>();
let spare_ptr = spare_ptr.cast_uninit();
let spare_len = self.buf.capacity() - self.len;

// SAFETY:
Expand Down
Loading
Loading