about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2019-09-02Auto merge of #63692 - iluuu1994:issue-49660, r=sfacklerbors-0/+8
Test that Wrapping arithmetic ops are implemented for all int types Closes #49660
2019-08-31Fix word repetition in str documentationJulian Gehring-4/+4
Fixes a few repetitions of "like like" in the `trim*` methods documentation of `str`.
2019-08-30Rollup merge of #63999 - GuillaumeGomez:as-ref-missing-links, r=Mark-SimulacrumMazdak Farrokhzad-11/+13
Add missing links on AsRef trait cc @rust-lang/docs
2019-08-30Rev::rposition counts from the wrong endXiang Fan-7/+6
Because of a compiler bug that adding `Self: ExactSizeIterator` makes the compiler forget `Self::Item` is `<I as Iterator>::Item`, we remove this specialization for now.
2019-08-30Add missing examples for Option typeGuillaume Gomez-0/+31
2019-08-30Add a "diagnostic item" schemeOliver Scherer-1/+2
This allows lints and other diagnostics to refer to items by a unique ID instead of relying on whacky path resolution schemes that may break when items are relocated.
2019-08-29Add missing links on AsRef traitGuillaume Gomez-11/+13
2019-08-29Rollup merge of #63992 - lzutao:integer-ord, r=nagisaMazdak Farrokhzad-2/+2
Small improvement for Ord implementation of integers Godbolt link: https://godbolt.org/z/tuTDOg ### Before **asm** ```asm example::cmp: mov eax, dword ptr [rdi] xor ecx, ecx cmp eax, dword ptr [rsi] seta cl mov eax, 255 cmovae eax, ecx ret ``` **llvm-mca** ``` Iterations: 100 Instructions: 700 Total Cycles: 217 Total uOps: 1100 Dispatch Width: 6 uOps Per Cycle: 5.07 IPC: 3.23 Block RThroughput: 1.8 ``` ### After **asm** ```asm example::cmp: mov eax, dword ptr [rdi] xor ecx, ecx cmp eax, dword ptr [rsi] setne cl mov eax, 255 cmovae eax, ecx ret ``` **llvm-mca** ``` Iterations: 100 Instructions: 700 Total Cycles: 209 Total uOps: 1000 Dispatch Width: 6 uOps Per Cycle: 4.78 IPC: 3.35 Block RThroughput: 1.7 ``` r? @nagisa
2019-08-29Small improvement for Ord implementation of integersLzu Tao-2/+2
2019-08-28Stabilize pin_into_inner in 1.39.0Alessandro Ghedini-2/+2
FCP: https://github.com/rust-lang/rust/issues/60245#issuecomment-522258129 Closes #60245
2019-08-28add missing `#[repr(C)]` on a unionDodo-0/+1
2019-08-26Rollup merge of #63845 - DevQps:47091-remove-bad-example, r=nikomatsakisMazdak Farrokhzad-8/+0
Removed a confusing FnOnce example # Description See #47091 for a discussion. ## Changes - Removed an example that might suggest readers that square_x is (only) FnOnce. closes #47091
2019-08-26Auto merge of #62891 - vext01:improve-black-box-docs, r=RalfJung,Centril,gnzlbgbors-4/+12
Improve the documentation for std::hint::black_box. The other day a colleague was reviewing some of my code which was using `black_box` to block constant propogation. There was a little confusion because the documentation kind of implies that `black_box` is only useful for dead code elimination, and only in benchmarking scenarios. The docs currently say: > A function that is opaque to the optimizer, to allow benchmarks to pretend to use outputs to assist in avoiding dead-code elimination. Here is our discussion, in which I show (using godbolt) that a black box can also block constant propagation: https://github.com/softdevteam/yk/pull/21#discussion_r302985038 This change makes the docstring for `black_box` a little more general, and while we are here, I've added an example (the same one from our discussion). ![image](https://user-images.githubusercontent.com/604955/61701322-ddf1e400-ad35-11e9-878c-b5b44a20770c.png) OK to go in?
2019-08-24Improve the documentation for std::hint::black_box.Edd Barrett-4/+12
2019-08-24Auto merge of #63823 - petrochenkov:noapply2, r=matthewjasperbors-8/+0
Audit uses of `apply_mark` in built-in macros + Remove default macro transparencies Every use of `apply_mark` in a built-in or procedural macro is supposed to look like this ```rust location.with_ctxt(SyntaxContext::root().apply_mark(ecx.current_expansion.id)) ``` where `SyntaxContext::root()` means that the built-in/procedural macro is defined directly, rather than expanded from some other macro. However, few people understood what `apply_mark` does, so we had a lot of copy-pasted uses of it looking e.g. like ```rust span = span.apply_mark(ecx.current_expansion.id); ``` , which doesn't really make sense for procedural macros, but at the same time is not too harmful, if the macros use the traditional `macro_rules` hygiene. So, to fight this, we stop using `apply_mark` directly in built-in macro implementations, and follow the example of regular proc macros instead and use analogues of `Span::def_site()` and `Span::call_site()`, which are much more intuitive and less error-prone. - `ecx.with_def_site_ctxt(span)` takes the `span`'s location and combines it with a def-site context. - `ecx.with_call_site_ctxt(span)` takes the `span`'s location and combines it with a call-site context. Even if called multiple times (which sometimes happens due to some historical messiness of the built-in macro code) these functions will produce the same result, unlike `apply_mark` which will grow the mark chain further in this case. --- After `apply_mark`s in built-in macros are eliminated, the remaining `apply_mark`s are very few in number, so we can start passing the previously implicit `Transparency` argument to them explicitly, thus eliminating the need in `default_transparency` fields in hygiene structures and `#[rustc_macro_transparency]` annotations on built-in macros. So, the task of making built-in macros opaque can now be formulated as "eliminate `with_legacy_ctxt` in favor of `with_def_site_ctxt`" rather than "replace `#[rustc_macro_transparency = "semitransparent"]` with `#[rustc_macro_transparency = "opaque"]`". r? @matthewjasper
2019-08-24Added an extra line to make the formatting conform to the rest of the document.Christian-0/+1
2019-08-24Removed the confusing FnOnce example. closes #47091Christian-9/+0
2019-08-23Auto merge of #63808 - Rosto75:master, r=KodrAusbors-2/+2
A bunch of minor documentation tweaks and fixes.
2019-08-23Remove default macro transparenciesVadim Petrochenkov-8/+0
All transparancies are passed explicitly now. Also remove `#[rustc_macro_transparency]` annotations from built-in macros, they are no longer used. `#[rustc_macro_transparency]` only makes sense for declarative macros now.
2019-08-22Rollup merge of #63805 - mati865:clippy, r=CentrilMazdak Farrokhzad-4/+3
Apply few Clippy suggestions Somewhat follow-up of https://github.com/rust-lang/rust/pull/62806 Changes per commit are rather small so I can squash them if that's preferred.
2019-08-22Change code formatting for readability.Tomasz Różański-2/+2
2019-08-22Apply clippy::let_and_return suggestionMateusz Mikuła-2/+1
2019-08-22Apply clippy::needless_return suggestionsMateusz Mikuła-2/+2
2019-08-21make abs, wrapping_abs, and overflowing_abs const functionsTrevor Spiteri-21/+9
2019-08-21Add comment to avoid accidentally remove the changes.Lzu Tao-0/+2
2019-08-21Use more optimal Ord implementation for integersLzu Tao-3/+3
2019-08-20Test that Wrapping arithmetic ops are implemented for all int typesIlija Tovilo-0/+8
2019-08-20Rollup merge of #63691 - timvermeulen:chain-size-hint, r=scottmcmMazdak Farrokhzad-8/+62
Fix bug in iter::Chain::size_hint `Chain::size_hint` currently ignores `self.state`, which means that the size hints of the underlying iterators are always combined regardless of the iteration state. This, of course, should only happen when the state is `ChainState::Both`.
2019-08-20Rollup merge of #63265 - JohnTitor:implement-nth-back-for-chunksexactmut, ↵Mazdak Farrokhzad-0/+35
r=scottmcm Implement `nth_back` for ChunksExactMut This is a part of #54054. r? @scottmcm
2019-08-18Fix bug in iter::Chain::size_hintTim Vermeulen-8/+62
2019-08-17Rollup merge of #62451 - SimonSapin:new_uninit, r=RalfJungMazdak Farrokhzad-0/+8
Add APIs for uninitialized Box, Rc, and Arc. (Plus get_mut_unchecked) Assigning `MaybeUninit::<Foo>::uninit()` to a local variable is usually free, even when `size_of::<Foo>()` is large. However, passing it for example to `Arc::new` [causes at least one copy](https://youtu.be/F1AquroPfcI?t=4116) (from the stack to the newly allocated heap memory) even though there is no meaningful data. It is theoretically possible that a Sufficiently Advanced Compiler could optimize this copy away, but this is [reportedly unlikely to happen soon in LLVM](https://youtu.be/F1AquroPfcI?t=5431). This PR proposes two sets of features: * Constructors for containers (`Box`, `Rc`, `Arc`) of `MaybeUninit<T>` or `[MaybeUninit<T>]` that do not initialized the data, and unsafe conversions to the known-initialized types (without `MaybeUninit`). The constructors are guaranteed not to make unnecessary copies. * On `Rc` and `Arc`, an unsafe `get_mut_unchecked` method that provides `&mut T` access without checking the reference count. `Arc::get_mut` involves multiple atomic operations whose cost can be non-trivial. `Rc::get_mut` is less costly, but we add `Rc::get_mut_unchecked` anyway for symmetry with `Arc`. These can be useful independently, but they will presumably be typical when the new constructors of `Rc` and `Arc` are used. An alternative with a safe API would be to introduce `UniqueRc` and `UniqueArc` types that have the same memory layout as `Rc` and `Arc` (and so zero-cost conversion to them) but are guaranteed to have only one reference. But introducing entire new types feels “heavier” than new constructors on existing types, and initialization of `MaybeUninit<T>` typically requires unsafe code anyway. Summary of new APIs (all unstable in this PR): ```rust impl<T> Box<T> { pub fn new_uninit() -> Box<MaybeUninit<T>> {…} } impl<T> Box<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Box<T> {…} } impl<T> Box<[T]> { pub fn new_uninit_slice(len: usize) -> Box<[MaybeUninit<T>]> {…} } impl<T> Box<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Box<[T]> {…} } impl<T> Rc<T> { pub fn new_uninit() -> Rc<MaybeUninit<T>> {…} } impl<T> Rc<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Rc<T> {…} } impl<T> Rc<[T]> { pub fn new_uninit_slice(len: usize) -> Rc<[MaybeUninit<T>]> {…} } impl<T> Rc<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Rc<[T]> {…} } impl<T> Arc<T> { pub fn new_uninit() -> Arc<MaybeUninit<T>> {…} } impl<T> Arc<MaybeUninit<T>> { pub unsafe fn assume_init(self) -> Arc<T> {…} } impl<T> Arc<[T]> { pub fn new_uninit_slice(len: usize) -> Arc<[MaybeUninit<T>]> {…} } impl<T> Arc<[MaybeUninit<T>]> { pub unsafe fn assume_init(self) -> Arc<[T]> {…} } impl<T: ?Sized> Rc<T> { pub unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T {…} } impl<T: ?Sized> Arc<T> { pub unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T {…} } ```
2019-08-17Doc nitSimon Sapin-1/+1
Co-Authored-By: Ralf Jung <post@ralfj.de>
2019-08-17Doc nitsSimon Sapin-1/+1
Co-Authored-By: Ralf Jung <post@ralfj.de>
2019-08-17Auto merge of #63462 - matthewjasper:hygienic-builtin-derives, r=petrochenkovbors-16/+19
Opaque builtin derive macros * Buiilt-in derives are now opaque macros * This required limiting the visibility of some previously unexposed functions in `core`. * This also required the change to `Ident` serialization. * All gensyms are replaced with hygienic identifiers * Use hygiene to avoid most other name-resolution issues with buiilt-in derives. * As far as I know the only remaining case that breaks is an ADT that has the same name as one of its parameters. Fixing this completely seemed to be more effort than it's worth. * Remove gensym in `Ident::decode`, which lead to linker errors due to `inline` being gensymmed. * `Ident`now panics if incremental compilation tries to serialize it (it currently doesn't). * `Ident` no longer uses `gensym` to emulate cross-crate hygiene. It only applied to reexports. * `SyntaxContext` is no longer serializable. * The long-term fix for this is to properly implement cross-crate hygiene, but this seemed to be acceptable for now. * Move type/const parameter shadowing checks to `resolve` * This was previously split between resolve and type checking. The type checking pass compared `InternedString`s, not Identifiers. * Removed the `SyntaxContext` from `{ast, hir}::{InlineAsm, GlobalAsm}` cc #60869 r? @petrochenkov
2019-08-17Rollup merge of #62737 - timvermeulen:cycle_try_fold, r=scottmcmMazdak Farrokhzad-0/+42
Override Cycle::try_fold It's not very pretty, but I believe this is the simplest way to correctly implement `Cycle::try_fold`. The following may seem correct: ```rust loop { acc = self.iter.try_fold(acc, &mut f)?; self.iter = self.orig.clone(); } ``` ...but this loops infinitely in case `self.orig` is empty, as opposed to returning `acc`. So we first have to fully iterate `self.orig` to check whether it is empty or not, and before _that_, we have to iterate the remaining elements of `self.iter`. This should always call `self.orig.clone()` the same amount of times as repeated `next()` calls would. r? @scottmcm
2019-08-17Make fmt-internal functions privateMatthew Jasper-5/+8
2019-08-17Make built-in derives opaque macrosMatthew Jasper-11/+11
2019-08-17Rollup merge of #63642 - eddyb:wrap-it-up, r=rkruppe,Mark-SimulacrumMazdak Farrokhzad-6/+64
Rename overflowing_{add,sub,mul} intrinsics to wrapping_{add,sub,mul}. These confused @Gankra, and then, also me, especially since `overflowing_*` *methods* also exist, but they map to `*_with_overflow` intrinsics! r? @oli-obk / @nikomatsakis cc @Mark-Simulacrum (on the rustbuild workaround)
2019-08-16rustbuild: work around the stdarch cfg(bootstrap) bug.Eduard-Mihai Burtescu-18/+18
2019-08-16Rename overflowing_{add,sub,mul} intrinsics to wrapping_{add,sub,mul}.Eduard-Mihai Burtescu-6/+64
2019-08-16Rollup merge of #63613 - petrochenkov:stdhyg, r=alexcrichtonMazdak Farrokhzad-22/+14
Hygienize use of built-in macros in the standard library Same as https://github.com/rust-lang/rust/pull/61629, but for built-in macros. Closes https://github.com/rust-lang/rust/issues/48781 r? @alexcrichton
2019-08-16Rollup merge of #60492 - acrrd:issues/54054_chain, r=SimonSapinMazdak Farrokhzad-0/+39
Add custom nth_back for Chain Implementation of nth_back for Chain. Part of #54054
2019-08-16Add new_uninit and assume_init on Box, Rc, and ArcSimon Sapin-0/+8
2019-08-16Rollup merge of #63615 - jens1o:patch-1, r=jonas-schievinkMazdak Farrokhzad-1/+1
Fix typo in DoubleEndedIterator::nth_back doc
2019-08-16Rollup merge of #63584 - Centril:cleanup-core-with-more-atb, r=alexregMazdak Farrokhzad-6/+2
libcore: more cleanups using `#![feature(associated_type_bounds)]` Turns out this was indeed a bootstrapping issue from a test with `./x.py check` locally after https://github.com/rust-lang/rust/pull/63534 merged. Closes https://github.com/rust-lang/rust/issues/63393 r? @alexreg cc @iluuu1994 cc https://github.com/rust-lang/rust/issues/52662
2019-08-15Fix typo in DoubleEndedIterator::nth_back docJens Hausdorf-1/+1
2019-08-15Remove `__rust_unstable_column`Vadim Petrochenkov-9/+1
2019-08-15Hygienize use of built-in macros in the standard libraryVadim Petrochenkov-13/+13
2019-08-15libcore: more cleanups using associated_type_boundsMazdak Farrokhzad-6/+2
2019-08-15Auto merge of #62429 - cuviper:iter-closures, r=cramertjbors-324/+590
Reduce the genericity of closures in the iterator traits By default, closures inherit the generic parameters of their scope, including `Self`. However, in most cases, the closures used to implement iterators don't need to be generic on the iterator type, only its `Item` type. We can reduce this genericity by redirecting such closures through local functions. This does make the closures more cumbersome to write, but it will hopefully reduce duplication in their monomorphizations, as well as their related type lengths.