Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/rust
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f02baf1bd2fc55c1cade587775c3202b44b158ab
Choose a base ref
..
head repository: rust-lang/rust
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 91b7f27707563e25c3ac8470f70a12ff55813a97
Choose a head ref
Showing with 3 additions and 2 deletions.
  1. +3 −2 library/core/src/char/methods.rs
5 changes: 3 additions & 2 deletions library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
@@ -1765,10 +1765,10 @@ const fn len_utf8(code: u32) -> usize {
pub const fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] {
const fn panic_at_const(_code: u32, _len: usize, _dst_len: usize) {
// Note that we cannot format in constant expressions.
panic!("encode_utf8: buffer does not have enough bytes to encode code point")
panic!("encode_utf8: buffer does not have enough bytes to encode code point");
}
fn panic_at_rt(code: u32, len: usize, dst_len: usize) {
panic!("encode_utf8: need {len} bytes to encode U+{code:04X} but buffer has just {dst_len}")
panic!("encode_utf8: need {len} bytes to encode U+{code:04X} but buffer has just {dst_len}");
}
let len = len_utf8(code);
match (len, &mut *dst) {
@@ -1790,6 +1790,7 @@ pub const fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] {
*c = (code >> 6 & 0x3F) as u8 | TAG_CONT;
*d = (code & 0x3F) as u8 | TAG_CONT;
}
// FIXME(const-hack) We would prefer to have streamlined panics when formatters become const-friendly.
_ => const_eval_select((code, len, dst.len()), panic_at_const, panic_at_rt),
};
// SAFETY: `<&mut [u8]>::as_mut_ptr` is guaranteed to return a valid pointer and `len` has been tested to be within bounds.