Skip to content

Commit 8fe8f56

Browse files
committed
Squashed 'library/' changes from 771d77c..78fc550
78fc550 Auto merge of rust-lang#133247 - GuillaumeGomez:reduce-integer-display-impl, r=workingjubilee db5c2c6 Rollup merge of rust-lang#132982 - suaviloquence:2-doc-changed-alloc-methods, r=Mark-Simulacrum 117ad4f Rollup merge of rust-lang#132533 - SUPERCILEX:patch-4, r=Mark-Simulacrum e2aa7c1 fix `Allocator` method names in `alloc` free function docs 6b141ee Rollup merge of rust-lang#133298 - n0toose:remove-dir-all-but-not-paths, r=Noratrieb e3691db Rollup merge of rust-lang#133260 - compiler-errors:deref, r=fee1-dead 895f290 Rollup merge of rust-lang#132730 - joboet:after_main_sync, r=Noratrieb 6ffa455 Rollup merge of rust-lang#133389 - eduardosm:stabilize-const_float_methods, r=RalfJung f413935 Rollup merge of rust-lang#133301 - GuillaumeGomez:add-example-wrapping-neg, r=workingjubilee 6112cfd Auto merge of rust-lang#132611 - compiler-errors:async-prelude, r=ibraheemdev 23a5a0e Auto merge of rust-lang#132597 - lukas-code:btree-plug-leak, r=jhpratt f0b0942 Constify Deref and DerefMut d05e8e8 Auto merge of rust-lang#133379 - jieyouxu:rollup-00jxo71, r=jieyouxu 641c1ae Stabilize `const_float_methods` 256c54d Auto merge of rust-lang#133377 - jieyouxu:rollup-n536hzq, r=jieyouxu dff533f Improve code by using `unsigned_abs` a850f7c Rollup merge of rust-lang#133237 - fee1-dead-contrib:constadd, r=compiler-errors 99741dd Rollup merge of rust-lang#133332 - bjoernager:const-array-as-mut-slice, r=jhpratt 9a152e2 Rollup merge of rust-lang#131505 - madsmtm:darwin_user_temp_dir, r=dtolnay a12c838 Auto merge of rust-lang#132994 - clubby789:cc-bisect, r=Kobzol 6548ad8 Auto merge of rust-lang#133360 - compiler-errors:rollup-a2o38tq, r=compiler-errors a4f797e Rollup merge of rust-lang#133264 - lolbinarycat:os-string-truncate, r=joboet a939801 Auto merge of rust-lang#132329 - compiler-errors:fn-and-destruct, r=lcnr 30aa6db Add code example for `wrapping_neg` method for signed integers bc77567 Deduplicate checking drop terminator 6f3ec5c Gate const drop behind const_destruct feature, and fix const_precise_live_drops post-drop-elaboration check fb6f0c2 Auto merge of rust-lang#133339 - jieyouxu:rollup-gav0nvr, r=jieyouxu c792ef3 Rollup merge of rust-lang#133337 - ColinFinck:thread-scoped-fix-typo, r=joboet cfed1c6 Rollup merge of rust-lang#133330 - RalfJung:close, r=the8472 e26edf0 Rollup merge of rust-lang#133313 - thesummer:fix-arc4random, r=cuviper 90a85ef Rollup merge of rust-lang#133288 - bjoernager:const-array-each-ref, r=jhpratt 4e6f154 Rollup merge of rust-lang#133238 - heiher:loong-stdarch-rexport, r=Amanieu 23a1b31 Auto merge of rust-lang#130867 - michirakara:steps_between, r=dtolnay 9693572 Fix typo in `std::thread::Scope::spawn` documentation. b4a5067 Mark '<[T; N]>::as_mut_slice' as 'const'; b6b40ef library: update comment around close() 6ce7e79 Don't try to use confstr in Miri 40d6e2c Auto merge of rust-lang#129238 - umgefahren:stabilize-ipv6-unique-local, r=dtolnay 276c0fc distinguish overflow and unimplemented in Step::steps_between 8be952b Use arc4random of libc for RTEMS target 4583dde Mention that std::fs::remove_dir_all fails on files 4f6ca37 Mark and implement 'each_ref' and 'each_mut' in '[T; N]' as const; ec220b6 constify `Add` 3c558bf Rollup merge of rust-lang#131736 - hoodmane:emscripten-wasm-bigint, r=workingjubilee 38d4c11 implement OsString::truncate 4fd2c8d Rollup merge of rust-lang#133226 - compiler-errors:opt-in-pointer-like, r=lcnr 3f03a0f Rollup merge of rust-lang#130800 - bjoernager:const-mut-cursor, r=joshtriplett eea7e23 Rollup merge of rust-lang#129838 - Ayush1325:uefi-process-args, r=joboet 8b4995a Make PointerLike opt-in as a trait f74b38a Reduce integer `Display` implementation size 2f179d1 Stabilize const_pin_2 b2dc297 re-export `is_loongarch_feature_detected` e26c298 Rollup merge of rust-lang#132732 - gavincrawford:as_ptr_attribute, r=Urgau d6ee9db Rollup merge of rust-lang#133183 - n0toose:improve-remove-dir-docs, r=joboet 40735d3 Rollup merge of rust-lang#125405 - m-ou-se:thread-add-spawn-hook, r=WaffleLapkin 6c20348 Rollup merge of rust-lang#123947 - zopsicle:vec_deque-Iter-as_slices, r=Amanieu 2089cb3 Update doc comments for spawn hook. c02090d Address review comments. 79bffa9 Fix tracking issue. 3eff64c Add tracking issue. 15bac4f Use Send + Sync for spawn hooks. a42af06 Add thread Builder::no_hooks(). 49ac15b Update thread spawn hooks. 2cc4b2e Use add_spawn_hook for libtest's output capturing. 24a0765 Add std::thread::add_spawn_hook. 50ac725 Correct comments concerning updated dangling pointer lint cdf5486 Auto merge of rust-lang#133205 - matthiaskrgr:rollup-xhhhp5u, r=matthiaskrgr 543667a Rollup merge of rust-lang#133200 - RalfJung:miri-rwlock-test, r=tgross35 7430eb4 ignore an occasionally-failing test in Miri 607b493 Rollup merge of rust-lang#133182 - RalfJung:const-panic-inline, r=tgross35 e6cd122 Rollup merge of rust-lang#132758 - nnethercote:improve-get_key_value-docs, r=cuviper a3c9597 Mention std::fs::remove_dir_all in std::fs::remove_dir bd5c142 Bump `stdarch` to the latest master e84f865 const_panic: inline in bootstrap builds to avoid f16/f128 crashes 05fecb9 std: allow after-main use of synchronization primitives c1beb25 Auto merge of rust-lang#133160 - jhpratt:rollup-wzj9q15, r=jhpratt ce80c9f Rollup merge of rust-lang#133145 - kornelski:static-mutex, r=traviscross f385ac2 Auto merge of rust-lang#128219 - connortsui20:rwlock-downgrade, r=tgross35 86151ab rename rustc_const_stable_intrinsic -> rustc_intrinsic_const_stable_indirect a33f889 Improve `{BTreeMap,HashMap}::get_key_value` docs. 15e6fc0 Document alternatives to `static mut` 1cd1dd7 Auto merge of rust-lang#120370 - x17jiri:likely_unlikely_fix, r=saethlin e475f40 Likely unlikely fix ddcabfe Rollup merge of rust-lang#133126 - ohno418:fix-String-doc, r=jhpratt e4eff6a Rollup merge of rust-lang#133116 - RalfJung:const-null-ptr, r=dtolnay 16e6d20 alloc: fix `String`'s doc e4fb962 clean up const stability around UB checks ee78601 stabilize const_ptr_is_null 1e4a9ee Rollup merge of rust-lang#132449 - RalfJung:is_val_statically_known, r=compiler-errors 1dfe94c Rollup merge of rust-lang#131717 - tgross35:stabilize-const_atomic_from_ptr, r=RalfJung 70326e8 reduce threads in downgrade test d58e4f2 fix `DOWNGRADED` bit unpreserved 5d68316 fix memory ordering bug + bad test 0604b8f add safety comments for queue implementation 00255e6 add `downgrade` to `queue` implementation 40256c6 modify queue implementation documentation f804164 add `downgrade` to `futex` implementation 572aded add simple `downgrade` implementations 48bcf09 add `downgrade` method onto `RwLockWriteGuard` 5416aef add `RwLock` `downgrade` tests 4010980 Rollup merge of rust-lang#133050 - tgross35:inline-f16-f128, r=saethlin 2ee4159 Rollup merge of rust-lang#133048 - cyrgani:ptr-doc-update, r=Amanieu e1448de Rollup merge of rust-lang#133019 - sorairolake:add-missing-period-and-colon, r=tgross35 b1d31d2 Rollup merge of rust-lang#132984 - sunshowers:pipe2, r=tgross35 8cef1ef Rollup merge of rust-lang#132977 - cberner:fix_solaris, r=tgross35 daa9c43 Rollup merge of rust-lang#132790 - aDotInTheVoid:ioslice-asslice-rides-again, r=cuviper cdb5ff5 Pass `f16` and `f128` by value in `const_assert!` 60ef479 use `&raw` in `{read, write}_unaligned` documentation d2983ff Auto merge of rust-lang#132709 - programmerjake:optimize-charto_digit, r=joshtriplett 918cc8d Rollup merge of rust-lang#133027 - no1wudi:master, r=jhpratt 25f5512 Auto merge of rust-lang#133026 - workingjubilee:rollup-q8ig6ah, r=workingjubilee d8de2cc Fix a copy-paste issue in the NuttX raw type definition c06bb34 Rollup merge of rust-lang#133008 - onur-ozkan:update-outdated-comment, r=jieyouxu 8eaea39 Rollup merge of rust-lang#133004 - cuviper:unrecover-btree, r=ibraheemdev 81a191a Rollup merge of rust-lang#133003 - zachs18:clonetouninit-dyn-compat-u8, r=dtolnay e3e5e35 Rollup merge of rust-lang#132907 - BLANKatGITHUB:intrinsic, r=saethlin f57853b Rollup merge of rust-lang#131304 - RalfJung:float-core, r=tgross35 7bc0436 Auto merge of rust-lang#122770 - iximeow:ixi/int-formatting-optimization, r=workingjubilee ce2e318 docs: Fix missing colon in methods for primitive types 1870e92 docs: Fix missing period in methods for integer types 6439774 Auto merge of rust-lang#133006 - matthiaskrgr:rollup-dz6oiq5, r=matthiaskrgr 98dad0b update outdated comment about test-float-parse 520d4fd Rollup merge of rust-lang#126046 - davidzeng0:mixed_integer_ops_unsigned_sub, r=Amanieu e3c425b Auto merge of rust-lang#132662 - RalfJung:const-panic-inlining, r=tgross35 c4b77cf Update core CloneToUninit tests d4e21f5 btree: simplify the backdoor between set and map 5d61cf9 Bump `cc` 44f376b Fix compilation error on Solaris due to flock usage 75609d6 Auto merge of rust-lang#132556 - clubby789:cargo-update, r=Mark-Simulacrum 5ba28a4 Run `cargo update` and update licenses 0820004 const_panic: don't wrap it in a separate function d30e2c0 [illumos] use pipe2 to create anonymous pipes 7e12686 Auto merge of rust-lang#132883 - LaihoE:vectorized_is_sorted, r=thomcc 02e32d7 Auto merge of rust-lang#132972 - matthiaskrgr:rollup-456osr7, r=matthiaskrgr 157eb1c Rollup merge of rust-lang#132970 - tyilo:nonzero-u-div-ceil-issue, r=tgross35 03e52a5 Rollup merge of rust-lang#132966 - RalfJung:const_option_ext, r=jhpratt 2f615a1 Rollup merge of rust-lang#132948 - RalfJung:const_unicode_case_lookup, r=Noratrieb f00e091 Rollup merge of rust-lang#132851 - chansuke:update-comment, r=thomcc 6560098 Auto merge of rust-lang#132870 - Noratrieb:inline-int-parsing, r=tgross35 a0c0c40 Add tracking issue number to unsigned_nonzero_div_ceil feature c229666 Make `CloneToUninit` dyn-compatible 6ab50dd stabilize const_option_ext 27fe6c7 Rollup merge of rust-lang#132541 - RalfJung:const-stable-extern-crate, r=compiler-errors 7fafe99 stabilize const_unicode_case_lookup c5ed625 Stabilize `Ipv6Addr::is_unique_local` and `Ipv6Addr::is_unicast_link_local` e0452c9 adds new declaration to codegen 33fa870 Auto merge of rust-lang#132943 - matthiaskrgr:rollup-164l3ej, r=matthiaskrgr 7f12f02 Rollup merge of rust-lang#132914 - rcorre:cell-grammar, r=tgross35 300a266 Rollup merge of rust-lang#132895 - scottmcm:generalize-nonnull-from-raw-parts, r=ibraheemdev a461cf9 remove no-longer-needed abs_private 170e993 allow rustc_private feature in force-unstable-if-unmarked crates 4a20245 Rollup merge of rust-lang#132929 - cuviper:check-alloc_zeroed, r=tgross35 992bbf7 Rollup merge of rust-lang#132869 - lolbinarycat:library-fix-too_long_first_doc_paragraph, r=tgross35 e3925fa Rollup merge of rust-lang#132847 - RalfJung:addr-dont-expose, r=Mark-Simulacrum 327a0d7 Auto merge of rust-lang#132919 - matthiaskrgr:rollup-ogghyvp, r=matthiaskrgr 67c3c9f Check for null in the `alloc_zeroed` example 068537a new intrinsic declaration b689951 new intrinsic declaration 16fa12e Rollup merge of rust-lang#132144 - adetaylor:receiver-trait-itself, r=wesleywiser 54f699d Rollup merge of rust-lang#120077 - SUPERCILEX:set-entry, r=Amanieu e541a4f Update dangling pointer tests 7707584 Tag relevant functions with #[rustc_as_ptr] attribute b541c5a Auto merge of rust-lang#132902 - matthiaskrgr:rollup-43qgg3t, r=matthiaskrgr 2d676d4 Update grammar in std::cell docs. 7325f33 Emscripten: link with -sWASM_BIGINT 1c482c9 Rollup merge of rust-lang#130999 - cberner:flock_pr, r=joboet 4dd2270 Auto merge of rust-lang#127589 - notriddle:notriddle/search-sem-3, r=GuillaumeGomez 0af64b6 Generalize `NonNull::from_raw_parts` per ACP362 2fd9ac4 vectorize slice::is_sorted 737521c `#[inline]` integer parsing functions b9be1dd split up the first paragraph of doc comments for better summaries f9063ff Update the doc comment of `ASCII_CASE_MASK` 57c7b80 elem_offset / subslice_range: use addr() instead of 'as usize' d19aa69 Rollup merge of rust-lang#132136 - RalfJung:target-feature-abi-compat, r=Mark-Simulacrum 6b0bd5a honor rustc_const_stable_indirect in non-staged_api crate with -Zforce-unstable-if-unmarked 070baf4 Add as_slice/into_slice for IoSlice/IoSliceMut. 978a553 Rollup merge of rust-lang#132778 - lolbinarycat:io-Error-into_inner-docs, r=cuviper 6d54bfe update io::Error::into_inner to acknowlage io::Error::other 7c0a90c Address review comments ac66068 Update library/std/src/sys/pal/windows/fs.rs d90f866 Auto merge of rust-lang#132717 - RalfJung:rustc_safe_intrinsic, r=compiler-errors f2bf9e6 remove support for rustc_safe_intrinsic attribute; use rustc_intrinsic functions instead 2391b4b Rollup merge of rust-lang#132738 - cuviper:channel-heap-init, r=ibraheemdev 086cfef mark is_val_statically_known intrinsic as stably const-callable dffc5e7 Rollup merge of rust-lang#132696 - fortanix:raoul/rte-235-fix_fmodl_missing_symbol_issue, r=tgross35 f14fc56 Rollup merge of rust-lang#132639 - RalfJung:intrinsics, r=workingjubilee,Amanieu 6d63012 Initialize channel `Block`s directly on the heap 7ff251b core: move intrinsics.rs into intrinsics folder 6244f48 Auto merge of rust-lang#132714 - mati865:update-memchr, r=tgross35 a2eaef7 Rollup merge of rust-lang#132715 - tabokie:fix-lazy-lock-doc, r=Noratrieb 6a77b21 Rollup merge of rust-lang#132665 - tyilo:nonzero-u-div-ceil, r=joboet 79d2063 Separate f128 `%` operation to deal with missing `fmodl` symbol 8022523 Auto merge of rust-lang#132705 - kornelski:inline-repeat, r=tgross35 df9f5db fix lazylock comment 7a82eb5 Auto merge of rust-lang#131888 - ChrisDenton:deopt, r=ibraheemdev 75b9ce3 unpin and update memchr 4d1c7d9 optimize char::to_digit and assert radix is at least 2 95bff3e Inline str::repeat 52c2a45 Rollup merge of rust-lang#132617 - uellenberg:fix-rendered-doc, r=cuviper 28f7e7b Auto merge of rust-lang#131721 - okaneco:const_eq_ignore_ascii_case, r=m-ou-se 41b7e5f Auto merge of rust-lang#132500 - RalfJung:char-is-whitespace-const, r=jhpratt 4ed08bd Add new unstable feature `const_eq_ignore_ascii_case` f4e9fe4 Auto merge of rust-lang#132664 - matthiaskrgr:rollup-i27nr7i, r=matthiaskrgr afc66fe Change some code blocks to quotes in rendered std doc 2e63cbd Rollup merge of rust-lang#131261 - clarfonthey:unsafe-cell-from-mut, r=m-ou-se ab6f663 Auto merge of rust-lang#132661 - matthiaskrgr:rollup-npytbl6, r=matthiaskrgr 8b165db Implement div_ceil for NonZero<unsigned> 6bc1b1b Rollup merge of rust-lang#132571 - RalfJung:const_eval_select_macro, r=oli-obk c12f4d1 Rollup merge of rust-lang#132473 - ZhekaS:core_fmt_radix_no_panic, r=joboet bbb9275 Rollup merge of rust-lang#132153 - bjoernager:const-char-encode-utf16, r=dtolnay 919de70 add const_eval_select macro to reduce redundancy 538f5b4 Rollup merge of rust-lang#132609 - NotWearingPants:patch-1, r=Amanieu 86c6f27 Rollup merge of rust-lang#132606 - eduardosm:char-slice-str-pattern-doc, r=tgross35 4660d7e most const intrinsics don't need an explicit rustc_const_unstable any more 8eb30fe add new rustc_const_stable_intrinsic attribute for const-stable intrinsics 792d164 convert all const-callable intrinsics into the new form (without extern block) fad7d68 docs: fix grammar in doc comment at unix/process.rs 92bb779 Improve example of `impl Pattern for &[char]` 553bb18 Add AsyncFn* to to the prelude in all editions 2ae24bf Fixed typo, rebased 47f60d7 Updated SAFETY comment to address underflow 581aa8d Replace checked slice indexing by unchecked to support panic-free code c5a0f6c Rollup merge of rust-lang#132579 - RalfJung:rustc-std-workspace-crates, r=Amanieu 9cdbf39 btree: don't leak value if destructor of key panics 4caff13 Stabilise 'const_char_encode_utf16'; 84fae7e Auto merge of rust-lang#132586 - workingjubilee:rollup-qrmn49a, r=workingjubilee 95b4127 update rustc-std-workspace crates 082b98d Rollup merge of rust-lang#132423 - RalfJung:const-eval-align-offset, r=dtolnay 3b40634 Auto merge of rust-lang#132434 - tgross35:f128-tests, r=workingjubilee 5dea8b2 Enable `f128` tests on all non-buggy platforms 🎉 2bb8ea3 Auto merge of rust-lang#132581 - workingjubilee:rollup-4wj318p, r=workingjubilee 83bd286 Update `compiler_builtins` to 0.1.138 and pin it 699702f Rollup merge of rust-lang#132563 - frectonz:master, r=Amanieu 4390c35 Auto merge of rust-lang#123723 - madsmtm:apple-std-os, r=dtolnay 1e8ed90 Auto merge of rust-lang#132479 - compiler-errors:fx-feat-yeet, r=fee1-dead 9a3b7c0 Rename the FIXMEs, remove a few that dont matter anymore ed4f110 Auto merge of rust-lang#132542 - RalfJung:const_panic, r=tgross35 d8bca01 remove const-support for align_offset 76b866c Modify `NonZero` documentation to reference the underlying integer type 9e57964 Rollup merge of rust-lang#132511 - RalfJung:const_arguments_as_str, r=dtolnay bfeeb74 Rollup merge of rust-lang#132503 - RalfJung:const-hash-map, r=Amanieu a42fc21 Rollup merge of rust-lang#132499 - RalfJung:unicode_data.rs, r=tgross35 0278cab Rollup merge of rust-lang#132393 - zedddie16:issue-131865-fix, r=tgross35 714115a Rollup merge of rust-lang#131377 - rick-de-water:nonzero-exp, r=dtolnay 9789c54 Rollup merge of rust-lang#129329 - eduardosm:rc-from-mut-slice, r=dtolnay ff9178b add const_panic macro to make it easier to fall back to non-formatting panic in const 9ef483b stabilize const_arguments_as_str 4c6593f Auto merge of rust-lang#132458 - RalfJung:rustc-const-unstable, r=Amanieu 81b20e0 Rustdoc: added brief colon explanation 73d9f4d Add Set entry API e883a60 Add BorrowedBuf::into_filled{,_mut} methods to allow returning buffer with original lifetime 261c5b9 remove const_hash feature leftovers d515da6 const_with_hasher test: actually construct a usable HashMap 11dc6c3 make char::is_whitespace unstably const 1a481fd unicode_data.rs: show command for generating file 3a5b026 get rid of a whole bunch of unnecessary rustc_const_unstable attributes 2e24b7f remove no-longer-needed attribute ffbcba0 add missing safety comments 768d0cd adjust test gating for f16/f128 6335056 float types: move copysign, abs, signum to libcore c353337 rustdoc-search: simplify rules for generics and type params 9d10ab7 Implement `From<&mut {slice}>` for `Box/Rc/Arc<{slice}>` 34329c0 Stabilize `const_atomic_from_ptr` a2e1edf Arbitrary self types v2: (unused) Receiver trait 2d26681 ABI compatibility: remove section on target features f1c9904 Support lock() and lock_shared() on async IO Files 7f6af4d Revert using `HEAP` static in Windows alloc 541bda1 Implement file_lock feature d7a7b0a uefi: process: Add args support 14aef3d Use with_capacity(0) because we're reading the capacity later on 5b16abe Prefer `target_vendor = "apple"` on confstr bc63981 use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on darwin f8dc879 Add LowerExp and UpperExp implementations 50afc52 Stabilize UnsafeCell::from_mut aa74e93 Mark 'get_mut' and 'set_position' in 'std::io::Cursor' as const; c370665 Make `std::os::darwin` public 797c249 Implement `mixed_integer_ops_unsigned_sub` ff1212e Add vec_deque::Iter::as_slices and friends e938dea try adding a test that LowerHex and friends don't panic, but it doesn't work c6d2bb7 improve codegen of fmt_num to delete unreachable panic git-subtree-dir: library git-subtree-split: 78fc550
1 parent dbb25f2 commit 8fe8f56

File tree

168 files changed

+9266
-6477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+9266
-6477
lines changed

Cargo.lock

+14-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

alloc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2021"
1010

1111
[dependencies]
1212
core = { path = "../core" }
13-
compiler_builtins = { version = "0.1.136", features = ['rustc-dep-of-std'] }
13+
compiler_builtins = { version = "=0.1.138", features = ['rustc-dep-of-std'] }
1414

1515
[dev-dependencies]
1616
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

alloc/src/alloc.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub use std::alloc::Global;
6161
/// of the allocator registered with the `#[global_allocator]` attribute
6262
/// if there is one, or the `std` crate’s default.
6363
///
64-
/// This function is expected to be deprecated in favor of the `alloc` method
64+
/// This function is expected to be deprecated in favor of the `allocate` method
6565
/// of the [`Global`] type when it and the [`Allocator`] trait become stable.
6666
///
6767
/// # Safety
@@ -106,7 +106,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
106106
/// of the allocator registered with the `#[global_allocator]` attribute
107107
/// if there is one, or the `std` crate’s default.
108108
///
109-
/// This function is expected to be deprecated in favor of the `dealloc` method
109+
/// This function is expected to be deprecated in favor of the `deallocate` method
110110
/// of the [`Global`] type when it and the [`Allocator`] trait become stable.
111111
///
112112
/// # Safety
@@ -125,7 +125,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
125125
/// of the allocator registered with the `#[global_allocator]` attribute
126126
/// if there is one, or the `std` crate’s default.
127127
///
128-
/// This function is expected to be deprecated in favor of the `realloc` method
128+
/// This function is expected to be deprecated in favor of the `grow` and `shrink` methods
129129
/// of the [`Global`] type when it and the [`Allocator`] trait become stable.
130130
///
131131
/// # Safety
@@ -145,7 +145,7 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
145145
/// of the allocator registered with the `#[global_allocator]` attribute
146146
/// if there is one, or the `std` crate’s default.
147147
///
148-
/// This function is expected to be deprecated in favor of the `alloc_zeroed` method
148+
/// This function is expected to be deprecated in favor of the `allocate_zeroed` method
149149
/// of the [`Global`] type when it and the [`Allocator`] trait become stable.
150150
///
151151
/// # Safety
@@ -155,11 +155,14 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
155155
/// # Examples
156156
///
157157
/// ```
158-
/// use std::alloc::{alloc_zeroed, dealloc, Layout};
158+
/// use std::alloc::{alloc_zeroed, dealloc, handle_alloc_error, Layout};
159159
///
160160
/// unsafe {
161161
/// let layout = Layout::new::<u16>();
162162
/// let ptr = alloc_zeroed(layout);
163+
/// if ptr.is_null() {
164+
/// handle_alloc_error(layout);
165+
/// }
163166
///
164167
/// assert_eq!(*(ptr as *mut u16), 0);
165168
///

