From 47465d2bf16a95713a331a7a55364ab258350505 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 31 Dec 2021 13:30:05 -0800 Subject: [PATCH] Touch up PR 984 --- book/src/binding/string.md | 4 ++-- include/cxx.h | 2 +- src/cxx.cc | 4 ++-- tests/test.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/book/src/binding/string.md b/book/src/binding/string.md index ad5e9caa..1e482781 100644 --- a/book/src/binding/string.md +++ b/book/src/binding/string.md @@ -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; diff --git a/include/cxx.h b/include/cxx.h index 56434711..907ee829 100644 --- a/include/cxx.h +++ b/include/cxx.h @@ -24,7 +24,6 @@ namespace rust { inline namespace cxxbridge1 { struct unsafe_bitcopy_t; -struct lossy_t; namespace { template @@ -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); } diff --git a/src/cxx.cc b/src/cxx.cc index 555aa681..593f28e6 100644 --- a/src/cxx.cc +++ b/src/cxx.cc @@ -73,8 +73,6 @@ std::size_t cxxbridge1$slice$len(const void *self) noexcept; namespace rust { inline namespace cxxbridge1 { -struct lossy_t {}; - template 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(1) : s, diff --git a/tests/test.rs b/tests/test.rs index 0f015411..13ce3456 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -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 �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!(