about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2020-01-20Rollup merge of #68335 - RalfJung:drop-in-place, r=Mark-SimulacrumDylan DPC-12/+2
Remove real_drop_in_place In https://github.com/rust-lang/rust/commit/af9b057156f610df3528a502c668cfed99ce8a1a, I added `real_drop_in_place` because Stacked Borrows at the time couldn't handle transmuting of mutable references to raw pointers and back. Stacked Borrows 2, however, doesn't have any issue with these transmutes, so it is time to remove this hack again.
2020-01-19Rollup merge of #68348 - xfix:patch-14, r=nagisaDylan DPC-0/+5
Make iter::Empty<T> Send and Sync for any T Continuing from #57682 It's quite funny, when I initially submitted this pull request, I said "Likely nobody will be using that property of `iter::empty`", but then a year later I got a compilation error because it wasn't `Send` and `Sync`. Unfortunately, `PhantomData<fn() -> T>` still errors out. Oh well. I proposed ` struct PhantomFnWorkaround<T>(fn() -> T);`, but dtolnay did not like it, so using explicit implementations.
2020-01-18Rollup merge of #68342 - lcnr:type_name_docs, r=Dylan-DPCMazdak Farrokhzad-1/+5
improve type_name_of_val docs suggested by @Globidev in https://github.com/rust-lang/rust/issues/66359#issuecomment-575016612
2020-01-18slice_patterns: remove internal uses of gateMazdak Farrokhzad-2/+2
2020-01-18Make iter::Empty<T> implement Send and Sync for any TKonrad Borowski-0/+5
2020-01-18improve type_name_of_val docslcnr/Bastian Kauschke-1/+5
2020-01-18get rid of real_drop_in_place againRalf Jung-12/+2
2020-01-17Rollup merge of #66564 - foeb:66219-document-unsafe-sync-cell-str, r=AmanieuDylan DPC-35/+112
Document unsafe blocks in core::{cell, str, sync} Split from #66506 (issue #66219). Hopefully doing a chunk at a time is more manageable! r? @RalfJung
2020-01-16Add SAFETY comment for atomic examplePhoebe Bell-1/+3
2020-01-16Fix formatting: ./x.py fmtPhoebe Bell-15/+5
2020-01-16Move comments for tidyPhoebe Bell-5/+5
2020-01-16Elaborate on SAFETY commentsPhoebe Bell-77/+88
2020-01-16Apply suggestions from code reviewPhoebe Bell-1/+1
Co-Authored-By: Ralf Jung <post@ralfj.de>
2020-01-16Fix typo "gurantees -> guarantees"Phoebe Bell-1/+1
2020-01-16Document unsafe blocks in core::{cell, str, sync}Phoebe Bell-17/+91
2020-01-17Auto merge of #66716 - derekdreery:debug_non_exhaustive, r=dtolnaybors-0/+142
Implement `DebugStruct::non_exhaustive`. This patch adds a function (finish_non_exhaustive) to add ellipsis before the closing brace when formatting using `DebugStruct`. ## Example ```rust #![feature(debug_non_exhaustive)] use std::fmt; struct Bar { bar: i32, hidden: f32, } impl fmt::Debug for Bar { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("Bar") .field("bar", &self.bar) .non_exhaustive(true) // Show that some other field(s) exist. .finish() } } assert_eq!( format!("{:?}", Bar { bar: 10, hidden: 1.0 }), "Bar { bar: 10, .. }", ); ```
2020-01-16Rust ./x.py fmtRichard Dodd-12/+14
2020-01-16Rollup merge of #68096 - varkor:diagnostic-cleanup, r=CentrilDylan DPC-1/+1
Clean up some diagnostics by making them more consistent In general: - Diagnostic should start with a lowercase letter. - Diagnostics should not end with a full stop. - Ellipses contain three dots. - Backticks should encode Rust code. I also reworded a couple of messages to make them read more clearly. It might be sensible to create a style guide for diagnostics, so these informal conventions are written down somewhere, after which we could audit the existing diagnostics. r? @Centril
2020-01-15Fix incorrect slice->ptr conversion in slice_from_raw_parts docsCAD97-1/+1
2020-01-15Rollup merge of #68232 - Mark-Simulacrum:unicode-tables, r=joshtriplettDylan DPC-3194/+2402
Optimize size/speed of Unicode datasets The overall implementation has the same general idea as the prior approach, which was based on a compressed trie structure, but modified to use less space (and, coincidentally, be an overall performance improvement). Sizes | Old | New | New/current -- | -- | -- | -- Alphabetic | 4616 | 2982 | 64.60% Case_Ignorable | 3144 | 2112 | 67.18% Cased | 2376 | 934 | 39.31% Cc | 19 | 43 | 226.32% Grapheme_Extend | 3072 | 1734 | 56.45% Lowercase | 2328 | 985 | 42.31% N | 2648 | 1239 | 46.79% Uppercase | 1978 | 934 | 47.22% White_Space | 241 | 140 | 58.09% | | | Total | 20422 | 11103 | 54.37% This table shows the size of the old and new tables in bytes. The most important of these tables is "Grapheme_Extend", as it is present in essentially all Rust programs due to being called from `str`'s Debug impl (`char::escape_debug`). In a representative case given by this [blog post] for the embedded world, the shrinking in this PR shrinks the final binary by 1,604 bytes, from 14,440 to 12,836. The performance of these new tables, based on the (rough) benchmark of linearly scanning the entire valid set of chars, querying for each `is_*`, is roughly ~50% better, though in some cases is either on par or slightly (3-5%) worse. In practice, I believe the size benefits of this PR are the main concern. The new implementation has been tested to be equivalent to the current nightly in terms of returned values on the set of valid chars. A (relatively) high-level explanation of the specific compression scheme used can be found [in the generator]. This is split into three commits -- the first adds the generator which produces the Rust code for the tables, the second adds support code for the lookup, and the third actually swaps the current implementation out for the new one. [blog post]: https://jamesmunns.com/blog/fmt-unreasonably-expensive/ [in the generator]: https://github.com/Mark-Simulacrum/rust/blob/unicode-tables/src/tools/unicode-table-generator/src/raw_emitter.rs
2020-01-15Mark leading_trailing_ones with tracking issue 57969Thom Chiovoloni-4/+4
2020-01-15Rollup merge of #67784 - Mark-Simulacrum:residual-pad-integral, r=dtolnayYuki Okushi-3/+21
Reset Formatter flags on exit from pad_integral This fixes a bug where after calling pad_integral with appropriate flags, the fill and alignment flags would be set to '0' and 'Right' and left as such even after exiting pad_integral, which meant that future calls on the same Formatter would get incorrect flags reported. This is quite difficult to observe in practice, as almost all formatting implementations in practice don't call `Display::fmt` directly, but rather use `write!` or a similar macro, which means that they cannot observe the effects of the wrong flags (as `write!` creates a fresh Formatter instance). However, we include a test case. A manual check leads me to believe this is the only case where we failed to reset the flags appropriately, but I could have missed something.
2020-01-14Stabilize ptr::slice_from_raw_parts[_mut]CAD97-7/+5
2020-01-14Replace old tables with new unicode dataMark Rousskov-3189/+2353
2020-01-14Add support code for new unicode_data moduleMark Rousskov-5/+49
2020-01-14Implement `finish_non_exhaustive` for `DebugStruct`.Richard Dodd-0/+140
2020-01-12Tests for leading_trailing_onesThom Chiovoloni-0/+55
2020-01-12Add {leading,trailing}_ones to primitive int typesThom Chiovoloni-0/+83
2020-01-12Diagnostics should not end with a full stopvarkor-1/+1
2020-01-11Constify alloc::LayoutLukas Lueg-4/+9
Tracking issue #67521, Layout::new in #66254
2020-01-11Rollup merge of #68114 - ecstatic-morse:fix-feature-gating, r=CentrilMazdak Farrokhzad-2/+0
Don't require `allow_internal_unstable` unless `staged_api` is enabled. #63770 changed `qualify_min_const_fn` to require `allow_internal_unstable` for *all* crates that used an unstable feature, regardless of whether `staged_api` was enabled or the `fn` that used that feature was stably const. In practice, this meant that every crate in the ecosystem that wanted to use nightly features added `#![feature(const_fn)]`, which skips `qualify_min_const_fn` entirely. After this PR, crates that do not have `#![feature(staged_api)]` will only need to enable the feature they are interested in. For example, `#![feature(const_if_match)]` will be enough to enable `if` and `match` in constants. Crates with `staged_api` (e.g., `libstd`) require `#[allow_internal_unstable]` to be added to a function if it uses nightly features unless that function is also marked `#[rustc_const_unstable]`. This prevents proliferation of `#[allow_internal_unstable]` into functions that are not callable in a `const` context on stable. r? @oli-obk (author of #63770) cc @Centril
2020-01-11Update test after renaming Result::as_derefLzu Tao-58/+27
2020-01-11Rename Result::as_deref_ok to as_derefLzu Tao-25/+2
2020-01-10Remove unnecessary `const_fn` feature gatesDylan MacKenzie-2/+0
This flag opts out of the min-const-fn checks entirely, which is usually not what we want. The few cases where the flag is still necessary have been annotated.
2020-01-11Rollup merge of #66045 - mzabaluev:unwrap-infallible, r=dtolnayYuki Okushi-0/+62
Add method Result::into_ok Implementation of https://github.com/rust-lang/rfcs/pull/2799 Tracking issue #61695
2020-01-10Rollup merge of #68054 - tspiteri:null-unchecked-as_mut, r=cramertjYuki Okushi-0/+14
doc: add Null-unchecked version section to mut pointer as_mut method The [`as_ref`](https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref-1) method already has a *Null-unchecked version* section, its example is a modification of the example in the main `as_ref` section. Similarly the example in this PR is a modification of the example in main [`as_mut`](https://doc.rust-lang.org/std/primitive.pointer.html#method.as_mut) section. Fixes #68032.
2020-01-10Rollup merge of #67935 - Thomasdezeeuw:issue_67669, r=withoutboatsYuki Okushi-0/+2
Relax the Sized bounds on Pin::map_unchecked(_mut) Fixes #67669.
2020-01-09Mark Layout::new as const stableCAD97-0/+1
2020-01-09Make Layout::new constChristopher Durham-3/+2
2020-01-09stabalize ManuallyDrop::takeCAD97-7/+8
2020-01-09doc: add Null-unchecked version section to mut pointer as_mut methodTrevor Spiteri-0/+14
The as_ref method already has a Null-unchecked version section, its example is a modification of the example in the main as_ref section. Similarly the example in this commit is a modification of the example in main as_mut section.
2020-01-09Rollup merge of #67966 - popzxc:core-std-matches, r=CentrilMazdak Farrokhzad-84/+21
Use matches macro in libcore and libstd This PR replaces matches like ```rust match var { value => true, _ => false, } ``` with use of `matches!` macro. r? @Centril
2020-01-09Rollup merge of #67884 - anp:allow-unused-const-attr, r=oli-obkMazdak Farrokhzad-0/+3
Fix incremental builds of core by allowing unused attribute. I *think* that the same problem as in https://github.com/rust-lang/rust/issues/65023 was introduced by https://github.com/rust-lang/rust/pull/67657. This works around the current incrcomp issue with these attributes by allowing it here. This resolves the near-term issue for me, at least.
2020-01-09Rollup merge of #67887 - anp:tracked-std-panics, r=nagisaYuki Okushi-0/+11
`Option::{expect,unwrap}` and `Result::{expect, expect_err, unwrap, unwrap_err}` have `#[track_caller]` The annotated functions now produce panic messages pointing to the location where they were called, rather than `core`'s internals.
2020-01-09Rollup merge of #67798 - matklad:spin-thouse-docs, r=AmanieuYuki Okushi-10/+4
Remove wrong advice about spin locks from `spin_loop_hint` docs Using a pure spin lock for a critical section in a preemptable thread is always wrong, however short the critical section may be. The thread might be preempted, which will cause all other threads to hammer busily at the core for the whole quant. Moreover, if threads have different priorities, this might lead to a priority inversion problem and a deadlock. More generally, a spinlock is not more efficient than a well-written mutex, which typically does several spin iterations at the start anyway. The advise about UP vs SMP is also irrelevant in the context of preemptive threads. See also accompanying piece: https://matklad.github.io/2020/01/02/spinlocs-considered-harmful.html And another, independent piece: https://probablydance.com/2019/12/30/measuring-mutexes-spinlocks-and-how-bad-the-linux-scheduler-really-is EDIT: obligatory disclosure that I am not an expert in these things, and might be terribly wrong :)
2020-01-08Use matches macro in libcore and libstdIgor Aleksanov-84/+21
2020-01-06Relax the Sized bounds on Pin::map_unchecked(_mut)Thomas de Zeeuw-0/+2
2020-01-06Rollup merge of #67915 - lzutao:Self, r=CentrilDylan DPC-30/+30
Use Self instead of $type r? @Dylan-DPC
2020-01-06Use Self instead of $typeLzu Tao-30/+30
2020-01-06macros: typo fixLucas Pardue-1/+1
spotted while reviewing the todo!macro docs