Skip to content

Ignore FFI-unsafe warning to support stable? #34

Description

@heaths

As the try_trait_v2 lingers on, perhaps we can just ignore the lint with something like:

use std::fmt;

const ERROR_INSTALL_FAILURE: Error =
    Error(unsafe { std::num::NonZero::<u32>::new_unchecked(1603) });

#[derive(Debug)]
#[repr(transparent)]
pub struct Error(std::num::NonZero<u32>);
impl std::error::Error for Error {}
impl fmt::Display for Error {
    fn fmt(&self, f: &'_ mut fmt::Formatter) -> fmt::Result {
        f.write_str(&self.0.to_string())
    }
}

pub type Result<T> = std::result::Result<T, Error>;

#[allow(improper_ctypes_definitions)]
#[no_mangle]
pub extern "C" fn print_size() -> Result<()> {
    println!("{}", std::mem::size_of::<Result<()>>());
    Err(ERROR_INSTALL_FAILURE)
}

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
    Ok(print_size()?)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions