about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2023-08-07Rollup merge of #114382 - scottmcm:compare-bytes-intrinsic, r=cjgillotMatthias Krüger-15/+40
Add a new `compare_bytes` intrinsic instead of calling `memcmp` directly As discussed in #113435, this lets the backends be the place that can have the "don't call the function if n == 0" logic, if it's needed for the target. (I didn't actually *add* those checks, though, since as I understood it we didn't actually need them on known targets?) Doing this also let me make it `const` (unstable), which I don't think `extern "C" fn memcmp` can be. cc `@RalfJung` `@Amanieu`
2023-08-07Rollup merge of #98935 - kellerkindt:option_retain, r=Mark-SimulacrumMatthias Krüger-0/+35
Implement `Option::take_if` Tracking issue: #98934 ACP: rust-lang/libs-team#70 [accepted]
2023-08-06Add a new `compare_bytes` intrinsic instead of calling `memcmp` directlyScott McMurray-15/+40
2023-08-06Remove ptr_from_mut diagnostic itemest31-1/+0
It was added by #113657 for its purposes. Now it is not used any more, remove it, as we use the attr now.
2023-08-06Add #[rustc_never_returns_null_ptr] to std functionsest31-0/+16
Add the attribute to standard library functions that are guaranteed to never return null pointers, as their originating data wouldn't allow it.
2023-08-05Auto merge of #111200 - a1phyr:spec_sized_iterators, r=the8472bors-0/+130
Optimize `Iterator` implementation for `&mut impl Iterator + Sized` This adds a specialization trait to forward `fold`, `try_fold`,... to the inner iterator where possible
2023-08-05Rollup merge of #114029 - Enselic:clone-doc, r=scottmcmMatthias Krüger-0/+40
Explain more clearly why `fn() -> T` can't be `#[derive(Clone)]` Closes #73480 The derived impls were generated with `rustc -Z unpretty=expanded main.rs` and the raw output is: ```rust struct Generate<T>(fn() -> T); #[automatically_derived] impl<T: ::core::marker::Copy> ::core::marker::Copy for Generate<T> { } #[automatically_derived] impl<T: ::core::clone::Clone> ::core::clone::Clone for Generate<T> { #[inline] fn clone(&self) -> Generate<T> { Generate(::core::clone::Clone::clone(&self.0)) } } ```
2023-08-04document our assumptions about symbols provided by the libcRalf Jung-5/+9
2023-08-03Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obkbors-0/+4
Add `internal_features` lint Implements https://github.com/rust-lang/compiler-team/issues/596 Also requires some more test blessing for codegen tests etc `@jyn514` had the idea of just `allow`ing the lint by default in the test suite. I'm not sure whether this is a good idea, but it's definitely one worth considering. Additional input encouraged.
2023-08-03Rollup merge of #113657 - Urgau:expand-incorrect_fn_null_check-lint, r=cjgillotMatthias Krüger-0/+2
Expand, rename and improve `incorrect_fn_null_checks` lint This PR, - firstly, expand the lint by now linting on references - secondly, it renames the lint `incorrect_fn_null_checks` -> `useless_ptr_null_checks` - and thirdly it improves the lint by catching `ptr::from_mut`, `ptr::from_ref`, as well as `<*mut _>::cast` and `<*const _>::cast_mut` Fixes https://github.com/rust-lang/rust/issues/113601 cc ```@est31```
2023-08-03Add `internal_features` lintNilstrieb-0/+4
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-08-03Implement Option::take_ifMichael Watzko-0/+35
2023-08-03Auto merge of #113220 - tgross35:cstr-bytes-docs, r=workingjubileebors-6/+7
Clarify documentation for `CStr` * Better differentiate summaries for `from_bytes_until_nul` and `from_bytes_with_nul` * Add some links where they may be helpful
2023-08-02Document soundness of Integer -> Pointer -> Integer conversions in ` const` ↵onestacked-1/+4
contexts. see this [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Soundness.20of.20Integer.20-.3E.20Pointer.20-.3E.20Integer.20conversions)
2023-08-02Auto merge of #112431 - Urgau:cast_ref_to_mut_improvments, r=Nilstriebbors-1/+2
Improve `invalid_reference_casting` lint This PR is a follow-up to https://github.com/rust-lang/rust/pull/111567 and https://github.com/rust-lang/rust/pull/113422. This PR does multiple things: - First it adds support for deferred de-reference, the goal is to support code like this, where the casting and de-reference are not done on the same expression ```rust let myself = self as *const Self as *mut Self; *myself = Self::Ready(value); ``` - Second it does not lint anymore on SB/TB UB code by only checking assignments (`=`, `+=`, ...) and creation of mutable references `&mut *` - Thirdly it greatly improves the diagnostics in particular for cast from `&mut` to `&mut` or assignments - ~~And lastly it renames the lint from `cast_ref_to_mut` to `invalid_reference_casting` which is more consistent with the ["rules"](https://github.com/rust-lang/rust-clippy/issues/2845) and also more consistent with what the lint checks~~ *https://github.com/rust-lang/rust/pull/113422* This PR is best reviewed commit by commit. r? compiler
2023-08-02Clarify documentation for `CStr`Trevor Gross-6/+7
* Better differentiate summaries for `from_bytes_until_nul` and `from_bytes_with_nul` * Add some links where they may be helpful
2023-08-01Add diagnostic items for `<*const _>::cast` and `ptr::from_mut`Urgau-0/+2
2023-08-01Auto merge of #112849 - m-ou-se:panic-message-format, r=thomccbors-6/+10
Change default panic handler message format. This changes the default panic hook's message format from: ``` thread '{thread}' panicked at '{message}', {location} ``` to ``` thread '{thread}' panicked at {location}: {message} ``` This puts the message on its own line without surrounding quotes, making it easiser to read. For example: Before: ``` thread 'main' panicked at 'env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`', src/main.rs:4:6 ``` After: ``` thread 'main' panicked at src/main.rs:4:6: env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh` ``` --- See this PR by `@nyurik,` which does that for only multi-line messages (specifically because of `assert_eq`): https://github.com/rust-lang/rust/pull/111071 This is the change that does that for *all* panic messages.
2023-08-01Rollup merge of #111081 - mattfbacon:master, r=workingjubileeMatthias Krüger-4/+56
impl SliceIndex<str> for (Bound<usize>, Bound<usize>) This impl is conspicuously missing.
2023-07-31Rollup merge of #109318 - joboet:better_fmt_placeholder, r=dtolnayMatthias Krüger-18/+10
Make `Debug` representations of `[Lazy, Once]*[Cell, Lock]` consistent with `Mutex` and `RwLock` `Mutex` prints `<locked>` as a field value when its inner value cannot be accessed, but the lazy types print a fixed string like "`OnceCell(Uninit)`". This could cause confusion if the inner type is a unit type named `Uninit` and does not respect the pretty-printing flag. With this change, the format message is now "`OnceCell(<uninit>)`", consistent with `Mutex`.
2023-07-31I'm mathematically challengedltdk-2/+2
2023-07-31Work around missing <*str>::lenMatt Fellenz-4/+4
2023-07-31impl SliceIndex<str> for (Bound<usize>, Bound<usize>)Matt Fellenz-4/+56
2023-07-31Can't compare usize and u32ltdk-2/+2
2023-07-31Use u32::from for MIN/MAX examplesltdk-2/+2
2023-07-31Add note on gap for MIN/MAXltdk-0/+35
2023-07-31Add char::MINltdk-0/+15
2023-07-30Rollup merge of #102198 - lukas-code:nonnull_as_ref, r=AmanieuMatthias Krüger-2/+3
`const`-stablilize `NonNull::as_ref` A bunch of pointer to reference methods have been made unstably const some time ago in #91823 under the feature gate `const_ptr_as_ref`. Out of these, `NonNull::as_ref` can be implemented as a `const fn` in stable rust today, so i hereby propose to const stabilize this function only. Tracking issue: #91822 ``@rustbot`` label +T-libs-api -T-libs
2023-07-30Explain more clearly why `fn() -> T` can't be `#[derive(Clone)]`Martin Nordholts-0/+40
2023-07-30Rollup merge of #112655 - WaffleLapkin:must_use_map_or, r=workingjubileeMatthias Krüger-0/+2
Mark `map_or` as `#[must_use]` I don't know what else to say. r? libs
2023-07-30Mark `map_or` as `#[must_use]`Maybe Waffle-0/+2
2023-07-30Fix implementation of `Duration::checked_div`Jacob Pratt-4/+4
2023-07-30Rollup merge of #113512 - vallentin:lines-doc, r=workingjubileefee1-dead-3/+8
Updated lines doc to include trailing carriage return note Updated `str::lines` doc to include explicit info about (trailing) carriage returns. Reference: #100311
2023-07-29Adjust some tests for invalid_reference_casting improvementsUrgau-1/+2
2023-07-29Change default panic handler message format.Mara Bos-6/+10
2023-07-29Auto merge of #113099 - bvanjoi:fix-112713-2, r=petrochenkovbors-1/+2
fix(resolve): update the ambiguity glob binding as warning recursively Fixes #47525 Fixes #56593, but `issue-56593-2.rs` is not fixed to ensure backward compatibility. Fixes #98467 Fixes #105235 Fixes #112713 This PR had added a field called `warn_ambiguous` in `NameBinding` which is only for back compatibly reason and used for lint. More details: https://github.com/rust-lang/rust/pull/112743 r? `@petrochenkov`
2023-07-29library: allow `ambiguous_glob_reexports` for `core_arch`bohan-1/+2
2023-07-28doc: replace wrong punctuation markTshepang Mbambo-1/+1
2023-07-27Override `Waker::clone_from` to avoid cloning `Waker`s unnecessarilySabrinaJewson-1/+14
2023-07-27Rollup merge of #114109 - veera-sivarajan:fix-str-docs, r=GuillaumeGomezGuillaume Gomez-1/+1
Docs: Fix URL for `rmatches` This PR fixes a link to `str::rmatches()` by pointing it to the correct URL.
2023-07-27Rollup merge of #114091 - waywardmonkeys:doc-fmt-finish-comments, ↵Guillaume Gomez-3/+3
r=GuillaumeGomez docs: fmt::Debug*: Fix comments for finish method. In the code sample for the `finish` method on `DebugList`, `DebugMap`, and `DebugSet`, refer to finishing the list, map, or set, rather than struct as it did.
2023-07-27Auto merge of #114034 - Amanieu:riscv-atomicbool, r=thomccbors-8/+54
Optimize `AtomicBool` for target that don't support byte-sized atomics `AtomicBool` is defined to have the same layout as `bool`, which means that we guarantee that it has a size of 1 byte. However on certain architectures such as RISC-V, LLVM will emulate byte atomics using a masked CAS loop on an aligned word. We can take advantage of the fact that `bool` only ever has a value of 0 or 1 to replace `swap` operations with `and`/`or` operations that LLVM can lower to word-sized atomic `and`/`or` operations. This takes advantage of the fact that the incoming value to a `swap` or `compare_exchange` for `AtomicBool` is often a compile-time constant. ### Example ```rust pub fn swap_true(atomic: &AtomicBool) -> bool { atomic.swap(true, Ordering::Relaxed) } ``` ### Old ```asm andi a1, a0, -4 slli a0, a0, 3 li a2, 255 sllw a2, a2, a0 li a3, 1 sllw a3, a3, a0 slli a3, a3, 32 srli a3, a3, 32 .LBB1_1: lr.w a4, (a1) mv a5, a3 xor a5, a5, a4 and a5, a5, a2 xor a5, a5, a4 sc.w a5, a5, (a1) bnez a5, .LBB1_1 srlw a0, a4, a0 andi a0, a0, 255 snez a0, a0 ret ``` ### New ```asm andi a1, a0, -4 slli a0, a0, 3 li a2, 1 sllw a2, a2, a0 amoor.w a1, a2, (a1) srlw a0, a1, a0 andi a0, a0, 255 snez a0, a0 ret ```
2023-07-26Fix URL for `rmatches`Veera-1/+1
2023-07-26docs: fmt::Debug*: Fix comments for finish method.Bruce Mitchener-3/+3
In the code sample for the `finish` method on `DebugList`, `DebugMap`, and `DebugSet`, refer to finishing the list, map, or set, rather than struct as it did.
2023-07-26Optimize `AtomicBool` for target that don't support byte-sized atomicsAmanieu d'Antras-8/+54
`AtomicBool` is defined to have the same layout as `bool`, which means that we guarantee that it has a size of 1 byte. However on certain architectures such as RISC-V, LLVM will emulate byte atomics using a masked CAS loop on an aligned word. We can take advantage of the fact that `bool` only ever has a value of 0 or 1 to replace `swap` operations with `and`/`or` operations that LLVM can lower to word-sized atomic `and`/`or` operations. This takes advantage of the fact that the incoming value to a `swap` or `compare_exchange` for `AtomicBool` is often a compile-time constant.
2023-07-25`impl TryFrom<char> for u16`Lukas Markeffsky-2/+36
2023-07-25core library: Disable fpmath tests for i386 ...liushuyu-1/+1
This patch disables the floating-point epsilon test for i386 since x87 registers are too imprecise and can't produce the expected results.
2023-07-24Auto merge of #111362 - mj10021:issue-74838-update, r=cuviperbors-1/+1
delete [allow(unused_unsafe)] from issue #74838 While looking into issue #111288 I noticed the following `#[allow(...)]` with a `FIXME` asking for it to be removed. Deleting the `#[allow(...)]` does not seem to break anything, it seems like the lint has been updated for unsafe blocks in macros?
2023-07-24remove additional [allow(unused_unsafe)]James Dietz-1/+1
2023-07-22Add #[inline] to core debug assertion helpersBen Kimock-0/+3