about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2023-05-13Auto merge of #111447 - scottmcm:remove-more-assumes, r=thomccbors-4/+0
Remove useless `assume`s from `slice::iter(_mut)` You were right in https://github.com/rust-lang/rust/pull/111395#discussion_r1190312704, r? `@the8472` LLVM already removes these assumes while optimizing, as can be seen in <https://rust.godbolt.org/z/KTfWKbdEM>.
2023-05-12`ascii::Char`-ify the escaping codeScott McMurray-50/+65
This means that `EscapeIterInner::as_str` no longer needs unsafe code, because the type system ensures the internal buffer is only ASCII, and thus valid UTF-8.
2023-05-12Remove useless `assume`s from `slice::iter(_mut)`Scott McMurray-4/+0
2023-05-13Auto merge of #103413 - RalfJung:phantom-dropck, r=lcnrbors-10/+73
PhantomData: fix documentation wrt interaction with dropck As far as I could find out, the `PhantomData`-dropck interaction *only* affects code using `may_dangle`. The documentation in the standard library has not been updated for 8 years and thus stems from a time when Rust still used "parametric dropck", before [RFC 1238](https://rust-lang.github.io/rfcs/1238-nonparametric-dropck.html). Back then what the docs said was correct, but with `may_dangle` dropck it stopped being entirely accurate and these days, with NLL, it is actively misleading. Fixes https://github.com/rust-lang/rust/issues/102810 Fixes https://github.com/rust-lang/rust/issues/70841 Cc `@nikomatsakis` I hope what I am saying here is right.^^
2023-05-12hedge for future changesRalf Jung-4/+7
Co-authored-by: lcnr <rust@lcnr.de>
2023-05-12Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwcobors-3/+4
Uplift `clippy::{drop,forget}_{ref,copy}` lints This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints. Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted. ## `drop_ref` and `forget_ref` The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value. ### Example ```rust let mut lock_guard = mutex.lock(); std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex // still locked operation_that_requires_mutex_to_be_unlocked(); ``` ### Explanation Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended. ## `drop_copy` and `forget_copy` The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait. ### Example ```rust let x: i32 = 42; // i32 implements Copy std::mem::forget(x) // A copy of x is passed to the function, leaving the // original unaffected ``` ### Explanation Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation. ----- Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting)
2023-05-11Auto merge of #111395 - scottmcm:slice-iter-zst-experiment, r=the8472bors-35/+51
Simplify the implementation of iterators over slices of ZSTs Currently, slice iterators over ZSTs store `end = start.wrapping_byte_add(len)`. That's slightly convenient for `is_empty`, but kinda annoying for pretty much everything else -- see bugs like #42789, for example. This PR instead changes it to just `end = ptr::invalid(len)` instead. That's easier to think about (IMHO, at least) as well as easier to represent. `next` is still to big to get inlined into the mir-opt/pre-codegen/ tests, but if I bump the inline threshold to force it to show the whole thing, this implementation is also less MIR: ``` > git diff --numstat 241 370 tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.mir 255 329 tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.mir 184 216 tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.mir 182 254 tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.mir ``` (That's ≈70 lines less for `Iter::next`, for example.) r? `@ghost` ~~Built atop #111282, so draft until that lands.~~
2023-05-11Populate effective visibilities in rustc_privacyBryanskiy-0/+6
2023-05-10Simplify the implementation of iterators over slices of ZSTsScott McMurray-35/+51
Currently, slice iterators over ZSTs store `end = start.wrapping_byte_add(len)`. That's slightly convenient for `is_empty`, but kinda annoying for pretty much everything else -- see bugs like 42789, for example. This PR instead changes it to just `end = ptr::invalid(len)` instead. That's easier to think about (IMHO, at least) as well as easier to represent.
2023-05-10Allow the drop_copy lint in some library examplesUrgau-0/+1
2023-05-10Remove useless drop of copy typeUrgau-3/+3
2023-05-10Rollup merge of #111408 - TomMD:patch-1, r=workingjubileeMatthias Krüger-1/+1
Fix incorrect implication of transmuting slices transmute<&[u8]> would be useful and as a beginner it is confusing to see documents casually confuse the types of &[u8] and [u8; SZ]
2023-05-09Fix incorrect implication of transmuting slicesThomas M. DuBuisson-1/+1
transmute<&[u8]> would be useful and as a beginner it is confusing to see documents casually confuse the types of &[u8] and [u8; SZ]
2023-05-09Rollup merge of #111282 - scottmcm:remove-unneeded-assumes, r=workingjubileeMatthias Krüger-10/+6
Remove some `assume`s from slice iterators that don't do anything Because the start pointer is iterators is already a `NonNull`, we emit the appropriate `!nonnull` metadata when loading the pointer to tell LLVM that it's non-null. Probably the best way to see that it's the metadata that's important (and not the `assume`) is to observe that LLVM actually *removes* the `assume` from the optimized IR: <https://rust.godbolt.org/z/KhE6G963n>. (I also checked that, yes, the if-not-ZST `assume` on `end` is still doing something: it's how there's a `!nonnull` metadata on its load, even though it's an ordinary raw pointer. The codegen test added in this PR fails if the other `assume` is removed.)
2023-05-09Rollup merge of #110770 - m-ou-se:fmt-temp-lifetime, r=oli-obkMatthias Krüger-0/+15
Limit lifetime of format_args!() with inlined args. Fixes #110769
2023-05-09Rollup merge of #97320 - usbalbin:stabilize_const_ptr_read, r=m-ou-seMatthias Krüger-9/+9
Stabilize const_ptr_read Stabilizes const_ptr_read, with tracking issue #80377
2023-05-09Auto merge of #111371 - compiler-errors:revert-110907, r=petrochenkovbors-6/+0
Revert "Populate effective visibilities in `rustc_privacy`" This reverts commit cff85f22f5030fbe7266d272da74a9e76160523c, cc #110907. It needs to be fixed, but there are too many issues being reported that I wanted to put up a revert until a proper fix can be committed. Fixes a ton of issues where private but still reachable impls were missing during codegen: Fixes #111320 Fixes #111321 Fixes #111334 Fixes #111357 Fixes #111368 Fixes #111373 Fixes #111377 Fixes #111386 Fixes #111387 `@bors` p=1 r? `@petrochenkov`
2023-05-09Limit lifetime of format_args!() with inlined args.Mara Bos-0/+15
2023-05-09Rollup merge of #110694 - est31:builtin, r=petrochenkovDylan DPC-3/+3
Implement builtin # syntax and use it for offset_of!(...) Add `builtin #` syntax to the parser, as well as a generic infrastructure to support both item and expression position builtin syntaxes. The PR also uses this infrastructure for the implementation of the `offset_of!` macro, added by #106934. cc `@petrochenkov` `@DrMeepster` cc #110680 `builtin #` tracking issue cc #106655 `offset_of!` tracking issue
2023-05-09Auto merge of #110027 - nbdd0121:dieting, r=m-ou-sebors-0/+9
Add `#[inline]` to functions that are never called This makes libcore binary size reduce by ~300 bytes. Not much, but these functions are never called so it doesn't make sense for them to get into the binary anyway.
2023-05-08Auto merge of #111296 - Sp00ph:const_gcd, r=nagisa,Mark-Simulacrumbors-37/+6
Always const-evaluate the GCD in `slice::align_to_offsets` Use an inline `const`-block to force the compiler to calculate the GCD at compile time, even in debug mode. This shouldn't affect the behavior of the program at all, but it drastically cuts down on the number of instructions emitted with optimizations disabled. With the current implementation, a single `slice::align_to` instantiation (specifically `<[u8]>::align_to::<u128>()`) generates 676 instructions (on x86-64). Forcing the GCD computation to be const cuts it down to 327 instructions, so just over 50% less. This is obviously not representative of actual runtime gains, but I still see it as a significant win as long as it doesn't degrade compile times. Not having to worry about LLVM const-evaluating the GCD function also allows it to use the textbook recursive euclidean algorithm instead of a much more complicated iterative implementation with multiple `unsafe`-blocks.
2023-05-08Revert "Populate effective visibilities in `rustc_privacy`"Michael Goulet-6/+0
This reverts commit cff85f22f5030fbe7266d272da74a9e76160523c.
2023-05-08Rollup merge of #111315 - Swatinem:rm-identitiy-future, r=Mark-SimulacrumYuki Okushi-7/+0
Remove `identity_future` from stdlib This function/lang_item was introduced in #104321 as a temporary workaround of future lowering. The usage and need for it went away in #104833. After a bootstrap update, the function itself can be removed from `std`.
2023-05-08Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, ↵bors-46/+41
r=Mark-Simulacrum enable `rust_2018_idioms` lint group for doctests With this change, `rust_2018_idioms` lint group will be enabled for compiler/libstd doctests. Resolves #106086 Resolves #99144 Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-07Auto merge of #111222 - scottmcm:constify-is_ascii, r=thomccbors-15/+61
Constify `[u8]::is_ascii` (unstably) UTF-8 checking in `const fn`-stabilized back in 1.63 (#97367), but apparently somehow ASCII checking was never const-ified, despite being simpler. New constness-tracking issue for `is_ascii`: #111090 I noticed this working on `ascii::Char`: #110998
2023-05-07Add `#[inline]` to functions that are never calledGary Guo-0/+9
2023-05-07Remove `identity_future` from stdlibArpad Borsos-7/+0
This function/lang_item was introduced in #104321 as a temporary workaround of future lowering. The usage and need for it went away in #104833. After a bootstrap update, the function itself can be removed from `std`.
2023-05-07Auto merge of #111125 - xfix:inline-socketaddr-methods, r=Mark-Simulacrumbors-0/+27
Inline SocketAddr methods
2023-05-06Tune the `is_ascii` implementation used for short slicesScott McMurray-10/+23
2023-05-07Rollup merge of #111301 - JohnBobbo96:cleanup_option_insert_methods, r=scottmcmYuki Okushi-4/+2
Remove calls to `mem::forget` and `mem::replace` in `Option::get_or_insert_with`. This removes the unneeded calls to `mem::forget` and `mem::replace` in `Option::get_or_insert_with`.
2023-05-07Rollup merge of #110094 - lukas-code:less-transmute, r=thomccYuki Okushi-13/+9
clean up `transmute`s in `core` * Use `transmute_unchecked` instead of `transmute_copy` for `MaybeUninit::transpose`. * Use manual transmute for `Option<Ordering>` → `i8`.
2023-05-06Remove unneeded calls to `mem::forget`John Bobbo-4/+2
and `mem::replace` in `Option::get_or_insert_with`.
2023-05-07enable `rust_2018_idioms` for doctestsozkanonur-46/+41
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-06Auto merge of #110907 - Bryanskiy:privacy_ef, r=petrochenkovbors-0/+6
Populate effective visibilities in 'rustc_privacy' Next part of RFC https://github.com/rust-lang/rust/issues/48054. r? `@petrochenkov`
2023-05-06Always const-eval the gcd in `slice::align_to_offsets`Markus Everling-37/+6
2023-05-06clean up transmutes in coreLukas Markeffsky-13/+9
2023-05-06Remove some `assume`s from slice iterators that don't do anythingScott McMurray-10/+6
2023-05-05Migrate offset_of from a macro to builtin # syntaxest31-3/+3
2023-05-05Stabilize const_ptr_readbors-9/+9
2023-05-05Auto merge of #111248 - Dylan-DPC:rollup-lbp0ui3, r=Dylan-DPCbors-1/+1
Rollup of 6 pull requests Successful merges: - #103056 (Fix `checked_{add,sub}_duration` incorrectly returning `None` when `other` has more than `i64::MAX` seconds) - #108801 (Implement RFC 3348, `c"foo"` literals) - #110773 (Reduce MIR dump file count for MIR-opt tests) - #110876 (Added default target cpu to `--print target-cpus` output and updated docs) - #111068 (Improve check-cfg implementation) - #111238 (btree_map: `Cursor{,Mut}::peek_prev` must agree) Failed merges: - #110694 (Implement builtin # syntax and use it for offset_of!(...)) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-05Populate effective visibilities in `rustc_privacy`Bryanskiy-0/+6
2023-05-05Rollup merge of #108801 - fee1-dead-contrib:c-str, r=compiler-errorsDylan DPC-1/+1
Implement RFC 3348, `c"foo"` literals RFC: https://github.com/rust-lang/rfcs/pull/3348 Tracking issue: #105723
2023-05-05Auto merge of #111113 - scottmcm:assume-align-offset, r=thomccbors-4/+11
`assume` the runtime range of `align_offset` Found when I saw code with `align_to` having extraneous checks. Demo that LLVM can't do this today: <https://rust.godbolt.org/z/6dnG749bq> (It's filed as https://github.com/llvm/llvm-project/issues/62502.)
2023-05-05`assume` the runtime range of `align_offset`Scott McMurray-4/+11
Found when I saw code with `align_to` having extraneous checks.
2023-05-05Rollup merge of #111213 - WaffleLapkin:fixup_dates, r=scottmcmYuki Okushi-2/+2
Fixup "since" dates for `array_tuple_conv` feature Fixes a mistake from #97594
2023-05-05Stabilize feature `nonzero_negation_ops`John Millikin-18/+12
2023-05-04Add an example that depends on `is_ascii` in a `const`Scott McMurray-0/+13
2023-05-04Constify `[u8]::is_ascii` (unstably)Scott McMurray-15/+35
UTF-8 checking in `const fn`-stabilized back in 1.63, but apparently somehow ASCII checking was never const-ified, despite being simpler.
2023-05-04Fixup "since" dates for `array_tuple_conv` featureMaybe Waffle-2/+2
2023-05-04Rollup merge of #111186 - jmillikin:nonzero-is-positive, r=dtolnayMatthias Krüger-0/+26
Add `is_positive` method for signed non-zero integers. ACP: https://github.com/rust-lang/libs-team/issues/105