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

Feature request: support attributes in rust! pseudo-macro #94

Open
ratijas opened this issue Jul 1, 2021 · 0 comments
Open

Feature request: support attributes in rust! pseudo-macro #94

ratijas opened this issue Jul 1, 2021 · 0 comments

Comments

@ratijas
Copy link
Contributor

ratijas commented Jul 1, 2021

Summary

As a user of cpp!() library, for whatever reason, I may want to write this:

cpp!(unsafe [n as "int"] {
    rust!(#[allow(unused)] Rust_myCallback [n : i32 as "int"] {
        // do something with or without `n`
    })
})

Description

Currently, cpp!() macro generates code with two C++ functions: extern "C" wrapper, and actual native C++ function with your code verbatim. It is done so that user's code control flow would not interfere with wrapping glue, e.g. explicit early return statements.

On contrary, rust! pseudo-macro's is to wrap user's code verbatim in a closure. It is purely an implementation details, but if we change it to a function and make that fact public and engraved in stone, then we'd be able to support new syntax with function attributes.

Why?

I wanted to silence clippy's needless_return warning in #93, but I just couldn't narrow it down to just single invocation, since expression/item attributes are not stable yet (and probably would never be). So, using #![allow(...)] attribute inside the block would give me compile error. Using outer #[allow(...)] block in C++ code is obviously not an option. And adding it to the whole top-level cpp!{{ ... }} macro silently did nothing good.

I just showed my particular example. There might be more use cases for attributes. It just feels like an artificial limitation that gets in the way.

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

No branches or pull requests

1 participant