cxx icon indicating copy to clipboard operation
cxx copied to clipboard

Translate #[must_use] attribute to C++17 [[nodiscard]]

Open dtolnay opened this issue 4 years ago • 0 comments

References:

  • https://doc.rust-lang.org/1.54.0/reference/attributes/diagnostics.html#the-must_use-attribute
  • https://en.cppreference.com/w/cpp/language/attributes/nodiscard
#[cxx::bridge]
mod ffi {
    #[must_use]
    struct S {...}

    extern "Rust" {
        #[must_use = "..."]
        type T;

        #[must_use]
        fn f() -> i32;
    }
}
// generated c++

struct [[nodiscard]] S final {...};

struct [[nodiscard("...")]] T final : rust::Opaque {...};

[[nodiscard]] int32_t f() noexcept;

dtolnay avatar Sep 05 '21 07:09 dtolnay