about summary refs log tree commit diff
AgeCommit message (Collapse)AuthorLines
2024-10-15Rollup merge of #131328 - ↵Matthias Krüger-7/+2
ismailarilik:remove-unnecessary-sorts-in-rustc-hir-analysis, r=compiler-errors Remove unnecessary sorts in `rustc_hir_analysis` A follow-up after #131140. Here the related objects are `IndexSet` so do not require a sort to stay stable. And they don't need to be `mut` anymore. r? ```@compiler-errors```
2024-10-15Rollup merge of #131137 - Mark-Simulacrum:relnotes, r=cuviperMatthias Krüger-0/+177
Add 1.82 release notes cc ````@rust-lang/release```` This is using the new release notes infrastructure. My expectation is that most and/or all edits should be made separately from this PR by updating various relnote tracking issues, and then we'll re-run the relnotes tool. That probably comes with an exception for the stabilized APIs for std, which will need to be manually added at the end.
2024-10-15Rollup merge of #130747 - folkertdev:c-cmse-nonsecure-entry-error-messages, ↵Matthias Krüger-108/+612
r=compiler-errors improve error messages for `C-cmse-nonsecure-entry` functions fixes https://github.com/rust-lang/rust/issues/81347 tracking issue: https://github.com/rust-lang/rust/issues/75835 brings error messages and testing for `C-cmse-nonsecure-entry` in line with `C-cmse-nonsecure-call`. r? `@compiler-errors`
2024-10-15Rollup merge of #130635 - eholk:pin-reborrow-sugar, r=compiler-errorsMatthias Krüger-39/+286
Add `&pin (mut|const) T` type position sugar This adds parser support for `&pin mut T` and `&pin const T` references. These are desugared to `Pin<&mut T>` and `Pin<&T>` in the AST lowering phases. This PR currently includes #130526 since that one is in the commit queue. Only the most recent commits (bd450027eb4a94b814a7dd9c0fa29102e6361149 and following) are new. Tracking: - #130494 r? `@compiler-errors`
2024-10-15Rollup merge of #130608 - YohDeadfall:cstr-from-into-str, r=workingjubileeMatthias Krüger-1/+25
Implemented `FromStr` for `CString` and `TryFrom<CString>` for `String` The motivation of this change is making it possible to use `CString` in generic methods with `FromStr` and `TryInto<String>` trait bounds. The same traits are already implemented for `OsString` which is an FFI type too.
2024-10-14improve error messages for `C-cmse-nonsecure-entry` functionsFolkert de Vries-108/+612
2024-10-14Auto merge of #131690 - matthiaskrgr:rollup-mcau4ol, r=matthiaskrgrbors-200/+977
Rollup of 8 pull requests Successful merges: - #129424 (Stabilize `Pin::as_deref_mut()`) - #131332 (Fix clobber_abi and disallow SVE-related registers in Arm64EC inline assembly) - #131384 (Update precondition tests (especially for zero-size access to null)) - #131430 (Special treatment empty tuple when suggest adding a string literal in format macro.) - #131550 (Make some tweaks to extern block diagnostics) - #131667 (Fix AArch64InlineAsmReg::emit) - #131679 (compiletest: Document various parts of compiletest's `lib.rs`) - #131682 (Tag PRs affecting compiletest with `A-compiletest`) Failed merges: - #131496 (Stabilise `const_make_ascii`.) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-14Rollup merge of #131682 - jieyouxu:compiletest-label, r=ZalatharMatthias Krüger-0/+5
Tag PRs affecting compiletest with `A-compiletest`
2024-10-14Rollup merge of #131679 - Zalathar:ct-docs, r=jieyouxuMatthias Krüger-13/+114
compiletest: Document various parts of compiletest's `lib.rs` This adds some much-needed comments to many of the items in compiletest's `lib.rs`, giving a better overview of how a compiletest invocation actually proceeds. To make review easier I have refrained from renames or functional changes, though I couldn't resist getting rid of one obviously-redundant `Arc::clone` in `make_test_closure`.
2024-10-14Rollup merge of #131667 - taiki-e:aarch64-inline-asm-reg-emit, r=AmanieuMatthias Krüger-49/+62
Fix AArch64InlineAsmReg::emit Currently, this method uses `self as u32 - Self::x0 as u32` to get register index: https://github.com/rust-lang/rust/blob/36780360b62320a61e2234b17ec600e8e4785509/compiler/rustc_target/src/asm/aarch64.rs#L204 However, this is incorrect for reasons explained in the following comment: https://github.com/rust-lang/rust/blob/36780360b62320a61e2234b17ec600e8e4785509/compiler/rustc_codegen_llvm/src/asm.rs#L544-L549 r? ``@Amanieu`` ``@rustbot`` label O-AArch64 +A-inline-assembly
2024-10-14Rollup merge of #131550 - compiler-errors:extern-diags, r=spastorinoMatthias Krüger-58/+62
Make some tweaks to extern block diagnostics Self-explanatory. See the diagnostic changes; I hope they make them a bit more descriptive. r? spastorino
2024-10-14Rollup merge of #131430 - surechen:fix_130495, r=jieyouxuMatthias Krüger-4/+90
Special treatment empty tuple when suggest adding a string literal in format macro. For example: ```rust let s = "123"; println!({}, "sss", s); ``` Suggest: `println!("{:?} {} {}", {}, "sss", s);` fixes #130170
2024-10-14Rollup merge of #131384 - saethlin:precondition-tests, r=ibraheemdevMatthias Krüger-55/+500
Update precondition tests (especially for zero-size access to null) I don't much like the current way I've updated the precondition check helpers, but I couldn't come up with anything better. Ideas welcome. I've organized `tests/ui/precondition-checks` mostly with one file per function that has `assert_unsafe_precondition` in it, with revisions that check each precondition. The important new test is `tests/ui/precondition-checks/zero-size-null.rs`.
2024-10-14Rollup merge of #131332 - taiki-e:arm64ec-clobber-abi, r=AmanieuMatthias Krüger-20/+143
Fix clobber_abi and disallow SVE-related registers in Arm64EC inline assembly Currently `clobber_abi` in Arm64EC inline assembly is implemented using `InlineAsmClobberAbi::AArch64NoX18`, but broken since it attempts to clobber registers that cannot be used in Arm64EC: https://godbolt.org/z/r3PTrGz5r ``` error: cannot use register `x13`: x13, x14, x23, x24, x28, v16-v31 cannot be used for Arm64EC --> <source>:6:14 | 6 | asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags)); | ^^^^^^^^^^^^^^^^ error: cannot use register `x14`: x13, x14, x23, x24, x28, v16-v31 cannot be used for Arm64EC --> <source>:6:14 | 6 | asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags)); | ^^^^^^^^^^^^^^^^ <omitted the same errors for v16-v31> ``` Additionally, this disallows SVE-related registers per https://github.com/rust-lang/rust/pull/131332#issuecomment-2401189142. cc ``@dpaoliello`` r? ``@Amanieu`` ``@rustbot`` label O-windows O-AArch64 +A-inline-assembly
2024-10-14Rollup merge of #129424 - coolreader18:stabilize-pin_as_deref_mut, r=dtolnayMatthias Krüger-1/+1
Stabilize `Pin::as_deref_mut()` Tracking issue: closes #86918 Stabilizing the following API: ```rust impl<Ptr: DerefMut> Pin<Ptr> { pub fn as_deref_mut(self: Pin<&mut Pin<Ptr>>) -> Pin<&mut Ptr::Target>; } ``` I know that an FCP has not been started yet, but this isn't a very complex stabilization, and I'm hoping this can motivate an FCP to *get* started - this has been pending for a while and it's a very useful function when writing Future impls. r? ``@jonhoo``
2024-10-14Auto merge of #131672 - matthiaskrgr:rollup-gyzysj4, r=matthiaskrgrbors-338/+469
Rollup of 8 pull requests Successful merges: - #128967 (std::fs::get_path freebsd update.) - #130629 (core/net: add Ipv[46]Addr::from_octets, Ipv6Addr::from_segments.) - #131274 (library: Const-stabilize `MaybeUninit::assume_init_mut`) - #131473 (compiler: `{TyAnd,}Layout` comes home) - #131533 (emscripten: Use the latest emsdk 3.1.68) - #131593 (miri: avoid cloning AllocExtra) - #131616 (merge const_ipv4 / const_ipv6 feature gate into 'ip' feature gate) - #131660 (Also use outermost const-anon for impl items in `non_local_defs` lint) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-14triagebot: tag PRs affecting compiletest with `A-compiletest`许杰友 Jieyou Xu (Joe)-0/+5
2024-10-14Document various parts of compiletest's `lib.rs`Zalathar-13/+114
2024-10-14Rollup merge of #131660 - Urgau:non_local_def-131643, r=jieyouxuMatthias Krüger-3/+27
Also use outermost const-anon for impl items in `non_local_defs` lint This PR update the logic for the impl paths (items) in the `non_local_definitions` lint to also consider const-anon in case the impl definition is wrapped inside const-anon it-self wrapped into a const-anon where the items are. r? `@jieyouxu` *(since you interacted on the issue)* Fixes *(after beta-backport)* #131643
2024-10-14Rollup merge of #131616 - RalfJung:const_ip, r=tgross35Matthias Krüger-22/+0
merge const_ipv4 / const_ipv6 feature gate into 'ip' feature gate https://github.com/rust-lang/rust/issues/76205 has been closed a while ago, but there are still some functions that reference it. Those functions are all unstable *and* const-unstable. There's no good reason to use a separate feature gate for their const-stability, so this PR moves their const-stability under the same gate as their regular stability, and therefore removes the remaining references to https://github.com/rust-lang/rust/issues/76205.
2024-10-14Rollup merge of #131593 - RalfJung:alloc-no-clone, r=saethlinMatthias Krüger-18/+31
miri: avoid cloning AllocExtra We shouldn't be cloning Miri allocations, so make `AllocExtra::clone` panic instead, and adjust the one case where we *do* clone (the leak check) to avoid cloning. This is in preparation for https://github.com/rust-lang/miri/pull/3966 where I am adding something to `AllocExtra` that cannot (easily) be cloned. r? ``@saethlin``
2024-10-14Rollup merge of #131533 - workingjubilee:update-emscripten-version, r=KobzolMatthias Krüger-2/+2
emscripten: Use the latest emsdk 3.1.68 This should fix our precompiled std being unsound in `std::fs` code. Should resolve #131467 I hope.
2024-10-14Rollup merge of #131473 - workingjubilee:move-that-abi-up, r=saethlinMatthias Krüger-261/+285
compiler: `{TyAnd,}Layout` comes home The `Layout` and `TyAndLayout` types are heavily abstract and have no particular target-specific qualities, though we do use them to answer questions particular to targets. We can keep it that way if we simply move them out of `rustc_target` and into `rustc_abi`. They bring a small entourage of connected types with them, but that's fine. This will allow us to strengthen a few abstraction barriers over time and thus make the notoriously gnarly layout code easier to refactor. For now, we don't need to worry about that and deliberately use reexports to minimize this particular diff.
2024-10-14Rollup merge of #131274 - workingjubilee:stabilize-the-one-that-got-away, ↵Matthias Krüger-3/+7
r=scottmcm library: Const-stabilize `MaybeUninit::assume_init_mut` FCP completed in https://github.com/rust-lang/rust/issues/86722#issuecomment-2393954459 Also moves const-ness of an unstable fn under the `maybe_uninit_slice` gate, Cc https://github.com/rust-lang/rust/issues/63569
2024-10-14Rollup merge of #130629 - Dirbaio:net-from-octets, r=tgross35Matthias Krüger-26/+114
core/net: add Ipv[46]Addr::from_octets, Ipv6Addr::from_segments. Adds: - `Ipv4Address::from_octets([u8;4])` - `Ipv6Address::from_octets([u8;16])` - `Ipv6Address::from_segments([u16;8])` equivalent to the existing `From` impls. Advantages: - Consistent with `to_bits, from_bits`. - More discoverable than the `From` impls. - Helps with type inference: it's common to want to convert byte slices to IP addrs. If you try this ```rust fn foo(x: &[u8]) -> Ipv4Addr { Ipv4Addr::from(foo.try_into().unwrap()) } ``` it [doesn't work](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0e2873312de275a58fa6e33d1b213bec). You have to write `Ipv4Addr::from(<[u8;4]>::try_from(x).unwrap())` instead, which is not great. With `from_octets` it is able to infer the right types. Found this while porting [smoltcp](https://github.com/smoltcp-rs/smoltcp/) from its own IP address types to the `core::net` types. ~~Tracking issues #27709 #76205~~ Tracking issue: https://github.com/rust-lang/rust/issues/131360
2024-10-14Rollup merge of #128967 - devnexen:get_path_fbsd_upd, r=joboetMatthias Krüger-3/+3
std::fs::get_path freebsd update. what matters is we re doing the right things as doing sizeof, rather than passing KINFO_FILE_SIZE (only defined on intel architectures), the kernel making sure it matches the expectation in its side.
2024-10-14Auto merge of #126557 - GrigorenkoPV:vec_track_caller, r=joboetbors-3/+107
Add `#[track_caller]` to allocating methods of `Vec` & `VecDeque` Part 4 in a lengthy saga. r? `@joshtriplett` because they were the reviewer the last 3 times. `@bors` rollup=never "[just in case this has perf effects, Vec is hot](https://github.com/rust-lang/rust/pull/79323#issuecomment-731866746)" This was first attempted in #79323 by `@nvzqz.` It got approval from `@joshtriplett,` but rotted with merge conflicts and got closed. Then it got picked up by `@Dylan-DPC-zz` in #83359. A benchmark was run[^perf], the results (after a bit of thinking[^thinking]) were deemed ok[^ok], but there was a typo[^typo] and the PR was made from a wrong remote in the first place[^remote], so #83909 was opened instead. By the time #83909 rolled around, the methods in question had received some optimizations[^optimizations], so another perf run was conducted[^perf2]. The results were ok[^ok2]. There was a suggestion to add regression tests for panic behavior [^tests], but before it could be addressed, the PR fell victim to merge conflicts[^conflicts] and died again[^rip]. 3 years have passed, and (from what I can tell) this has not been tried again, so here I am now, reviving this old effort. Given how much time has passed and the fact that I've also touched `VecDeque` this time, it probably makes sense to `@bors` try `@rust-timer` [^perf]: https://github.com/rust-lang/rust/pull/83359#issuecomment-804450095 [^thinking]: https://github.com/rust-lang/rust/pull/83359#issuecomment-805286704 [^ok]: https://github.com/rust-lang/rust/pull/83359#issuecomment-812739031 [^typo]: https://github.com/rust-lang/rust/pull/83359#issuecomment-812750205 [^remote]: https://github.com/rust-lang/rust/pull/83359#issuecomment-814067119 [^optimizations]: https://github.com/rust-lang/rust/pull/83909#issuecomment-813736593 [^perf2]: https://github.com/rust-lang/rust/pull/83909#issuecomment-813825552 [^ok2]: https://github.com/rust-lang/rust/pull/83909#issuecomment-813831341 [^tests]: https://github.com/rust-lang/rust/pull/83909#issuecomment-825788964 [^conflicts]: https://github.com/rust-lang/rust/pull/83909#issuecomment-851173480 [^rip]: https://github.com/rust-lang/rust/pull/83909#issuecomment-873569771
2024-10-14Special treatment empty tuple when suggest adding a string literal in format ↵surechen-4/+90
macro. For example: ```rust let s = "123"; println!({}, "sss", s); ``` Suggest: `println!("{:?} {} {}", {}, "sss", s);` fixes #130170
2024-10-13Auto merge of #131662 - matthiaskrgr:rollup-r1wkfxw, r=matthiaskrgrbors-29/+39
Rollup of 8 pull requests Successful merges: - #130356 (don't warn about a missing change-id in CI) - #130900 (Do not output () on empty description) - #131066 (Add the Chinese translation entry to the RustByExample build process) - #131067 (Fix std_detect links) - #131644 (Clean up some Miri things in `sys/windows`) - #131646 (sys/unix: add comments for some Miri fallbacks) - #131653 (Remove const trait bound modifier hack) - #131659 (enable `download_ci_llvm` test) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-14Fix AArch64InlineAsmReg::emitTaiki Endo-49/+62
2024-10-14Fix clobber_abi and disallow SVE-related registers in Arm64EC inline assemblyTaiki Endo-20/+143
2024-10-13Auto merge of #131560 - cuviper:start-1.84, r=cuviperbors-7/+12
Bump to 1.84 https://forge.rust-lang.org/release/process.html#bump-the-stable-version-number-t-6-days-friday-the-week-before r? ghost
2024-10-13core/net: use hex for ipv6 doctests for consistency.Dario Nieuwenhuis-37/+25
2024-10-13core/net: add Ipv[46]Addr::from_octets, Ipv6Addr::from_segmentsDario Nieuwenhuis-1/+101
2024-10-13Rollup merge of #131659 - onur-ozkan:llvm-test, r=albertlarsan68Matthias Krüger-5/+15
enable `download_ci_llvm` test This was ignored because it caused merge failures on [LLVM update PR](https://github.com/rust-lang/rust/pull/131448). The issue was not checking `is_ci_llvm_available` in the test which is crucial for enabling CI LLVM: https://github.com/rust-lang/rust/blob/2aa26d8a722cf8810b27538c24b93d29324d4ac7/src/bootstrap/src/core/config/config.rs#L2835-L2844
2024-10-13Rollup merge of #131653 - compiler-errors:no-modifier-hack, r=fee1-deadMatthias Krüger-8/+2
Remove const trait bound modifier hack It's no longer necessary, according to the test suite :D r? `@fee1-dead` or anyone really
2024-10-13Rollup merge of #131646 - RalfJung:unix-miri-fallbacks, r=joboetMatthias Krüger-1/+2
sys/unix: add comments for some Miri fallbacks
2024-10-13Rollup merge of #131644 - RalfJung:win-miri, r=joboetMatthias Krüger-8/+3
Clean up some Miri things in `sys/windows` - remove miri hack that is only needed for win7 (we don't support win7 as a target in Miri) - remove outdated comment now that Miri is on CI
2024-10-13Rollup merge of #131067 - ismailarilik:fix-std-detect-links, r=albertlarsan68Matthias Krüger-0/+4
Fix std_detect links This PR aims to fix this issue: https://github.com/rust-lang/rust/issues/96506 Fixes #96506
2024-10-13Rollup merge of #131066 - Binlogo:build-doc/rbe-add-zh-entry, r=albertlarsan68Matthias Krüger-1/+1
Add the Chinese translation entry to the RustByExample build process Following the guidelines outlined at [https://github.com/rust-lang/rust-by-example/blob/master/TRANSLATING.md](https://github.com/rust-lang/rust-by-example/blob/master/TRANSLATING.md), I am adding a Chinese translation to Rust by Example. You can view the related pull request here: [https://github.com/rust-lang/rust-by-example/pull/1886#issue-2537891289](https://github.com/rust-lang/rust-by-example/pull/1886#issue-2537891289). For similar issues and PRs, see [https://github.com/rust-lang/rust/issues/124641](https://github.com/rust-lang/rust/issues/124641) and [https://github.com/rust-lang/rust/pull/124731](https://github.com/rust-lang/rust/pull/124731).
2024-10-13Rollup merge of #130900 - capickett:empty-description-rust-version, ↵Matthias Krüger-3/+5
r=albertlarsan68 Do not output () on empty description When passing an explicitly empty description string, as explained here https://github.com/rust-lang/rust/blob/master/config.example.toml#L611-L613, my expectation is that the resulting rustc will be compatible with upstream. However, it seems that instead, a `()` is added to the end of the version string, causing the version compatibility check to fail. My proposed fix here would be to instead only print `({description})` if `description` is a non-empty string.
2024-10-13Rollup merge of #130356 - lolbinarycat:ci-no-change-id, r=albertlarsan68Matthias Krüger-3/+7
don't warn about a missing change-id in CI fixes #130352
2024-10-13Also use outermost const-anon for impl items in `non_local_defs` lintUrgau-3/+27
2024-10-13check `stage0`, `channel` and `version` files for CI rustconur-ozkan-6/+11
These files have important role for compiler builds, so include them in the "if-unchanged" rustc logic. Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-10-13enable `download_ci_llvm` testonur-ozkan-5/+15
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-10-13Auto merge of #125679 - clarfonthey:escape_ascii, r=joboetbors-26/+110
Optimize `escape_ascii` using a lookup table Based upon my suggestion here: https://github.com/rust-lang/rust/pull/125340#issuecomment-2130441817 Effectively, we can take advantage of the fact that ASCII only needs 7 bits to make the eighth bit store whether the value should be escaped or not. This adds a 256-byte lookup table, but 256 bytes *should* be small enough that very few people will mind, according to my probably not incontrovertible opinion. The generated assembly isn't clearly better (although has fewer branches), so, I decided to benchmark on three inputs: first on a random 200KiB, then on `/bin/cat`, then on `Cargo.toml` for this repo. In all cases, the generated code ran faster on my machine. (an old i7-8700) But, if you want to try my benchmarking code for yourself: <details><summary>Criterion code below. Replace <code>/home/ltdk/rustsrc</code> with the appropriate directory.</summary> ```rust #![feature(ascii_char)] #![feature(ascii_char_variants)] #![feature(const_option)] #![feature(let_chains)] use core::ascii; use core::ops::Range; use criterion::{criterion_group, criterion_main, Criterion}; use rand::{thread_rng, Rng}; const HEX_DIGITS: [ascii::Char; 16] = *b"0123456789abcdef".as_ascii().unwrap(); #[inline] const fn backslash<const N: usize>(a: ascii::Char) -> ([ascii::Char; N], Range<u8>) { const { assert!(N >= 2) }; let mut output = [ascii::Char::Null; N]; output[0] = ascii::Char::ReverseSolidus; output[1] = a; (output, 0..2) } #[inline] const fn hex_escape<const N: usize>(byte: u8) -> ([ascii::Char; N], Range<u8>) { const { assert!(N >= 4) }; let mut output = [ascii::Char::Null; N]; let hi = HEX_DIGITS[(byte >> 4) as usize]; let lo = HEX_DIGITS[(byte & 0xf) as usize]; output[0] = ascii::Char::ReverseSolidus; output[1] = ascii::Char::SmallX; output[2] = hi; output[3] = lo; (output, 0..4) } #[inline] const fn verbatim<const N: usize>(a: ascii::Char) -> ([ascii::Char; N], Range<u8>) { const { assert!(N >= 1) }; let mut output = [ascii::Char::Null; N]; output[0] = a; (output, 0..1) } /// Escapes an ASCII character. /// /// Returns a buffer and the length of the escaped representation. const fn escape_ascii_old<const N: usize>(byte: u8) -> ([ascii::Char; N], Range<u8>) { const { assert!(N >= 4) }; match byte { b'\t' => backslash(ascii::Char::SmallT), b'\r' => backslash(ascii::Char::SmallR), b'\n' => backslash(ascii::Char::SmallN), b'\\' => backslash(ascii::Char::ReverseSolidus), b'\'' => backslash(ascii::Char::Apostrophe), b'\"' => backslash(ascii::Char::QuotationMark), 0x00..=0x1F => hex_escape(byte), _ => match ascii::Char::from_u8(byte) { Some(a) => verbatim(a), None => hex_escape(byte), }, } } /// Escapes an ASCII character. /// /// Returns a buffer and the length of the escaped representation. const fn escape_ascii_new<const N: usize>(byte: u8) -> ([ascii::Char; N], Range<u8>) { /// Lookup table helps us determine how to display character. /// /// Since ASCII characters will always be 7 bits, we can exploit this to store the 8th bit to /// indicate whether the result is escaped or unescaped. /// /// We additionally use 0x80 (escaped NUL character) to indicate hex-escaped bytes, since /// escaped NUL will not occur. const LOOKUP: [u8; 256] = { let mut arr = [0; 256]; let mut idx = 0; loop { arr[idx as usize] = match idx { // use 8th bit to indicate escaped b'\t' => 0x80 | b't', b'\r' => 0x80 | b'r', b'\n' => 0x80 | b'n', b'\\' => 0x80 | b'\\', b'\'' => 0x80 | b'\'', b'"' => 0x80 | b'"', // use NUL to indicate hex-escaped 0x00..=0x1F | 0x7F..=0xFF => 0x80 | b'\0', _ => idx, }; if idx == 255 { break; } idx += 1; } arr }; let lookup = LOOKUP[byte as usize]; // 8th bit indicates escape let lookup_escaped = lookup & 0x80 != 0; // SAFETY: We explicitly mask out the eighth bit to get a 7-bit ASCII character. let lookup_ascii = unsafe { ascii::Char::from_u8_unchecked(lookup & 0x7F) }; if lookup_escaped { // NUL indicates hex-escaped if matches!(lookup_ascii, ascii::Char::Null) { hex_escape(byte) } else { backslash(lookup_ascii) } } else { verbatim(lookup_ascii) } } fn escape_bytes(bytes: &[u8], f: impl Fn(u8) -> ([ascii::Char; 4], Range<u8>)) -> Vec<ascii::Char> { let mut vec = Vec::new(); for b in bytes { let (buf, range) = f(*b); vec.extend_from_slice(&buf[range.start as usize..range.end as usize]); } vec } pub fn criterion_benchmark(c: &mut Criterion) { let mut group = c.benchmark_group("escape_ascii"); group.sample_size(1000); let rand_200k = &mut [0; 200 * 1024]; thread_rng().fill(&mut rand_200k[..]); let cat = include_bytes!("/bin/cat"); let cargo_toml = include_bytes!("/home/ltdk/rustsrc/Cargo.toml"); group.bench_function("old_rand", |b| { b.iter(|| escape_bytes(rand_200k, escape_ascii_old)); }); group.bench_function("new_rand", |b| { b.iter(|| escape_bytes(rand_200k, escape_ascii_new)); }); group.bench_function("old_bin", |b| { b.iter(|| escape_bytes(cat, escape_ascii_old)); }); group.bench_function("new_bin", |b| { b.iter(|| escape_bytes(cat, escape_ascii_new)); }); group.bench_function("old_cargo_toml", |b| { b.iter(|| escape_bytes(cargo_toml, escape_ascii_old)); }); group.bench_function("new_cargo_toml", |b| { b.iter(|| escape_bytes(cargo_toml, escape_ascii_new)); }); group.finish(); } criterion_group!(benches, criterion_benchmark); criterion_main!(benches); ``` </details> My benchmark results: ``` escape_ascii/old_rand time: [1.6965 ms 1.7006 ms 1.7053 ms] Found 22 outliers among 1000 measurements (2.20%) 4 (0.40%) high mild 18 (1.80%) high severe escape_ascii/new_rand time: [1.6749 ms 1.6953 ms 1.7158 ms] Found 38 outliers among 1000 measurements (3.80%) 38 (3.80%) high mild escape_ascii/old_bin time: [224.59 µs 225.40 µs 226.33 µs] Found 39 outliers among 1000 measurements (3.90%) 17 (1.70%) high mild 22 (2.20%) high severe escape_ascii/new_bin time: [164.86 µs 165.63 µs 166.58 µs] Found 107 outliers among 1000 measurements (10.70%) 43 (4.30%) high mild 64 (6.40%) high severe escape_ascii/old_cargo_toml time: [23.397 µs 23.699 µs 24.014 µs] Found 204 outliers among 1000 measurements (20.40%) 21 (2.10%) high mild 183 (18.30%) high severe escape_ascii/new_cargo_toml time: [16.404 µs 16.438 µs 16.483 µs] Found 88 outliers among 1000 measurements (8.80%) 56 (5.60%) high mild 32 (3.20%) high severe ``` Random: 1.7006ms => 1.6953ms (<1% speedup) Binary: 225.40µs => 165.63µs (26% speedup) Text: 23.699µs => 16.438µs (30% speedup)
2024-10-13Remove const trait bound modifier hackMichael Goulet-8/+2
2024-10-13Auto merge of #131645 - matthiaskrgr:rollup-lgr1ezu, r=matthiaskrgrbors-342/+374
Rollup of 6 pull requests Successful merges: - #131086 (Update unicode-width to 0.2.0) - #131585 (compiletest: Remove the one thing that was checking a directive's `original_line`) - #131614 (Error on trying to use revisions in `run-make` tests) - #131638 (compiletest: Move debugger setup code out of `lib.rs`) - #131641 (switch unicode-data bitsets back to 'static') - #131642 (Special case error message for a `build-fail` test that failed check build) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-13sys/unix: add comments for some Miri fallbacksRalf Jung-1/+2
2024-10-13Rollup merge of #131642 - jieyouxu:build-fail-check-fail, r=KobzolMatthias Krüger-7/+26
Special case error message for a `build-fail` test that failed check build A `build-fail` test requires that a check build (roughly `--emit=metadata`, no codegen) succeeds but fails later. Previously, if its check build failed, the user will see the error message ``` error: test compilation failed although it shouldn't! ``` which is confusing. Because the test is `build-fail`, we want the test compilation to fail! This error message doesn't account for the difference between a check build and a complete build, so let's special case the error message for a `build-fail` test whose check build failed to instead say ``` error: `build-fail` test is required to pass check build, but check build failed ``` Fixes #130894.