alloc/src/boxed.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ use core::error::{self, Error};
191191
use core::fmt;
192192
use core::future::Future;
193193
use core::hash::{Hash, Hasher};
194+
#[cfg(not(bootstrap))]
195+
use core::marker::PointerLike;
194196
use core::marker::{Tuple, Unsize};
195197
use core::mem::{self, SizedTypeProperties};
196198
use core::ops::{
@@ -225,6 +227,7 @@ pub use thin::ThinBox;
225227
#[fundamental]
226228
#[stable(feature = "rust1", since = "1.0.0")]
227229
#[rustc_insignificant_dtor]
230+
#[cfg_attr(not(bootstrap), doc(search_unbox))]
228231
// The declaration of the `Box` struct must be kept in sync with the
229232
// compiler or ICEs will happen.
230233
pub struct Box<
@@ -1499,6 +1502,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
14991502
/// [`as_ptr`]: Self::as_ptr
15001503
#[unstable(feature = "box_as_ptr", issue = "129090")]
15011504
#[rustc_never_returns_null_ptr]
1505+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
15021506
#[inline]
15031507
pub fn as_mut_ptr(b: &mut Self) -> *mut T {
15041508
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
@@ -1547,6 +1551,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
15471551
/// [`as_ptr`]: Self::as_ptr
15481552
#[unstable(feature = "box_as_ptr", issue = "129090")]
15491553
#[rustc_never_returns_null_ptr]
1554+
#[cfg_attr(not(bootstrap), rustc_as_ptr)]
15501555
#[inline]
15511556
pub fn as_ptr(b: &Self) -> *const T {
15521557
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
@@ -1734,7 +1739,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
17341739
// Pre-allocate memory to allow writing the cloned value directly.
17351740
let mut boxed = Self::new_uninit_in(self.1.clone());
17361741
unsafe {
1737-
(**self).clone_to_uninit(boxed.as_mut_ptr());
1742+
(**self).clone_to_uninit(boxed.as_mut_ptr().cast());
17381743
boxed.assume_init()
17391744
}
17401745
}
@@ -2128,3 +2133,7 @@ impl<E: Error> Error for Box<E> {
21282133
Error::provide(&**self, request);
21292134
}
21302135
}
2136+
2137+
#[cfg(not(bootstrap))]
2138+
#[unstable(feature = "pointer_like_trait", issue = "none")]
2139+
impl<T> PointerLike for Box<T> {}

alloc/src/boxed/convert.rs

+45
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,29 @@ impl<T: Clone> From<&[T]> for Box<[T]> {
109109
}
110110
}
111111

