about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
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/+5
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-29Auto merge of #114197 - matthiaskrgr:rollup-iluf7u4, r=matthiaskrgrbors-1/+1
Rollup of 7 pull requests Successful merges: - #113773 (Don't attempt to compute layout of type referencing error) - #114107 (Prevent people from assigning me as a PR reviewer) - #114124 (tests/ui/proc-macro/*: Migrate FIXMEs to check-pass) - #114171 (Fix switch-stdout test for none unix/windows platforms) - #114172 (Fix issue_15149 test for the SGX target) - #114173 (btree/map.rs: remove "Basic usage" text) - #114174 (doc: replace wrong punctuation mark) r? `@ghost` `@rustbot` modify labels: rollup
2023-07-29Auto merge of #111916 - fee1-dead-contrib:noop-method-call-warn, ↵bors-0/+1
r=compiler-errors make `noop_method_call` warn by default r? `@compiler-errors`
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-23fixDeadbeef-0/+1
2023-07-22Add #[inline] to core debug assertion helpersBen Kimock-0/+3
2023-07-22Auto merge of #113746 - clarfonthey:ip_bits, r=thomccbors-52/+119
Add BITS, from_bits, to_bits to IP addresses ACP: rust-lang/libs-team#235 Tracking issue: #113744
2023-07-22Rollup merge of #113898 - ajtribick:encode_utf16_size_hint, r=cuviperMatthias Krüger-5/+16
Fix size_hint for EncodeUtf16 More realistic upper and lower bounds, and handle the case where the iterator is located within a surrogate pair. Resolves #113897
2023-07-22Rollup merge of #113252 - tgross35:const-cstr-from-ptr-tracking-issue, ↵Matthias Krüger-1/+1
r=ChrisDenton Update the tracking issue for `const_cstr_from_ptr` Tracking issue #101719 was for `const_cstr_methods`, #113219 is a new issue specific for `const_cstr_from_ptr`. (I believe #101719 could also be closed) ```@rustbot``` label +T-libs-api +A-docs
2023-07-22Rollup merge of #112490 - Alexendoo:c-char-cfg-all, r=cuviperMatthias Krüger-5/+0
Remove `#[cfg(all())]` workarounds from `c_char` Casts to type aliases are now ignored by Clippy https://github.com/rust-lang/rust-clippy/pull/8596 Closes https://github.com/rust-lang/rust-clippy/issues/8093
2023-07-21Auto merge of #112699 - bluebear94:mf/more-is-sorted-tests, r=cuviperbors-1/+58
Add more comprehensive tests for is_sorted and friends See #53485 and #55045.
2023-07-21Clarify logic on bytes:code units ratioAndrew Tribick-2/+4