summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2022-02-11Take in account the unreachable! macro in the non_fmt_panic lintLoïc BRANSTETT-1/+2
2022-02-11Fix invalid special casing of the unreachable! macroLoïc BRANSTETT-0/+57
2022-02-09Rollup merge of #92611 - Amanieu:asm-reference, r=m-ou-seMatthias Krüger-0/+12
Add links to the reference and rust by example for asm! docs and lints These were previously removed in #91728 due to broken links. cc ``@ehuss`` since this updates the rust-by-example submodule
2022-01-07Rollup merge of #92600 - asquared31415:float-must-use, r=joshtriplettEric Huss-0/+10
Add some missing `#[must_use]` to some `f{32,64}` operations This PR adds `#[must_use]` to the following methods: - `f32::recip` - `f32::max` - `f32::min` - `f32::maximum` - `f32::minimum` and their equivalents in `f64`. These methods all produce a new value without modifying the original and so are pointless to call without using the result.
2022-01-07Rollup merge of #92568 - Mark-Simulacrum:non-exhaustive-variant-count, r=the8472Eric Huss-0/+4
Add note about non_exhaustive to variant_count Since `variant_count` isn't returning something opaque, I thought it makes sense to explicitly call out that its return value may change for some enums. cc #73662
2022-01-07Implement `TryFrom<char>` for `u8`Ian Douglas Scott-0/+27
Previously suggested in https://github.com/rust-lang/rfcs/issues/2854. It makes sense to have this since `char` implements `From<u8>`. Likewise `u32`, `u64`, and `u128` (since #79502) implement `From<char>`.
2022-01-06add some missing must use to float opsasquared31415-0/+10
2022-01-05Auto merge of #92587 - matthiaskrgr:rollup-qnwa8qx, r=matthiaskrgrbors-22/+32
Rollup of 7 pull requests Successful merges: - #92092 (Drop guards in slice sorting derive src pointers from &mut T, which is invalidated by interior mutation in comparison) - #92388 (Fix a minor mistake in `String::try_reserve_exact` examples) - #92442 (Add negative `impl` for `Ord`, `PartialOrd` on `LocalDefId`) - #92483 (Stabilize `result_cloned` and `result_copied`) - #92574 (Add RISC-V detection macro and more architecture instructions) - #92575 (ast: Always keep a `NodeId` in `ast::Crate`) - #92583 (:arrow_up: rust-analyzer) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-05Rollup merge of #92574 - luojia65:riscv-kernel-dev-rust, r=AmanieuMatthias Krüger-5/+15
Add RISC-V detection macro and more architecture instructions This pull request includes: - Update `stdarch` dependency to include ratified RISC-V supervisor and hypervisor instruction intrinsics which is useful in Rust kernel development - Add macro `is_riscv_feature_detected!` - Modify impl of `core::hint::spin_loop` to comply with latest version of `core::arch` After this update, users may now develop RISC-V kernels and user applications more freely. r? `@Amanieu`
2022-01-05Rollup merge of #92483 - ksqsf:master, r=dtolnayMatthias Krüger-8/+8
Stabilize `result_cloned` and `result_copied` Tracking issue: #63168 The FCP is now completed.
2022-01-05Rollup merge of #92092 - saethlin:fix-sort-guards-sb, r=danielhenrymantillaMatthias Krüger-9/+9
Drop guards in slice sorting derive src pointers from &mut T, which is invalidated by interior mutation in comparison I tried to run https://github.com/rust-lang/miri-test-libstd on `alloc` with `-Zmiri-track-raw-pointers`, and got a failure on the test `slice::panic_safe`. The test failure has nothing to do with panic safety, it's from how the test tests for panic safety. I minimized the test failure into this very silly program: ```rust use std::cell::Cell; use std::cmp::Ordering; #[derive(Clone)] struct Evil(Cell<usize>); fn main() { let mut input = vec![Evil(Cell::new(0)); 3]; // Hits the bug pattern via CopyOnDrop in core input.sort_unstable_by(|a, _b| { a.0.set(0); Ordering::Less }); // Hits the bug pattern via InsertionHole in alloc input.sort_by(|_a, b| { b.0.set(0); Ordering::Less }); } ``` To fix this, I'm just removing the mutability/uniqueness where it wasn't required.
2022-01-05Rollup merge of #92322 - alper:add_debug_trait_documentation, r=dtolnayMatthias Krüger-2/+21
Add another implementation example to Debug trait As per the discussion in: #92276
2022-01-05Add is_riscv_feature_detected!; modify impl of hint::spin_loopluojia65-5/+15
Update library/core/src/hint.rs Co-authored-by: Amanieu d'Antras <amanieu@gmail.com> Remove redundant config gate
2022-01-04Add note about non_exhaustive to variant_countMark Rousskov-0/+4
2022-01-04Auto merge of #92560 - matthiaskrgr:rollup-jeli7ip, r=matthiaskrgrbors-89/+124
Rollup of 7 pull requests Successful merges: - #91587 (core::ops::unsize: improve docs for DispatchFromDyn) - #91907 (Allow `_` as the length of array types and repeat expressions) - #92515 (RustWrapper: adapt for an LLVM API change) - #92516 (Do not use deprecated -Zsymbol-mangling-version in bootstrap) - #92530 (Move `contains` method of Option and Result lower in docs) - #92546 (Update books) - #92551 (rename StackPopClean::None to Root) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-04Touch up Debug example from PR 92322David Tolnay-3/+7
2022-01-04Rollup merge of #92530 - dtolnay:contains, r=yaahcMatthias Krüger-88/+92
Move `contains` method of Option and Result lower in docs Follow-up to #92444 trying to get the `Option` and `Result` rustdocs in better shape. This addresses the request in https://github.com/rust-lang/rust/issues/62358#issuecomment-645676285. The `contains` methods are previously too high up in the docs on both `Option` and `Result` &mdash; stuff like `ok` and `map` and `and_then` should all be featured higher than `contains`. All of those are more ubiquitously useful than `contains`.
2022-01-04Rollup merge of #91587 - nrc:dispatchfromdyn-docs, r=yaahcMatthias Krüger-1/+32
core::ops::unsize: improve docs for DispatchFromDyn Docs-only PR, improves documentation for DispatchFromDyn.
2022-01-04Stabilize `result_cloned` and `result_copied`ksqsf-8/+8
2022-01-03Make the documentation of builtin macro attributes accessibleDaniel Henry-Mantilla-11/+17
- Do not `#[doc(hidden)]` the `#[derive]` macro attribute - Add a link to the reference section to `derive`'s inherent docs - Do the same for `#[test]` and `#[global_allocator]` - Fix `GlobalAlloc` link (why is it on `core` and not `alloc`?) - Try `no_inline`-ing the `std` reexports from `core` - Revert "Try `no_inline`-ing the `std` reexports from `core`" - Address PR review - Also document the unstable macros
2022-01-03Move `contains` method of Option and Result lower in docsDavid Tolnay-88/+92
2022-01-03Rollup merge of #92444 - dtolnay:coremethods, r=joshtriplettMatthias Krüger-428/+449
Consolidate Result's and Option's methods into fewer impl blocks `Result`'s and `Option`'s methods have historically been separated up into `impl` blocks based on their trait bounds, with the bounds specified on type parameters of the impl block. I find this unhelpful because closely related methods, like `unwrap_or` and `unwrap_or_default`, end up disproportionately far apart in source code and rustdocs: <pre> impl&lt;T&gt; Option&lt;T&gt; { pub fn unwrap_or(self, default: T) -&gt; T { ... } <img alt="one eternity later" src="https://user-images.githubusercontent.com/1940490/147780325-ad4e01a4-c971-436e-bdf4-e755f2d35f15.jpg" width="750"> } impl&lt;T: Default&gt; Option&lt;T&gt; { pub fn unwrap_or_default(self) -&gt; T { ... } } </pre> I'd prefer for method to be in as few impl blocks as possible, with the most logical grouping within each impl block. Any bounds needed can be written as `where` clauses on the method instead: ```rust impl<T> Option<T> { pub fn unwrap_or(self, default: T) -> T { ... } pub fn unwrap_or_default(self) -> T where T: Default, { ... } } ``` *Warning: the end-to-end diff of this PR is computed confusingly by git / rendered confusingly by GitHub; it's practically impossible to review that way. I've broken the PR into commits that move small groups of methods for which git behaves better &mdash; these each should be easily individually reviewable.*
2022-01-02Auto merge of #91961 - kornelski:track_split_caller, r=joshtriplettbors-0/+5
Track caller of slice split and swap Improves error location for `slice.split_at*()` and `slice.swap()`. These are generic inline functions, so the `#[track_caller]` on them is free — only changes a value of an argument already passed to panicking code.
2021-12-30Consolidate impl Option<&mut T>David Tolnay-4/+5
2021-12-30Consolidate impl Option<&T>David Tolnay-28/+29
2021-12-30Move Option::as_deref_mutDavid Tolnay-28/+26
2021-12-30Move Option::as_derefDavid Tolnay-28/+26
2021-12-30Move Option::unwrap_or_defaultDavid Tolnay-41/+39
2021-12-30Consolidate impl Result<&mut T, E>David Tolnay-5/+9
2021-12-30Consolidate impl Result<&T, E>David Tolnay-22/+26
2021-12-30Move Result::into_errDavid Tolnay-36/+37
2021-12-30Move Result::into_okDavid Tolnay-36/+37
2021-12-30Move Result::expect_err and Result::unwrap_errDavid Tolnay-56/+60
2021-12-30Move Result::unwrap_or_defaultDavid Tolnay-36/+37
2021-12-30Move Result::expect and Result::unwrapDavid Tolnay-68/+76
2021-12-30Move Result::as_deref_mutDavid Tolnay-25/+26
2021-12-30Move Result::as_derefDavid Tolnay-23/+24
2021-12-30Use `UnsafeCell::get_mut()` in `core::lazy::OnceCell::get_mut()`Chayim Refael Friedman-2/+1
This removes one unnecessary `unsafe` block.
2021-12-29Auto merge of #92291 - AngelicosPhosphoros:typeid_inline_revert_92135, ↵bors-1/+0
r=joshtriplett Reverts #92135 because perf regression Please, start a perf test for this. r? `@joshtriplett` You approved original PR.
2021-12-28Rollup merge of #92335 - ecstatic-morse:std-column-unicode, r=ManishearthMatthias Krüger-0/+12
Document units for `std::column` Fixes #92301. r? ``@Manishearth`` (for the terminology and the Chinese)
2021-12-27Document units for `std::column`Dylan MacKenzie-0/+12
2021-12-27Add another implementation example to Debug traitAlper Çugun-2/+17
2021-12-26Reverts #92135 because perf regressionAngelicosPhosphoros-1/+0
2021-12-24Auto merge of #92135 - AngelicosPhosphoros:typeid_inline_74362, r=dtolnaybors-0/+1
Add `#[inline]` modifier to `TypeId::of` It was already inlined but it happened only in 4th InlinerPass on my testcase. With `#[inline]` modifier it happens on 2nd pass. Closes #74362
2021-12-23Constify `core::intrinsics::black_box`woppopo-1/+4
2021-12-23Auto merge of #92155 - m-ou-se:panic-fn, r=eddybbors-5/+11
Use panic() instead of panic!() in some places in core. See https://github.com/rust-lang/rust/pull/92068 and https://github.com/rust-lang/rust/pull/92140. This avoids the `panic!()` macro in a few potentially hot paths. This becomes more relevant when switching `core` to Rust 2021, as it'll avoid format_args!() and save some compilation time. (It doesn't make a huge difference, but still.) (Also the errors in const panic become slightly nicer.)
2021-12-23Rollup merge of #88858 - spektom:to_lower_upper_rev, r=dtolnayMatthias Krüger-0/+34
Allow reverse iteration of lowercase'd/uppercase'd chars The PR implements `DoubleEndedIterator` trait for `ToLowercase` and `ToUppercase`. This enables reverse iteration of lowercase/uppercase variants of character sequences. One of use cases: determining whether a char sequence is a suffix of another one. Example: ```rust fn endswith_ignore_case(s1: &str, s2: &str) -> bool { for eob in s1 .chars() .flat_map(|c| c.to_lowercase()) .rev() .zip_longest(s2.chars().flat_map(|c| c.to_lowercase()).rev()) { match eob { EitherOrBoth::Both(c1, c2) => { if c1 != c2 { return false; } } EitherOrBoth::Left(_) => return true, EitherOrBoth::Right(_) => return false, } } true } ```
2021-12-22Update stability attribute for double ended case mapping iteratorsDavid Tolnay-2/+2
2021-12-21Use panic() instead of panic!() in some places in core.Mara Bos-5/+11
2021-12-21Rollup merge of #91823 - woppopo:const_ptr_as_ref, r=lcnrMatthias Krüger-15/+30
Make `PTR::as_ref` and similar methods `const`. Tracking issue: #91822 Feature gate: `#![feature(const_ptr_as_ref)]` ```rust // core::ptr impl<T: ?Sized> *const T { pub const unsafe fn as_ref<'a>(self) -> Option<&'a T>; pub const unsafe fn as_uninit_ref<'a>(self) -> Option<&'a MaybeUninit<T>> where T: Sized; pub const unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]>; } impl<T: ?Sized> *mut T { pub const unsafe fn as_ref<'a>(self) -> Option<&'a T>; pub const unsafe fn as_uninit_ref<'a>(self) -> Option<&'a MaybeUninit<T>> where T: Sized; pub const unsafe fn as_mut<'a>(self) -> Option<&'a mut T>; pub const unsafe fn as_uninit_mut<'a>(self) -> Option<&'a mut MaybeUninit<T>> where T: Sized; pub const unsafe fn as_uninit_slice<'a>(self) -> Option<&'a [MaybeUninit<T>]>; pub const unsafe fn as_uninit_slice_mut<'a>(self) -> Option<&'a mut [MaybeUninit<T>]>; } impl<T: Sized> NonNull<T> { pub const unsafe fn as_uninit_ref<'a>(&self) -> &'a MaybeUninit<T>; pub const unsafe fn as_uninit_mut<'a>(&mut self) -> &'a mut MaybeUninit<T>; } impl<T: ?Sized> NonNull<T> { pub const unsafe fn as_ref<'a>(&self) -> &'a T; pub const unsafe fn as_mut<'a>(&mut self) -> &'a mut T; pub const unsafe fn as_uninit_slice<'a>(&self) -> &'a [MaybeUninit<T>]; pub const unsafe fn as_uninit_slice_mut<'a>(&self) -> &'a mut [MaybeUninit<T>]; } ```