112+
#[cfg(not(no_global_oom_handling))]
113+
#[stable(feature = "box_from_mut_slice", since = "CURRENT_RUSTC_VERSION")]
114+
impl<T: Clone> From<&mut [T]> for Box<[T]> {
115+
/// Converts a `&mut [T]` into a `Box<[T]>`
116+
///
117+
/// This conversion allocates on the heap
118+
/// and performs a copy of `slice` and its contents.
119+
///
120+
/// # Examples
121+
/// ```rust
122+
/// // create a &mut [u8] which will be used to create a Box<[u8]>
123+
/// let mut array = [104, 101, 108, 108, 111];
124+
/// let slice: &mut [u8] = &mut array;
125+
/// let boxed_slice: Box<[u8]> = Box::from(slice);
126+
///
127+
/// println!("{boxed_slice:?}");
128+
/// ```
129+
#[inline]
130+
fn from(slice: &mut [T]) -> Box<[T]> {
131+
Self::from(&*slice)
132+
}
133+
}
134+
112135
#[cfg(not(no_global_oom_handling))]
113136
#[stable(feature = "box_from_cow", since = "1.45.0")]
114137
impl<T: Clone> From<Cow<'_, [T]>> for Box<[T]> {
@@ -147,6 +170,28 @@ impl From<&str> for Box<str> {
147170
}
148171
}
149172

