about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2020-11-02Rollup merge of #78637 - mystor:atomic_ptr_bool, r=m-ou-seYuki Okushi-0/+125
Add fetch_update methods to AtomicBool and AtomicPtr These methods were stabilized for the integer atomics in #71843, but the methods were not added for the non-integer atomics `AtomicBool` and `AtomicPtr`.
2020-11-02Rollup merge of #78627 - est31:total_cmp_no_superset, r=m-ou-seYuki Okushi-0/+8
Point out that total_cmp is no strict superset of partial comparison Partial comparison and total_cmp are not equal. This helps preventing the mistake of creating float wrappers that base their Ord impl on total_cmp and their PartialOrd impl on the PartialOrd impl of the float type. PartialOrd and Ord [are required to agree with each other](https://doc.rust-lang.org/std/cmp/trait.Ord.html#how-can-i-implement-ord).
2020-11-02Rollup merge of #78620 - gabhijit:bitops_doc_fix, r=m-ou-seYuki Okushi-12/+23
Trivial fixes to bitwise operator documentation Added fixes to documentation of `BitAnd`, `BitOr`, `BitXor` and `BitAndAssign`, where the documentation for implementation on `Vector<bool>` was using logical operators in place of the bitwise operators. r? @steveklabnik Closes #78619
2020-11-02Rollup merge of #78606 - autarch:patch-1, r=m-ou-seYuki Okushi-1/+3
Clarify handling of final line ending in str::lines() I found the description as it stands a bit confusing. I've added a bit more explanation to make it clear that a trailing line ending does not produce a final empty line.
2020-11-01Add fetch_update methods to AtomicBool and AtomicPtrNika Layzell-0/+125
These methods were stabilized for the integer atomics in #71843, but the methods were not added for the non-integer atomics `AtomicBool` and `AtomicPtr`.
2020-11-01Point out that total_cmp is no strict superset of partial comparisonest31-0/+8
Partial comparison and total_cmp are not equal. This helps preventing the mistake of creating float wrappers that base their Ord impl on total_cmp and their PartialOrd impl on the PartialOrd impl of the float type. PartialOrd and Ord are required to agree with each other.
2020-11-01Remove incorrect statement about line ending content in lines doc changeDave Rolsky-2/+2
2020-11-01documentation examples fixes in rustfmt conventionAbhijit Gadgil-11/+19
2020-11-01Rollup merge of #78621 - solson:inline, r=m-ou-seMara Bos-0/+2
Inline Default::default() for atomics Functions like `AtomicUsize::default()` are not cross-crate inlineable before this PR ([see assembly output here](https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=e353321766418f759c69fb141d3732f8)), which can lead to unexpected performance issues when initializing a large array using this function, e.g. as seen [here](https://github.com/spacejam/sled/blob/d513996a85875be8c813fd0e30a548b89682289a/src/histogram.rs#L53) which should turn into a simple loop writing zeroes but doesn't. r? @m-ou-se
2020-11-01Rollup merge of #78602 - RalfJung:raw-ptr-aliasing-issues, r=m-ou-seMara Bos-6/+12
fix various aliasing issues in the standard library This fixes various cases where the standard library either used raw pointers after they were already invalidated by using the original reference again, or created raw pointers for one element of a slice and used it to access neighboring elements.
2020-11-01Rollup merge of #78596 - pavlukivan:master, r=m-ou-seMara Bos-1/+1
Fix doc links to std::fmt `std::format` and `core::write` macros' docs linked to `core::fmt` for format string reference, even though only `std::fmt` has format string documentation (and the link titles were `std::fmt`)
2020-11-01Rollup merge of #78073 - fusion-engineering-forks:inline, r=eddybMara Bos-0/+12
Add #[inline] to some functions in core::str. Almost all str functions already had #[inline].
2020-11-01Inline Default::default() for atomicsScott Olson-0/+2
2020-11-01Fixes incorrect paranthesis.Abhijit Gadgil-1/+1
2020-11-01Trivial fixes to bitwise operator documentationAbhijit Gadgil-4/+7
Added fixes to documentation of `BitAnd`, `BitOr`, `BitXor` and `BitAndAssign`, where the documentation for implementation on `Vector<bool>` was using logical operators in place of the bitwise operators. r? @steveklabnik cc #78619
2020-10-31Clarify handling of final line ending in str::lines()Dave Rolsky-1/+3
I found the description as it stands a bit confusing. I've added a bit more explanation to make it clear that a trailing line ending does not produce a final empty line.
2020-10-31fix aliasing issues in SipHasherRalf Jung-1/+1
2020-10-31fix aliasing issues in u128 formatting codeRalf Jung-5/+11
2020-10-31Fix doc links to std::fmtIvan Pavluk-1/+1
std::format and core::write macros' docs linked to core::fmt for format string reference, even though only std::fmt has format string documentation and the link titles were std::fmt.
2020-10-29Improve wording of `core::ptr::drop_in_place` docsCamelid-3/+3
And two small intra-doc link conversions in `std::{f32, f64}`.
2020-10-29Rollup merge of #75078 - ijackson:slice-strip, r=steveklabnikJonas Schievink-12/+14
Improve documentation for slice strip_* functions Prompted by the stabilisation tracking issue #73413 I looked at the docs for `strip_prefix` and `strip_suffix` for both `str` and `slice`, and I felt they could be slightly improved. Thanks for your attention.
2020-10-28Inline NonZeroN::from(n)Peter Todd-0/+1
2020-10-28Rollup merge of #78152 - spastorino:separate-unsized-locals, r=oli-obkDylan DPC-1/+2
Separate unsized locals Closes #71694 Takes over again #72029 and #74971 cc @RalfJung @oli-obk @pnkfelix @eddyb as they've participated in previous reviews of this PR.
2020-10-27Do not depend on except for bootstrapSantiago Pastorino-1/+1
2020-10-27Add unsized_fn_params featureSantiago Pastorino-0/+1
2020-10-27Changed lint to check for `std::fmt::Pointer` and `transmute`Ayrton-0/+2
The lint checks arguments in calls to `transmute` or functions that have `Pointer` as a trait bound and displays a warning if the argument is a function reference. Also checks for `std::fmt::Pointer::fmt` to handle formatting macros although it doesn't depend on the exact expansion of the macro or formatting internals. `std::fmt::Pointer` and `std::fmt::Pointer::fmt` were also added as diagnostic items and symbols.
2020-10-27Rollup merge of #78375 - taiki-e:question-in-macros, r=kennytmYuki Okushi-43/+16
Use ? in core/std macros
2020-10-27Rollup merge of #78347 - Rustin-Liu:rustin-patch-doc, r=kennytmYuki Okushi-14/+24
Add lexicographical comparison doc close https://github.com/rust-lang/rust/issues/72255
2020-10-27Rollup merge of #76635 - scottmcm:slice-as-chunks, r=LukasKalbertodtYuki Okushi-15/+71
Add [T]::as_chunks(_mut) Allows getting the slices directly, rather than just through an iterator as in `array_chunks(_mut)`. The constructors for those iterators are then written in terms of these methods, so the iterator constructors no longer have any `unsafe` of their own. Unstable, of course. #74985
2020-10-26Add lexicographical comparison docRustin-Liu-14/+24
Add links Fix typo Use `sequence` Fix typo Fix broken link Fix broken link Fix broken link Fix broken links Fix broken links
2020-10-26Auto merge of #75728 - nagisa:improve_align_offset_2, r=Mark-Simulacrumbors-3/+14
Optimise align_offset for stride=1 further `stride == 1` case can be computed more efficiently through `-p (mod a)`. That, then translates to a nice and short sequence of LLVM instructions: %address = ptrtoint i8* %p to i64 %negptr = sub i64 0, %address %offset = and i64 %negptr, %a_minus_one And produces pretty much ideal code-gen when this function is used in isolation. Typical use of this function will, however, involve use of the result to offset a pointer, i.e. %aligned = getelementptr inbounds i8, i8* %p, i64 %offset This still looks very good, but LLVM does not really translate that to what would be considered ideal machine code (on any target). For example that's the codegen we obtain for an unknown alignment: ; x86_64 dec rsi mov rax, rdi neg rax and rax, rsi add rax, rdi In particular negating a pointer is not something that’s going to be optimised for in the design of CISC architectures like x86_64. They are much better at offsetting pointers. And so we’d love to utilize this ability and produce code that's more like this: ; x86_64 lea rax, [rsi + rdi - 1] neg rsi and rax, rsi To achieve this we need to give LLVM an opportunity to apply its various peep-hole optimisations that it does during DAG selection. In particular, the `and` instruction appears to be a major inhibitor here. We cannot, sadly, get rid of this load-bearing operation, but we can reorder operations such that LLVM has more to work with around this instruction. One such ordering is proposed in #75579 and results in LLVM IR that looks broadly like this: ; using add enables `lea` and similar CISCisms %offset_ptr = add i64 %address, %a_minus_one %mask = sub i64 0, %a %masked = and i64 %offset_ptr, %mask ; can be folded with `gepi` that may follow %offset = sub i64 %masked, %address …and generates the intended x86_64 machine code. One might also wonder how the increased amount of code would impact a RISC target. Turns out not much: ; aarch64 previous ; aarch64 new sub x8, x1, #1 add x8, x1, x0 neg x9, x0 sub x8, x8, #1 and x8, x9, x8 neg x9, x1 add x0, x0, x8 and x0, x8, x9 (and similarly for ppc, sparc, mips, riscv, etc) The only target that seems to do worse is… wasm32. Onto actual measurements – the best way to evaluate snipets like these is to use llvm-mca. Much like Aarch64 assembly would allow to suspect, there isn’t any performance difference to be found. Both snippets execute in same number of cycles for the CPUs I tried. On x86_64, we get throughput improvement of >50%! Fixes #75579
2020-10-26Rollup merge of #78126 - shepmaster:aarch64-apple-darwin-valist, r=nagisaDylan DPC-7/+11
Properly define va_arg and va_list for aarch64-apple-darwin From [Apple][]: > Because of these changes, the type `va_list` is an alias for `char*`, > and not for the struct type in the generic procedure call standard. With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi` passes. Fixes #78092 [Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-26Rollup merge of #77836 - RalfJung:transmute_copy, r=Mark-SimulacrumDylan DPC-4/+4
transmute_copy: explain that alignment is handled correctly The doc comment currently is somewhat misleading because if it actually transmuted `&T` to `&U`, a higher-aligned `U` would be problematic.
2020-10-25Properly define va_arg and va_list for aarch64-apple-darwinJake Goulding-7/+11
From [Apple][]: > Because of these changes, the type `va_list` is an alias for `char*`, > and not for the struct type in the generic procedure call standard. With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi` passes. Fixes #78092 [Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-26Use ? in core/std macrosTaiki Endo-43/+16
2020-10-25Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obkYuki Okushi-8/+17
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s `#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks. While it was originally only meant to be used only on macros, its use was expanded to `const fn`s. This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s. This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540). Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'. Closes rust-lang/rust#69399 r? @oli-obk
2020-10-24Rollup merge of #78069 - fusion-engineering-forks:core-const-panic-str, ↵Jonas Schievink-1/+8
r=RalfJung Fix const core::panic!(non_literal_str). Invocations of `core::panic!(x)` where `x` is not a string literal expand to `panic!("{}", x)`, which is not understood by the const panic logic right now. This adds `panic_str` as a lang item, and modifies the const eval implementation to hook into this item as well. This fixes the issue mentioned here: https://github.com/rust-lang/rust/issues/51999#issuecomment-687604248 r? `@RalfJung` `@rustbot` modify labels: +A-const-eval
2020-10-24Rollup merge of #76614 - NoraCodes:nora/control_flow_enum, r=scottmcmJonas Schievink-23/+17
change the order of type arguments on ControlFlow This allows ControlFlow<BreakType> which is much more ergonomic for common iterator combinator use cases. Addresses one component of #75744
2020-10-24Rollup merge of #78109 - cuviper:exhausted-rangeinc, r=dtolnayJonas Schievink-21/+43
Check for exhaustion in RangeInclusive::contains and slicing When a range has finished iteration, `is_empty` returns true, so it should also be the case that `contains` returns false. Fixes #77941.
2020-10-24Rollup merge of #77392 - Canop:option_insert, r=m-ou-seJonas Schievink-7/+37
add `insert` to `Option` This removes a cause of `unwrap` and code complexity. This allows replacing ``` option_value = Some(build()); option_value.as_mut().unwrap() ``` with ``` option_value.insert(build()) ``` It's also useful in contexts not requiring the mutability of the reference. Here's a typical cache example: ``` let checked_cache = cache.as_ref().filter(|e| e.is_valid()); let content = match checked_cache { Some(e) => &e.content, None => { cache = Some(compute_cache_entry()); // unwrap is OK because we just filled the option &cache.as_ref().unwrap().content } }; ``` It can be changed into ``` let checked_cache = cache.as_ref().filter(|e| e.is_valid()); let content = match checked_cache { Some(e) => &e.content, None => &cache.insert(compute_cache_entry()).content, }; ``` *(edited: I removed `insert_with`)*
2020-10-23add tracking issue number to option_insert feature gateCanop-1/+1
2020-10-23Update library/core/src/option.rsCanop-4/+0
Co-authored-by: Ivan Tham <pickfire@riseup.net>
2020-10-23Update library/core/src/option.rsCanop-0/+2
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-10-23fix naming unconsistency between function doc and prototypeCanop-9/+8
2020-10-23more tests in option.insert, code cleaning in optionCanop-12/+17
Code cleaning made according to suggestions in discussion on PR ##77392 impacts insert, get_or_insert and get_or_insert_with.
2020-10-23remove `option.insert_with`Canop-19/+1
`option.insert` covers both needs anyway, `insert_with` is redundant.
2020-10-23add `insert` and `insert_with` to `Option`Canop-0/+46
This removes a cause of `unwrap` and code complexity. This allows replacing ``` option_value = Some(build()); option_value.as_mut().unwrap() ``` with ``` option_value.insert(build()) ``` or ``` option_value.insert_with(build) ``` It's also useful in contexts not requiring the mutability of the reference. Here's a typical cache example: ``` let checked_cache = cache.as_ref().filter(|e| e.is_valid()); let content = match checked_cache { Some(e) => &e.content, None => { cache = Some(compute_cache_entry()); // unwrap is OK because we just filled the option &cache.as_ref().unwrap().content } }; ``` It can be changed into ``` let checked_cache = cache.as_ref().filter(|e| e.is_valid()); let content = match checked_cache { Some(e) => &e.content, None => &cache.insert_with(compute_cache_entry).content, }; ```
2020-10-23Rollup merge of #77969 - ryan-scott-dev:bigo-notation-consistency, r=m-ou-seYuki Okushi-9/+9
Doc formating consistency between slice sort and sort_unstable, and big O notation consistency Updated documentation for slice sorting methods to be consistent between stable and unstable versions, which just ended up being minor formatting differences. I also went through and updated any doc comments with big O notation to be consistent with #74010 by italicizing them rather than having them in a code block.
2020-10-23Rollup merge of #77339 - ↵Yuki Okushi-0/+46
fusion-engineering-forks:tryfrom-nonzero-to-nonzero, r=dtolnay Implement TryFrom between NonZero types. This will instantly be stable, as trait implementations for stable types and traits can not be `#[unstable]`. Closes #77258. @rustbot modify labels: +T-libs
2020-10-22change the order of type arguments on ControlFlowLeonora Tindall-23/+17
This allows ControlFlow<BreakType> which is much more ergonomic for common iterator combinator use cases.