about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2020-06-09[AVR] Fix debug printing of function pointersDylan McKay-2/+12
This commit fixes debug printing of function pointers on AVR. AVR does not support `addrspacecast` instructions, and so this patch modifies libcore so that a `ptrtoint` IR instruction is used and the address space cast is avoided.
2020-06-08Rollup merge of #73118 - alamb:alamb/doc-drop-typo, r=shepmasterDylan DPC-1/+1
Improve the wording in documentation of std::mem::drop I thought the original phrasing was somewhat awkward compared to rest of the (very well written) documentation, so figured I would propose a change to improve it.
2020-06-08Fix test call for error caseAlexis Bourget-9/+9
2020-06-08Correctly format the tests and import TryFromAlexis Bourget-1/+2
2020-06-08Fix the typo (size of the size)Stanislav Tkach-2/+2
2020-06-08Added implementations for NonZero(U|I)sizeAlexis Bourget-0/+2
2020-06-08Fix small typo in docs for std::mem::dropalamb-1/+1
2020-06-08Rollup merge of #73001 - ilya-bobyr:master, r=dtolnayRalf Jung-0/+44
Free `default()` forwarding to `Default::default()` It feels a bit redundant to have to say `Default::default()` every time I need a new value of a type that has a `Default` instance. Especially so, compared to Haskell, where the same functionality is called `def`. Providing a free `default()` function that forwards to `Default::default()` seems to improve the situation. The trait is still there, so if someone wants to be explicit and to say `Default::default()` - it still works, but if imported as `std::default::default;`, then the free function reduces typing and visual noise.
2020-06-07Rollup merge of #72998 - poliorcetics:atomic-availability-doc, r=AmanieuDylan DPC-0/+87
Mention that some atomic operations may not be available on some platforms fixes #54250 This simply adds a line saying the type/function/method may not be available on some platforms, depending on said platform capabilities. I *think* I got them all.
2020-06-07Free `default()` forwarding to `Default::default()`Ilya Bobyr-0/+44
When creating default values a trait method needs to be called with an explicit trait name. `Default::default()` seems redundant. A free function on the other hand, when imported directly, seems to be a better API, as it is just `default()`. When implementing the trait, a method is still required.
2020-06-06Only mention `u8` and not booleansPoliorcetics-1/+1
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2020-06-06Rollup merge of #71796 - RalfJung:from-secs, r=nikomatsakisRalf Jung-1/+0
de-promote Duration::from_secs In https://github.com/rust-lang/rust/pull/67531, we removed the `rustc_promotable` attribute from a bunch of `Duration` methods, but not from `Duration::from_secs`. This makes the current list of promotable functions the following (courtesy of @ecstatic-morse): * `INT::min_value`, `INT::max_value` * `std::mem::size_of`, `std::mem::align_of` * `RangeInclusive::new` (backing `x..=y`) * `std::ptr::null`, `std::ptr::null_mut` * `RawWaker::new`, `RawWakerVTable::new` ??? * `Duration::from_secs` I feel like the last one stands out a bit here -- the rest are all very core language primitives, and `RawWaker` has a strong motivation for getting a `'static` vtable. But a `&'static Duration`? That seems unlikely. So I propose we no longer promote calls to `Duration::from_secs`, which is what this PR does. https://github.com/rust-lang/rust/pull/67531 saw zero regressions and I am not aware of anyone complaining that this broke their (non-cratered) code, so I consider it likely the same will be true here, but of course we'd do a crater run. See [this document](https://github.com/rust-lang/const-eval/blob/master/promotion.md) for some more background on promotion and https://github.com/rust-lang/const-eval/issues/19 for some of the concerns around promoting function calls.
2020-06-05std: Enable atomic.fence emission on wasm32Alex Crichton-8/+0
This commit removes the `#[cfg]` guards in `atomic::fence` on wasm targets. Since these guards were originally added the upstream wasm specification for threads gained an `atomic.fence` instruction, so LLVM no longer panics on these intrinsics. Although there aren't a ton of tests in-repo for this right now I've tested locally and all of these fences generate `atomic.fence` instructions in wasm. Closes #72997
2020-06-05Improve the new documentation to be more precise about the necessary ↵Alexis Bourget-67/+97
platform's capabilities
2020-06-05stabilize leading_trailing_onesYoshua Wuyts-13/+12
2020-06-04Add a **Note**: comment in documentation when the type/method/function is ↵Alexis Bourget-13/+70
not always available
2020-06-03Bump to 1.46Mark Rousskov-37/+5
2020-06-02Clarify the behaviour of Pattern when used with methods like str::containsAlexis Bourget-0/+37
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