173+
#[cfg(not(no_global_oom_handling))]
174+
#[stable(feature = "box_from_mut_slice", since = "CURRENT_RUSTC_VERSION")]
175+
impl From<&mut str> for Box<str> {
176+
/// Converts a `&mut str` into a `Box<str>`
177+
///
178+
/// This conversion allocates on the heap
179+
/// and performs a copy of `s`.
180+
///
181+
/// # Examples
182+
///
183+
/// ```rust
184+
/// let mut original = String::from("hello");
185+
/// let original: &mut str = &mut original;
186+
/// let boxed: Box<str> = Box::from(original);
187+
/// println!("{boxed}");
188+
/// ```
189+
#[inline]
190+
fn from(s: &mut str) -> Box<str> {
191+
Self::from(&*s)
192+
}
193+
}
194+
150195
#[cfg(not(no_global_oom_handling))]
151196
#[stable(feature = "box_from_cow", since = "1.45.0")]
152197
impl From<Cow<'_, str>> for Box<str> {

alloc/src/collections/btree/map.rs

+48-38
Original file line numberDiff line numberDiff line change
@@ -289,40 +289,12 @@ impl<K: Clone, V: Clone, A: Allocator + Clone> Clone for BTreeMap<K, V, A> {
289289
}
290290
}
291291

292-
impl<K, Q: ?Sized, A: Allocator + Clone> super::Recover<Q> for BTreeMap<K, SetValZST, A>
293-
where
294-
K: Borrow<Q> + Ord,
295-
Q: Ord,
296-
{
297-
type Key = K;
298-
299-
fn get(&self, key: &Q) -> Option<&K> {
300-
let root_node = self.root.as_ref()?.reborrow();
301-
match root_node.search_tree(key) {
302-
Found(handle) => Some(handle.into_kv().0),
303-
GoDown(_) => None,
304-
}
305-
}
306-
307-
fn take(&mut self, key: &Q) -> Option<K> {
308-
let (map, dormant_map) = DormantMutRef::new(self);
309-
let root_node = map.root.as_mut()?.borrow_mut();
310-
match root_node.search_tree(key) {
311-
Found(handle) => Some(
312-
OccupiedEntry {
313-
handle,
314-
dormant_map,
315-
alloc: (*map.alloc).clone(),
316-
_marker: PhantomData,
317-
}
318-
.remove_kv()
319-
.0,
320-
),
321-
GoDown(_) => None,
322-
}
323-
}
324-
325-
fn replace(&mut self, key: K) -> Option<K> {
292+
/// Internal functionality for `BTreeSet`.
293+
impl<K, A: Allocator + Clone> BTreeMap<K, SetValZST, A> {
294+
pub(super) fn replace(&mut self, key: K) -> Option<K>
295+
where
296+
K: Ord,
297+
{
326298
let (map, dormant_map) = DormantMutRef::new(self);
327299
let root_node =
328300
map.root.get_or_insert_with(|| Root::new((*map.alloc).clone())).borrow_mut();
@@ -705,20 +677,58 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
705677
}
706678
}
707679

708-
/// Returns the key-value pair corresponding to the supplied key.
680+
/// Returns the key-value pair corresponding to the supplied key. This is
681+
/// potentially useful:
682+
/// - for key types where non-identical keys can be considered equal;
683+
/// - for getting the `&K` stored key value from a borrowed `&Q` lookup key; or
684+
/// - for getting a reference to a key with the same lifetime as the collection.
709685
///
710686
/// The supplied key may be any borrowed form of the map's key type, but the ordering
711687
/// on the borrowed form *must* match the ordering on the key type.
712688
///
713689
/// # Examples
714690
///
715691
/// ```
692+
/// use std::cmp::Ordering;
716693
/// use std::collections::BTreeMap;
717694
///
695+
/// #[derive(Clone, Copy, Debug)]
696+
/// struct S {
697+
/// id: u32,
698+
/// # #[allow(unused)] // prevents a "field `name` is never read" error
699+
/// name: &'static str, // ignored by equality and ordering operations
700+
/// }
701+
///
702+
/// impl PartialEq for S {
703+
/// fn eq(&self, other: &S) -> bool {
704+
/// self.id == other.id
705+
/// }
706+
/// }
707+
///
708+
/// impl Eq for S {}
709+
///
710+
/// impl PartialOrd for S {
711+
/// fn partial_cmp(&self, other: &S) -> Option<Ordering> {
712+
/// self.id.partial_cmp(&other.id)
713+
/// }
714+
/// }
715+
///
716+
/// impl Ord for S {
717+
/// fn cmp(&self, other: &S) -> Ordering {
718+
/// self.id.cmp(&other.id)
719+
/// }
720+
/// }
721+
///
722+
/// let j_a = S { id: 1, name: "Jessica" };
723+
/// let j_b = S { id: 1, name: "Jess" };
724+
/// let p = S { id: 2, name: "Paul" };
725+
/// assert_eq!(j_a, j_b);
726+
///
718727
/// let mut map = BTreeMap::new();
719-
/// map.insert(1, "a");
720-
/// assert_eq!(map.get_key_value(&1), Some((&1, &"a")));
721-
/// assert_eq!(map.get_key_value(&2), None);
728+
/// map.insert(j_a, "Paris");
729+
/// assert_eq!(map.get_key_value(&j_a), Some((&j_a, &"Paris")));
730+
/// assert_eq!(map.get_key_value(&j_b), Some((&j_a, &"Paris"))); // the notable case
731+
/// assert_eq!(map.get_key_value(&p), None);
722732
/// ```
723733
#[stable(feature = "map_get_key_value", since = "1.40.0")]
724734
pub fn get_key_value<Q: ?Sized>(&self, k: &Q) -> Option<(&K, &V)>

0 commit comments

Comments
 (0)