Skip to content

Allow users to annotate functions without body with contracts #3325

@celinval

Description

@celinval

Requested feature: Allow users to annotate external "C" functions and intrinsics with contracts.
Use case: Adding safety contracts to std intrinsics and extern "C" functions.
Link to relevant documentation (Rust reference, Nomicon, RFC):

Test case:

    /// The size of the referenced value in bytes.
    ///
    /// The stabilized version of this intrinsic is [`crate::mem::size_of_val`].
    #[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
    #[rustc_nounwind]
    #[requires(matches!(
        <T as Pointee>::Metadata::map_dyn(crate::ptr::metadata(_val)::metadata(), |dyn_meta| {
    ub_checks::can_dereference(dyn_meta)}), None | Some(true)))]
    pub fn size_of_val<T: ?Sized>(_val: *const T) -> usize;

Fails with the following compilation error:

error: expected curly braces
    --> /verify-std/library/core/src/intrinsics.rs:1070:59
     |
1070 |     pub fn size_of_val<T: ?Sized>(_val: *const T) -> usize;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Z-ContractsIssue related to code contracts[C] Feature / EnhancementA new feature request or enhancement to an existing feature.[E] User ExperienceAn UX enhancement for an existing feature. Including deprecation of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions