Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

anforowicz
Copy link
Contributor

Motivation for this PR

The work toward supporting arbitrary T in generics would be easier if we didn't special-case specific Ts. (I have a local chain of commits that builds on top of this PR, and ends up supporting Vec<Box<T>>.)

Safety/correctness of this PR

IIUC ::cxx::private::RustVec<T>:

  • Has the same ABI regardless of T: a few usizes:
    repr: [MaybeUninit<usize>; mem::size_of::<Vec<c_void>>() / mem::size_of::<usize>()],
  • Doesn't leak T somewhere else in the FFI ABI (e.g. there are no extern/FFI APIs defined in rust_vec.rs)

Therefore I don't understand why:

  • macro/src/expand.rs replaces RustVec<String> with RustVec<RustString> (either "manually", or by calling expand_extern_type)
  • src/rust_vec.rs needs to provide (via impl RustVec<RustString>) support for transmuting between values/references/etc of Vec<String> and RustVec<RustString>

So, assuming my understanding above is correct, this PR stops special casing Vec<String>.

FWIW RustVec<RustString> seems to come all the way from the original commit that added support for Vec<String>: 33f56ad. And before this commit Vec<String> was being rejected in syntax/check.rs. So maybe I am missing something here?

Optional: unrelated tests/ui failures in my local testing

One more (optional) question: any idea why I see some unexpected differences in rustc output for tests/ui in my local testing via cargo test? For example, when I try with a recent nightly version (rustc 1.91.0-nightly (7ad23f43a 2025-09-09)) at a recent cxx revision (c7cb3bf), then TRYBUILD=overwrite cargo test generates the commit at anforowicz@09a5217 (which AFAICT only inserts a bit of whitespace in some testcases to indent error messages from rustc), but GitHub CI then fails with https://github.com/anforowicz/cxx/actions/runs/17624407527/job/50077573425. FWIW I tried, but ultimately failed to check which rustc version is used by GitHub CI...

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay dtolnay merged commit d32086a into dtolnay:master Sep 12, 2025
30 checks passed
@dtolnay
Copy link
Owner

dtolnay commented Sep 12, 2025

any idea why I see some unexpected differences in rustc output for tests/ui in my local testing via cargo test?

That would be from testing with an outdated version of trybuild. You can tell what version is being used by CI in the log.

I tried, but ultimately failed to check which rustc version is used by GitHub CI…

The specific nightly date shows up in the log:

@anforowicz anforowicz deleted the avoid-special-casing-vec-string branch September 12, 2025 23:43
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

Successfully merging this pull request may close these issues.

2 participants