Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 1 addition & 37 deletions docs/errors/nested_type.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,7 @@ mod outer_type {
}
```

This will fail if the `mod outer_type` name is not unique, and due to
b/481667188: if the `Inner` type is a forward declaration, which is completed
outside of the `OuterType` type. If that happens, `Inner` will not receive
bindings.

## Fix

### Type Alias {#alias}

The most general fix, which will ensure `Inner` gets bindings if it can, is to
move it outside of `OuterType`:

```c++
struct Inner {};
struct OuterType {
using Inner = Inner;
};
```

Even if the bindings for the `using Inner = Inner;` fail for any of the above
reasons, the top-level `struct Inner` will still receive bindings, if it can.
This will fail if the `mod outer_type` name is not unique.

### Disambiguate the names {#disambiguate}

Expand All @@ -59,19 +39,3 @@ struct OuterImpl {

using OuterType = OuterImpl;
```

### b/481667188: Complete the type

TODO(b/481667188): Completing the type inside the class should not be necessary.

For now, avoid this pattern if `Inner` is meant to be used from Rust:

```c++
struct OuterType {
struct Inner;
};
struct OuterType::Inner {...};
```

Defining the complete type inside of `OuterType` will work, as will the general
[type alias solution](#alias) above.
1 change: 0 additions & 1 deletion rs_bindings_from_cc/test/golden/nested_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ struct Bar {};

} // namespace no_longer_top_level

// TODO(b/481667188): Nested should get bindings.
struct ContainsForwardDeclared {
struct Nested;
};
Expand Down
1 change: 0 additions & 1 deletion rs_bindings_from_cc/test/golden/nested_types_rs_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,6 @@ pub mod no_longer_top_level {

// namespace no_longer_top_level

/// TODO(b/481667188): Nested should get bindings.
#[derive(Clone, Copy, ::ctor::MoveAndAssignViaCopy)]
#[repr(C)]
///CRUBIT_ANNOTATE: cpp_type=ContainsForwardDeclared
Expand Down
Loading