summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2020-06-02Rollup merge of #72891 - lzutao:wrapping_int-max, r=sfacklerYuki Okushi-12/+4
Add associated consts MIN/MAX for Wrapping<Int>
2020-06-02Rollup merge of #72886 - xfix:patch-21, r=jonas-schievinkYuki Okushi-1/+0
Remove allow missing_debug_implementations for MaybeUninit It already has a Debug implementation.
2020-06-02Rollup merge of #72825 - Amanieu:asm-warning, r=davidtwcoYuki Okushi-1/+1
Clarify errors and warnings about the transition to the new asm! Hopefully addresses the concerns from https://github.com/rust-lang/rust/pull/71007#issuecomment-636412905.
2020-06-01Add associated consts MIN/MAX for Wrapping<Int>Lzu Tao-12/+4
2020-06-01Remove allow missing_debug_implementations for MaybeUninitKonrad Borowski-1/+0
It already has a Debug implementation.
2020-06-01Rollup merge of #72834 - JOE1994:correct_confusing_term, r=sfacklerDylan DPC-4/+4
Rephrase term 'non-pointer type' Hello :cat2: , If the reader assumes that 'pointer type's include 'smart pointer's, the term 'non-pointer type' could mislead the reader to assume that x should not be a smart pointer type. I tried to rephrase the term 'non-pointer type' to remove ambiguity in the doc comments. closes #72335 Thank you for reviewing this PR! :superhero_woman:
2020-05-31Rephrase term 'non-pointer type'JOE1994-4/+4
If the reader assumes that 'pointer type's include 'smart pointer's, the term 'non-pointer type' could mislead the reader to assume that x should not be a smart pointer type. I tried to rephrase the term 'non-pointer type' to remove ambiguity in the doc comments. closes #72335 Thank you for reviewing this PR! :)
2020-05-31Rollup merge of #72829 - JOE1994:clarify_terms, r=jonas-schievinkDylan DPC-2/+2
Clarify terms in doc comments Doc comments of `copy_from_slice` say that people should use `clone_from_slice` when 'src' doesn't implement `Copy`. However, 'src' is a reference and it always implements `Copy`. The term 'src' should be fixed to `T`(element type of slice 'src') in the doc comments. Thank you for reviewing this PR :) :smiley_cat:
2020-05-31Rollup merge of #72812 - RalfJung:miri-char-test, r=jonas-schievinkDylan DPC-2/+5
Miri tests: skip parts of test_char_range The new `test_char_range` test takes forever in Miri as it loops over all values of `char`. This makes it skip most of them when being run in Miri.
2020-05-31Clarify terms in doc commentsJOE1994-2/+2
Doc comments of 'copy_from_slice' say that people should use 'clone_from_slice' when 'src' doesn't implement 'Copy'. However, 'src' is a reference and it always implements 'Copy'. The term 'src' should be fixed to 'T' in the doc comments. Thank you for reviewing this PR :)
2020-05-31Clarify errors and warnings about the transition to the new asm!Amanieu d'Antras-1/+1
2020-05-31Miri tests: skip parts of test_char_rangeRalf Jung-2/+5
2020-05-31Rollup merge of #72683 - RalfJung:char-debug-check, r=Mark-SimulacrumRalf Jung-64/+109
from_u32_unchecked: check validity, and fix UB in Wtf8 Fixes https://github.com/rust-lang/rust/issues/72760
2020-05-30Rollup merge of #72773 - Rantanen:is_char_boundary-docs, r=joshtriplettRalf Jung-4/+3
Fix is_char_boundary documentation Given the "start _and/or end_" wording in the original, the way I understood it was that the `str::is_char_boundary` method would also return `true` for the last byte in a UTF-8 code point sequence. (Which would have meant that for a string consisting of nothing but 1 and 2 byte UTF-8 code point sequences, it would return nothing but `true`.) In practice the method returns `true` only for the starting byte of each sequence and the end of the string: [Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=e9f5fc4d6bf2f1bf57a75f3c9a180770) I was also somewhat tempted to remove the _The start and end of the string are considered to be boundaries_, since that's implied by the first sentence, but I decided to avoid bikeshedding over it and left it as it was since it's not wrong in relation to how the method behaves.
2020-05-30encode_utf8_raw is not always valid UTF-8; clarify commentsRalf Jung-7/+12
2020-05-30Rollup merge of #72368 - CAD97:rangeto, r=dtolnayRalf Jung-13/+11
Resolve overflow behavior for RangeFrom This specifies a documented unspecified implementation detail of `RangeFrom` and makes it consistently implement the specified behavior. Specifically, `(u8::MAX).next()` is defined to cause an overflow, and resolve that overflow in the same manner as the `Step::forward` implementation. The inconsistency that has existed is `<RangeFrom as Iterator>::nth`. The existing behavior should be plain to see after #69659: the skipping part previously always panicked if it caused an overflow, but the final step (to set up the state for further iteration) has always been debug-checked. The inconsistency, then, is that `RangeFrom::nth` does not implement the same behavior as the naive (and default) implementation of just calling `next` multiple times. This PR aligns `RangeFrom::nth` to have identical behavior to the naive implementation. It also lines up with the standard behavior of primitive math in Rust everywhere else in the language: debug checked overflow. cc @Amanieu --- Followup to #69659. Closes #25708 (by documenting the panic as intended). The documentation wording is preliminary and can probably be improved. This will probably need an FCP, as it changes observable stable behavior.
2020-05-30also expose and use encode_utf16_raw for wtf8Ralf Jung-22/+39
2020-05-30expose char::encode_utf8_raw for libstdRalf Jung-40/+63
2020-05-30Rollup merge of #72162 - cuviper:extend_one, r=Mark-SimulacrumYuki Okushi-5/+26
Add Extend::{extend_one,extend_reserve} This adds new optional methods on `Extend`: `extend_one` add a single element to the collection, and `extend_reserve` pre-allocates space for the predicted number of incoming elements. These are used in `Iterator` for `partition` and `unzip` as they shuffle elements one-at-a-time into their respective collections.
2020-05-29Add extend_one tracking issue 72631Josh Stone-2/+2
2020-05-29Use a canonical name for extend_reserve(additional)Josh Stone-1/+3
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2020-05-29Add Extend::{extend_one,extend_reserve}Josh Stone-5/+24
This adds new optional methods on `Extend`: `extend_one` add a single element to the collection, and `extend_reserve` pre-allocates space for the predicted number of incoming elements. These are used in `Iterator` for `partition` and `unzip` as they shuffle elements one-at-a-time into their respective collections.
2020-05-29Auto merge of #72756 - RalfJung:rollup-tbjmtx2, r=RalfJungbors-13/+112
Rollup of 9 pull requests Successful merges: - #67460 (Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes) - #71095 (impl From<[T; N]> for Box<[T]>) - #71500 (Make pointer offset methods/intrinsics const) - #71804 (linker: Support `-static-pie` and `-static -shared`) - #71862 (Implement RFC 2585: unsafe blocks in unsafe fn) - #72103 (borrowck `DefId` -> `LocalDefId`) - #72407 (Various minor improvements to Ipv6Addr::Display) - #72413 (impl Step for char (make Range*<char> iterable)) - #72439 (NVPTX support for new asm!) Failed merges: r? @ghost
2020-05-29Rollup merge of #72413 - CAD97:char-range, r=dtolnayRalf Jung-1/+85
impl Step for char (make Range*<char> iterable) [[irlo thread]](https://internals.rust-lang.org/t/mini-rfc-make-range-char-work/12392?u=cad97) [[godbolt asm example]](https://rust.godbolt.org/z/fdveKo) Add an implementation of the `Step` trait for `char`, which has the effect of making `RangeInclusive<char>` (and the other range types) iterable. I've used the surrogate range magic numbers as magic numbers here rather than e.g. a `const SURROGATE_RANGE = 0xD800..0xE000` because these numbers appear to be used as magic numbers elsewhere and there doesn't exist constants for them yet. These files definitely aren't where surrogate range constants should live. `ExactSizeIterator` is not implemented because `0x10FFFF` is bigger than fits in a `usize == u16`. However, given we already provide some `ExactSizeIterator` that are not correct on 16 bit targets, we might still want to consider providing it for `Range`[`Inclusive`]`<char>`, as it is definitely _very_ convenient. (At the very least, we want to make sure `.count()` doesn't bother iterating the range.) The second commit in this PR changes a call to `Step::forward` to use `Step::forward_unchecked` in `RangeInclusive::next`. This is because without this patch, iteration over all codepoints (`'\0'..=char::MAX`) does not successfully optimize out the panicking branch. This was mentioned in the PR that updated `Step` to its current design, but was deemed not yet necessary as it did not impact codegen for integral types. More of `Range*`'s implementations' calls to `Step` methods will probably want to see if they can use the `_unchecked` version as (if) we open up `Step` to being implemented on more types. --- cc @rust-lang/libs, this is insta-stable and a fairly significant addition to `Range*`'s capabilities; this is the first instance of a noncontinuous domain being iterable with `Range` (or, well, anything other than primitive integers). I don't think this needs a full RFC, but it should definitely get some decent eyes on it.
2020-05-29Rollup merge of #71500 - josephlr:offset, r=oli-obk,RalfJungRalf Jung-12/+27
Make pointer offset methods/intrinsics const Implements #71499 using [the implementations from miri](https://github.com/rust-lang/miri/blob/52f5d202bdcfe8986f0615845f8d1647ab8a2c6a/src/shims/intrinsics.rs#L96-L112). I added some tests what's allowed and what's UB. Let me know if any other cases should be added. CC: @RalfJung @oli-obk
2020-05-29Rollup merge of #72568 - golddranks:add_total_cmp_to_floats, r=sfacklerDylan DPC-0/+148
Implement total_cmp for f32, f64 # Overview * Implements method `total_cmp` on `f32` and `f64`. This method implements a float comparison that, unlike the standard `partial_cmp`, is total (defined on all values) in accordance to the IEEE 754 (rev 2008) §5.10 `totalOrder` predicate. * The method has an API similar to `cmp`: `pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering { ... }`. * Implements tests. * Has documentation. # Justification for the API * Total ordering for `f32` and `f64` has been discussed many time before: * https://internals.rust-lang.org/t/pre-pre-rfc-range-restricting-wrappers-for-floating-point-types/6701 * https://github.com/rust-lang/rfcs/issues/1249 * https://github.com/rust-lang/rust/pull/53938 * https://github.com/rust-lang/rust/issues/5585 * The lack of total ordering leads to frequent complaints, especially from people new to Rust. * This is an ergonomics issue that needs to be addressed. * However, the default behaviour of implementing only `PartialOrd` is intentional, as relaxing it might lead to correctness issues. * Most earlier implementations and discussions have been focusing on a wrapper type that implements trait `Ord`. Such a wrapper type is, however not easy to add because of the large API surface added. * As a minimal step that hopefully proves uncontroversial, we can implement a stand-alone method `total_cmp` on floating point types. * I expect adding such methods should be uncontroversial because... * Similar methods on `f32` and `f64` would be warranted even in case stdlib would provide a wrapper type that implements `Ord` some day. * It implements functionality that is standardised. (IEEE 754, 2008 rev. §5.10 Note, that the 2019 revision relaxes the ordering. The way we do ordering in this method conforms to the stricter 2008 standard.) * With stdlib APIs such as `slice::sort_by` and `slice::binary_search_by` that allow users to provide a custom ordering criterion, providing additional helper methods is a minimal way of adding ordering functionality. * Not also does it allow easily using aforementioned APIs, it also provides an easy and well-tested primitive for the users and library authors to implement an `Ord`-implementing wrapper, if needed.
2020-05-29Rollup merge of #72310 - jyn514:peekable-next-if, r=dtolnayDylan DPC-0/+88
Add Peekable::next_if Prior art: `rust_analyzer` uses [`Parser::eat`](https://github.com/rust-analyzer/rust-analyzer/blob/50f4ae798b7c54d417ee88455b87fd0477473150/crates/ra_parser/src/parser.rs#L94), which is `next_if` specialized to `|y| self.next_if(|x| x == y)`. Basically every other parser I've run into in Rust has an equivalent of `Parser::eat`; see for example - [cranelift](https://github.com/bytecodealliance/wasmtime/blob/94190d57244b26baf36629c88104b0ba516510cf/cranelift/reader/src/parser.rs#L498) - [rcc](https://github.com/jyn514/rcc/blob/a8159c3904a0c950fbba817bf9109023fad69033/src/parse/mod.rs#L231) - [crunch](https://github.com/Kixiron/crunch-lang/blob/8521874fab8a7d62bfa7dea8bd1da94b63e31be8/crates/crunch-parser/src/parser/mod.rs#L213-L241) Possible extensions: A specialization of `next_if` to using `Eq::eq`. The only difficulty here is the naming - maybe `next_if_eq`? Alternatives: - Instead of `func: impl FnOnce(&I::Item) -> bool`, use `func: impl FnOnce(I::Item) -> Option<I::Item>`. This has the advantage that `func` can move the value if necessary, but means that there is no guarantee `func` will return the same value it was given. - Instead of `fn next_if(...) -> Option<I::Item>`, use `fn next_if(...) -> bool`. This makes the common case of `iter.next_if(f).is_some()` easier, but makes the unusual case impossible. Bikeshedding on naming: - `next_if` could be renamed to `consume_if` (to match `eat`, but a little more formally) - `next_if_eq` could be renamed to `consume`. This is more concise but less self-explanatory if you haven't written a lot of parsers. - Both of the above, but with `consume` replaced by `eat`.
2020-05-29Rollup merge of #72720 - poliorcetics:clarify-take-doc, r=joshtriplettYuki Okushi-0/+11
Clarify the documentation of `take` This PR addresses the concerns of #61222, adding an example for the behaviour of `Iterator::take` when there are less than `n` elements.
2020-05-29Rollup merge of #72452 - Lucretiel:precision-doc, r=dtolnayYuki Okushi-1/+2
Clarified the documentation for Formatter::precision Added a note that `precision` is interpreted as max-width when formatting strings
2020-05-29Rollup merge of #72324 - Amanieu:atomic_minmax, r=dtolnayYuki Okushi-10/+2
Stabilize AtomicN::fetch_min and AtomicN::fetch_max Some architectures (ARMv8.1 LSE and RISC-V) have specific instructions for atomic min/max which the compiler can only generate through explicit instrinsics.
2020-05-29Rollup merge of #71843 - sfackler:cas-loop-cleanup, r=dtolnayYuki Okushi-15/+11
Tweak and stabilize AtomicN::fetch_update The fetch_update method implements a compare-and-swap loop to update the value in an atomic to an arbitrary value computed by a closure. I've applied a few tweaks suggested by @mystor in this comment on the tracking issue: https://github.com/rust-lang/rust/issues/48655#issuecomment-496036553. Specifically, the load and store ordering arguments have been swapped to match with the orderings of `compare_exchange`, and the closure has been moved from the first to last argument. Moving the closure to the last argument is a change away from other methods on the atomic types which place the ordering(s) last, but matches with the broad convention that closure arguments come last in functions. In particular, rustfmt style lays calls with multi-line closures out more cleanly when the closure comes last.
2020-05-29Clarify the documentation of takeAlexis Bourget-0/+11
2020-05-29Rollup merge of #72466 - lzutao:stabilize_str-strip, r=dtolnayDylan DPC-5/+2
Stabilize str_strip feature This PR stabilizes these APIs: ```rust impl str { /// Returns a string slice with the prefix removed. /// /// If the string starts with the pattern `prefix`, `Some` is returned with the substring where /// the prefix is removed. Unlike `trim_start_matches`, this method removes the prefix exactly /// once. pub fn strip_prefix<'a, P: Pattern<'a>>(&'a self, prefix: P) -> Option<&'a str>; /// Returns a string slice with the suffix removed. /// /// If the string ends with the pattern `suffix`, `Some` is returned with the substring where /// the suffix is removed. Unlike `trim_end_matches`, this method removes the suffix exactly /// once. pub fn strip_suffix<'a, P>(&'a self, suffix: P) -> Option<&'a str> where P: Pattern<'a>, <P as Pattern<'a>>::Searcher: ReverseSearcher<'a>; } ``` Closes #67302
2020-05-28from_u32_unchecked: check validity when debug assertions are enabledRalf Jung-2/+2
2020-05-28FIx off-by-one in char::steps_betweenCAD97-1/+3
2020-05-27Fix is_char_boundary documentationMikko Rantanen-4/+3
2020-05-26Add Peekable::next_ifJoshua Nelson-0/+88
Prior art: `rust_analyzer` uses [`Parser::eat`](https://github.com/rust-analyzer/rust-analyzer/blob/50f4ae798b7c54d417ee88455b87fd0477473150/crates/ra_parser/src/parser.rs#L94), which is `next_if` specialized to `|y| next_if(|x| x == y)`. Basically every other parser I've run into in Rust has an equivalent of Parser::eat; see for example - [cranelift](https://github.com/bytecodealliance/wasmtime/blob/94190d57244b26baf36629c88104b0ba516510cf/cranelift/reader/src/parser.rs#L498) - [rcc](https://github.com/jyn514/rcc/blob/a8159c3904a0c950fbba817bf9109023fad69033/src/parse/mod.rs#L231) - [crunch](https://github.com/Kixiron/crunch-lang/blob/8521874fab8a7d62bfa7dea8bd1da94b63e31be8/crates/crunch-parser/src/parser/mod.rs#L213-L241)
2020-05-27Rollup merge of #72626 - phimuemue:doubleendediter_doc, r=dtolnayDylan DPC-0/+26
Add remark regarding DoubleEndedIterator While reviewing https://github.com/rust-itertools/itertools/pull/442/commits/14293bd18f01b6bd4856816222f808f46603eccd#diff-2c16d2ada06ad2fd1fc754679646d471, I realized that a `DoubleEndedIterator` may yield different elements depending on whether it is traversed forwards or backwards. (Not only the *order*, but possibly also the yielded values.) I found this remarkable, but could not find anything in the current docs, so I thought it may be worth mentioning this explicitly. Unfortunately, I could not test these changes locally (`rustdoc` complains about `unresolved import`). Sorry if this causes headache. If I should change something, please let me know. If it seems too trivial, feel free to just close this PR.
2020-05-27Rollup merge of #72606 - GuillaumeGomez:cell-example-update, r=Dylan-DPCDylan DPC-3/+3
Small cell example update r? @Dylan-DPC
2020-05-26Add remark regarding DoubleEndedIteratorphilipp-0/+26
2020-05-26Small cell example updateGuillaume Gomez-3/+3
2020-05-26Add tracing issue for total_cmpPyry Kontio-2/+2
2020-05-25Rollup merge of #72450 - csmoe:issue-72442, r=oli-obkDylan DPC-0/+1
Fix ice-#72442 Closes #72442 Closes #72426 r? @oli-obk
2020-05-25core: Make pointer offset methods "const fn"Joe Richey-12/+27
Signed-off-by: Joe Richey <joerichey@google.com>
2020-05-26Fix the same typos again orzPyry Kontio-4/+4
2020-05-26Add bit twiddlingPyry Kontio-15/+19
2020-05-26remove unneeded and unidiomatic must_usePyry Kontio-2/+0
2020-05-26Fix typo in src/libcore/num/f32.rsPyry Kontio-1/+1
Co-authored-by: bluss <bluss@users.noreply.github.com>
2020-05-26Fix typo in src/libcore/num/f32.rsPyry Kontio-1/+1
Co-authored-by: bluss <bluss@users.noreply.github.com>
2020-05-25Add total_cmp to f32 and f64, plus testsPyry Kontio-0/+146