These are broken because multiple SharedPtrs can point to the same data,
and getting a &mut from each of them would result in multiple &mut to
overlapping data.
Clang-tidy emits this warning:
src/cxx.cc:338:3: warning: use '= default' to define a trivial default constructor [modernize-use-equals-default]
MaybeUninit() {}
^ ~~
= default;
src/cxx.cc:339:3: warning: use '= default' to define a trivial destructor [modernize-use-equals-default]
~MaybeUninit() {}
^ ~~
= default;
but following the suggestion makes the code not compile (the default
implementation of the default constructor "is implicitly deleted because
the default definition would be ill-formed").
src/cxx.cc: In function ‘std::string* cxxbridge1$std$shared_ptr$string$uninit(std::shared_ptr<std::__cxx11::basic_string<char> >*)’:
src/cxx.cc:465:48: error: use of deleted function ‘rust::cxxbridge1::{anonymous}::MaybeUninit<T>::MaybeUninit() [with T = std::__cxx11::basic_string<char>]’
465 | reinterpret_cast<CXX_TYPE *>(new rust::MaybeUninit<CXX_TYPE>); \
| ^~~~~~~~~~~~~~~~~~~~~
src/cxx.cc:512:3: note: in expansion of macro ‘SHARED_PTR_OPS’
512 | MACRO(string, std::string)
| ^~~~~
src/cxx.cc:517:1: note: in expansion of macro ‘FOR_EACH_SHARED_PTR’
517 | FOR_EACH_SHARED_PTR(SHARED_PTR_OPS)
| ^~~~~~~~~~~~~~~~~~~
src/cxx.cc:338:3: note: ‘rust::cxxbridge1::{anonymous}::MaybeUninit<T>::MaybeUninit() [with T = std::__cxx11::basic_string<char>]’ is implicitly deleted because the default definition would be ill-formed:
338 | MaybeUninit() = default;
| ^~~~~~~~~~~
src/cxx.cc:337:5: error: union member ‘rust::cxxbridge1::{anonymous}::MaybeUninit<std::__cxx11::basic_string<char> >::value’ with non-trivial ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
337 | T value;
| ^~~~~
This generates multiple Rust-side and C++-side error messages
when a given opaque C++ type is being used in contexts which
allow only a Trivial type. Previously, we showed just the first
message and discarded all others.
Previously we allowed extern types to be used as un-pinned
reference parameters only if there happened to be some other
use of the type in some way which required it to be Trivial.
With this change,
* Opaque extern types must always be pinned when used as mutable
reference parameters;
* Trivial extern types need never be pinned when used as mutable
reference parameters.