dtolnay / dtolnay/cxx

Duplicate const generated on cxx::bridge file in C++

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

Description

Thanks for your work on this useful library! Right now I'm using `cxx::bridge` to provide Elixir bindings for PyTorch via Rustler (https://github.com/andfoy/extorch). I'm trying to use a `rust::Slice` with `std::shared_ptr`, where `CrossTensor` is a C++ opaque type as follows:

```rust
/// Index a tensor using a list of tensors.
fn index(
tensor: &SharedPtr,
indices: &[&SharedPtr]
) -> Result>;
```

Where index has the following signature:

```c++
std::shared_ptr index(
const std::shared_ptr &tensor,
rust::Slice&> indices);
```

When I try to compile the library, it seems that the code generator is producing a bridge signature with duplicate `const` keywords, which causes compilation errors:

```c++
::rust::repr::PtrLen cxxbridge1$index(const ::std::shared_ptr<::CrossTensor> &tensor, ::rust::Slice &> indices, ::std::shared_ptr<::CrossTensor> *return$) noexcept
```

I don't know if the `&[&SharedPtr]` declaration is malformed or if I should not use a slice in this case. I would appreciate any help with this issue.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the cxx::bridge code-generation path that emits the C++ signature, using the Rust declaration and generated signature shown here as the reproduction. Done means the generated declaration contains one const for the slice element type and compiles without the duplicate-const error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
devtools
Issue type
Bug
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.