dtolnay / dtolnay/cxx

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

Open
#930 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
6.8k
Forks
424
Avg merge
1h 19m
Merged PRs (30d)
6

Description

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

```rust
#[cxx::bridge]
mod ffi {
#[must_use]
struct S {...}

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

#[must_use]
fn f() -> i32;
}
}
```

```cpp
// generated c++

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

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

[[nodiscard]] int32_t f() noexcept;
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the #[cxx::bridge] examples and the linked Rust and C++ attribute references. Trace how bridge attributes on structs, extern Rust types, and functions are handled when generated C++ is emitted. Done means the shown #[must_use] forms produce the corresponding C++17 [[nodiscard]] declarations.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.