Touch up PR 984

This commit is contained in:
David Tolnay 2021-12-31 13:30:05 -08:00
parent fa7380675e
commit 47465d2bf1
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
4 changed files with 6 additions and 6 deletions

View File

@ -26,7 +26,7 @@ public:
// Replaces invalid UTF-8 data with the replacement character (U+FFFD).
static String lossy(const std::string &) noexcept;
static String lossy(const char *) noexcept;
static String lossy(const char *, std::size_t) noexcept;
static String lossy(const char *, size_t) noexcept;
// Throws std::invalid_argument if not UTF-16.
String(const char16_t *);
@ -34,7 +34,7 @@ public:
// Replaces invalid UTF-16 data with the replacement character (U+FFFD).
static String lossy(const char16_t *) noexcept;
static String lossy(const char16_t *, std::size_t) noexcept;
static String lossy(const char16_t *, size_t) noexcept;
String &operator=(const String &) noexcept;
String &operator=(String &&) noexcept;

View File

@ -24,7 +24,6 @@ namespace rust {
inline namespace cxxbridge1 {
struct unsafe_bitcopy_t;
struct lossy_t;
namespace {
template <typename T>
@ -93,6 +92,7 @@ public:
String(unsafe_bitcopy_t, const String &) noexcept;
private:
struct lossy_t;
String(lossy_t, const char *, std::size_t) noexcept;
String(lossy_t, const char16_t *, std::size_t) noexcept;
friend void swap(String &lhs, String &rhs) noexcept { lhs.swap(rhs); }

View File

@ -73,8 +73,6 @@ std::size_t cxxbridge1$slice$len(const void *self) noexcept;
namespace rust {
inline namespace cxxbridge1 {
struct lossy_t {};
template <typename Exception>
void panic [[noreturn]] (const char *msg) {
#if defined(RUST_CXX_NO_EXCEPTIONS)
@ -138,6 +136,8 @@ String::String(const char16_t *s, std::size_t len) {
len);
}
struct String::lossy_t {};
String::String(lossy_t, const char *s, std::size_t len) noexcept {
cxxbridge1$string$from_utf8_lossy(
this, s == nullptr && len == 0 ? reinterpret_cast<const char *>(1) : s,

View File

@ -51,7 +51,7 @@ fn test_c_return() {
cast::c_char_to_unsigned(ffi::c_return_slice_char(&shared)),
);
assert_eq!("2020", ffi::c_return_rust_string());
assert_eq!("Hello <EFBFBD>World", ffi::c_return_rust_string_lossy());
assert_eq!("Hello \u{fffd}World", ffi::c_return_rust_string_lossy());
assert_eq!("2020", ffi::c_return_unique_ptr_string().to_str().unwrap());
assert_eq!(4, ffi::c_return_unique_ptr_vector_u8().len());
assert_eq!(