Skip to content

Commit

Permalink
Merge from rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
The Miri Cronjob Bot committed Jun 28, 2024
2 parents cf231e8 + 6c38c60 commit 652f0b8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
18 changes: 4 additions & 14 deletions alloc/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@
#[allow_internal_unstable(rustc_attrs, liballoc_internals)]
macro_rules! vec {
() => (
$crate::__rust_force_expr!($crate::vec::Vec::new())
$crate::vec::Vec::new()
);
($elem:expr; $n:expr) => (
$crate::__rust_force_expr!($crate::vec::from_elem($elem, $n))
$crate::vec::from_elem($elem, $n)
);
($($x:expr),+ $(,)?) => (
$crate::__rust_force_expr!(<[_]>::into_vec(
<[_]>::into_vec(
// This rustc_box is not required, but it produces a dramatic improvement in compile
// time when constructing arrays with many elements.
#[rustc_box]
$crate::boxed::Box::new([$($x),+])
))
)
);
}

Expand Down Expand Up @@ -126,13 +126,3 @@ macro_rules! format {
res
}}
}

/// Force AST node to an expression to improve diagnostics in pattern position.
#[doc(hidden)]
#[macro_export]
#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
macro_rules! __rust_force_expr {
($e:expr) => {
$e
};
}
2 changes: 1 addition & 1 deletion std/src/sys_common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl Wtf8Buf {
#[inline]
pub(crate) fn extend_from_slice(&mut self, other: &[u8]) {
self.bytes.extend_from_slice(other);
self.is_known_utf8 = self.is_known_utf8 || self.next_surrogate(0).is_none();
self.is_known_utf8 = false;
}
}

Expand Down
24 changes: 24 additions & 0 deletions std/src/sys_common/wtf8/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,3 +725,27 @@ fn wtf8_utf8_boundary_between_surrogates() {
string.push(CodePoint::from_u32(0xD800).unwrap());
check_utf8_boundary(&string, 3);
}

#[test]
fn wobbled_wtf8_plus_bytes_isnt_utf8() {
let mut string: Wtf8Buf = unsafe { Wtf8::from_bytes_unchecked(b"\xED\xA0\x80").to_owned() };
assert!(!string.is_known_utf8);
string.extend_from_slice(b"some utf-8");
assert!(!string.is_known_utf8);
}

#[test]
fn wobbled_wtf8_plus_str_isnt_utf8() {
let mut string: Wtf8Buf = unsafe { Wtf8::from_bytes_unchecked(b"\xED\xA0\x80").to_owned() };
assert!(!string.is_known_utf8);
string.push_str("some utf-8");
assert!(!string.is_known_utf8);
}

#[test]
fn unwobbly_wtf8_plus_utf8_is_utf8() {
let mut string: Wtf8Buf = Wtf8Buf::from_str("hello world");
assert!(string.is_known_utf8);
string.push_str("some utf-8");
assert!(string.is_known_utf8);
}

0 comments on commit 652f0b8

Please sign in to comment.