Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't return Result<Box<T>> #309

Closed
exlavasage opened this issue Sep 21, 2020 · 1 comment · Fixed by #311
Closed

Can't return Result<Box<T>> #309

exlavasage opened this issue Sep 21, 2020 · 1 comment · Fixed by #311
Labels

Comments

@exlavasage
Copy link

exlavasage commented Sep 21, 2020

I am trying to return a Result<Box< T >> and I am getting the below compile errors.

expected struct std::boxed::Box, found enum std::result::Result
expected enum std::result::Result, found *-ptr

I have tried setting the return type to Result and Box and both compile fine.

Here is a simple proof.

#[cxx::bridge()]
mod test {
    struct Test {
        size: usize,
    }

    extern "Rust" {
        fn test() -> Result<Box<Test>>;
    }   
}       
        
fn test() -> Result<Box<test::Test>> {
    Ok(Box::<test::Test>::new(test::Test{size: 0}))
}

The reason I want to return a Result<Box> is because in my use case T is a rust opaque type, but I made T a shared type to check that both Result and Box compile fine where Result<Box> doesn't.

@exlavasage exlavasage changed the title Can't return Result of Box Can't return Result<Box<T>> Sep 21, 2020
@dtolnay dtolnay added the bug label Sep 21, 2020
@dtolnay
Copy link
Owner

dtolnay commented Sep 21, 2020

Thanks for the report! Fixed in 0.4.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants