about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2018-05-16Fix `Debug` impl of `Duration` for precisions > 9Lukas Kalbertodt-11/+24
Previously, the code would panic for high precision values. Now it has the same behavior as printing normal floating point values: if a high precision is specified, '0's are added.
2018-05-16Implement rounding for `Duration`s Debug outputLukas Kalbertodt-7/+51
Rounding is done like for printing floating point numbers. If the first digit which isn't printed (due to the precision parameter) is larger than '4', the number is rounded up.
2018-05-16fix a typo in signed-integer::from_str_radix()SHA Miao-1/+1
just a small typo.
2018-05-15Separate feature gate for wrapping_next_power_of_twoClar Charr-4/+6
2018-05-15Add Option::xor methodClar Charr-0/+36
2018-05-15Rollup merge of #50745 - kraai:patch-1, r=kennytmGuillaume Gomez-1/+1
Uncapitalize "You"
2018-05-15Rollup merge of #49767 - ecstatic-morse:ptr-docs, r=steveklabnikGuillaume Gomez-101/+430
Rewrite docs for `std::ptr` This PR attempts to resolve #29371. This is a fairly major rewrite of the `std::ptr` docs, and deserves a fair bit of scrutiny. It adds links to the GNU libc docs for various instrinsics, adds internal links to types and functions referenced in the docs, adds new, more complex examples for many functions, and introduces a common template for discussing unsafety of functions in `std::ptr`. All functions in `std::ptr` (with the exception of `ptr::eq`) are unsafe because they either read from or write to a raw pointer. The "Safety" section now informs that the function is unsafe because it dereferences a raw pointer and requires that any pointer to be read by the function points to "a valid vaue of type `T`". Additionally, each function imposes some subset of the following conditions on its arguments. * The pointer points to valid memory. * The pointer points to initialized memory. * The pointer is properly aligned. These requirements are discussed in the "Undefined Behavior" section along with the consequences of using functions that perform bitwise copies without requiring `T: Copy`. I don't love my new descriptions of the consequences of making such copies. Perhaps the old ones were good enough? Some issues which still need to be addressed before this is merged: - [ ] The new docs assert that `drop_in_place` is equivalent to calling `read` and discarding the value. Is this correct? - [ ] Do `write_bytes` and `swap_nonoverlapping` require properly aligned pointers? - [ ] The new example for `drop_in_place` is a lackluster. - [ ] Should these docs rigorously define what `valid` memory is? Or should is that the job of the reference? Should we link to the reference? - [ ] Is it correct to require that pointers that will be read from refer to "valid values of type `T`"? - [x] I can't imagine ever using `{read,write}_volatile` with non-`Copy` types. Should I just link to {read,write} and say that the same issues with non-`Copy` types apply? - [x] `write_volatile` doesn't link back to `read_volatile`. - [ ] Update docs for the unstable [`swap_nonoverlapping`](https://github.com/rust-lang/rust/issues/42818) - [ ] Update docs for the unstable [unsafe pointer methods RFC](https://github.com/rust-lang/rfcs/pull/1966) Looking forward to your feedback. r? @steveklabnik
2018-05-14Add implementation of Extend for ()Taylor Cramer-0/+7
2018-05-14Uncapitalize "You"Matt Kraai-1/+1
2018-05-13Fix incorrect statement about return value for Iterator::zip.Corey Farwell-2/+1
Fixes https://github.com/rust-lang/rust/issues/50225.
2018-05-12Rollup merge of #50545 - rizakrko:const_time, r=oli-obkMark Simulacrum-6/+48
Made some functions in time module const They may be const, or i missed something?
2018-05-10const timeRoman Stoliar-6/+48
added rustc_const_unstable attribute extended tests added conversion test fixed tidy test added feature attribute
2018-05-10Rollup merge of #50588 - ExpHP:i-can-see-my-house-from-here, r=frewsxcvAlex Crichton-4/+4
Move "See also" disambiguation links for primitive types to top Closes #50384. <details> <summary>Images</summary> ![rust-slice](https://user-images.githubusercontent.com/1411280/39843148-caa41c3e-53b7-11e8-8123-b57c25a4d9e0.png) ![rust-isize](https://user-images.githubusercontent.com/1411280/39843146-ca94b384-53b7-11e8-85f3-3f5e5d353a05.png) </details> r? @steveklabnik
2018-05-10Rollup merge of #50574 - s3bk:range_inclusive_into_inner, r=SimonSapinAlex Crichton-0/+15
add fn `into_inner(self) -> (Idx, Idx)` to RangeInclusive (#49022) adds `into_inner(self) -> (Idx, Idx)` to RangeInclusive https://github.com/rust-lang/rust/issues/49022#issuecomment-387645176
2018-05-10Rollup merge of #50010 - ExpHP:slice-bounds, r=alexcrichtonAlex Crichton-74/+242
Give SliceIndex impls a test suite of girth befitting the implementation (and fix a UTF8 boundary check) So one day I was writing something in my codebase that basically amounted to `impl SliceIndex for (Bound<usize>, Bound<usize>)`, and I said to myself: *Boy, gee, golly! I never realized bounds checking was so tricky!* At some point when I had around 60 lines of tests for it, I decided to go see how the standard library does it to see if I missed any edge cases. ...That's when I discovered that libcore only had about 40 lines of tests for slicing altogether, and none of them even used `..=`. --- This PR includes: * **Literally the first appearance of the word `get_unchecked_mut` in any directory named `test` or `tests`.** * Likewise the first appearance of `get_mut` used with _any type of range argument_ in these directories. * Tests for the panics on overflow with `..=`. * I wanted to test on `[(); usize::MAX]` as well but that takes linear time in debug mode </3 * A horrible and ugly test-generating macro for the `should_panic` tests that increases the DRYness by a single order of magnitude (which IMO wasn't enough, but I didn't want to go any further and risk making the tests inaccessible to next guy). * Same stuff for str! * Actually, the existing `str` tests were pretty good. I just helped filled in the holes. * [A fix for the bug it caught](https://github.com/rust-lang/rust/issues/50002). (only one ~~sadly~~)
2018-05-09Shorten ownership safety discussion in `read_volatile`Dylan MacKenzie-8/+15
Non-`Copy` types should not be in volatile memory.
2018-05-09move See also links to topMichael Lamparski-4/+4
2018-05-09Use the "Safety" heading instead of "Undefined Behavior"Dylan MacKenzie-65/+9
2018-05-09add fn `into_inner(self) -> (Idx, Idx)` to RangeInclusive (#49022)Sebastian Köln-0/+15
2018-05-09Rollup merge of #50511 - Manishearth:must-use, r=QuietMisdreavuskennytm-6/+6
Add some explanations for #[must_use] `#[must_use]` can be given a string argument which is shown whilst warning for things. We should add a string argument to most of the user-exposed ones. I added these for everything but the operators, mostly because I'm not sure what to write there or if we need anything there.
2018-05-09Rollup merge of #50464 - est31:master, r=rkruppekennytm-6/+4
Remove some transmutes
2018-05-09Rollup merge of #50148 - japaric:const-manuallydrop, r=oli-obkkennytm-1/+2
turn `ManuallyDrop::new` into a constant function
2018-05-09Rollup merge of #50539 - clarcharr:log_const, r=dtolnaykennytm-0/+16
Add more logarithm constants Right now, we have `ln(2)` and `ln(10)`, but only `log2(e)` and `log10(e)`. This also adds `log2(10)` and `log10(2)` for consistency.
2018-05-08Add missing Wrapping methods, use doc_comment!Clar Charr-199/+486
2018-05-08Add more logarithm constantsClar Charr-0/+16
2018-05-07Add explanation for #[must_use] on Debug buildersManish Goregaokar-5/+5
2018-05-07Add explanation for #[must_use] on ResultManish Goregaokar-1/+1
2018-05-07Unpin: Fix references to Pin typeRalf Jung-4/+4
2018-05-07Rename PinMut::borrow to PinMut::reborrow and make it a methodRalf Jung-3/+6
2018-05-07PinMut::get_mut can also preserve the lifetimeRalf Jung-1/+1
2018-05-07Change PinMut::map to be able to preserve the original reference's lifetimeRalf Jung-1/+1
Suggested by @dylanede at <https://github.com/rust-lang/rust/issues/49150#issuecomment-381071442>.
2018-05-07Rename Pin to PinMutRalf Jung-24/+24
As discussed at [1] §3 and [2] and [3], a formal look at pinning requires considering a distinguished "shared pinned" mode/typestate. Given that, it seems desirable to at least eventually actually expose that typestate as a reference type. This renames Pin to PinMut, freeing the name Pin in case we want to use it for a shared pinned reference later on. [1] https://www.ralfj.de/blog/2018/04/10/safe-intrusive-collections-with-pinning.html [2] https://github.com/rust-lang/rfcs/pull/2349#issuecomment-379250361 [3] https://github.com/rust-lang/rust/issues/49150#issuecomment-380488275
2018-05-07make the const constructor unstableJorge Aparicio-0/+1
2018-05-06resolved conflict with upstream commitBrad Gibson-238/+376
2018-05-06Improve `Debug` impl of `core::time::Duration`Lukas Kalbertodt-1/+189
Prior to this, Duration simply derived Debug. Since Duration doesn't implement `Display`, the only way to inspect its value is to use `Debug`. Unfortunately, the derived `Debug` impl is far from optimal for humans. In many cases, Durations are used for some quick'n'dirty benchmarking (or in general: measuring the time of some code). Correctly understanding the output of Duration's Debug impl is not easy (e.g. is "{ secs: 0, nanos: 968360102 }" or "{ secs: 0, nanos 98507324 }" shorter?). This commit replaces the derived impl with a manual one. It prints the duration as seconds (i.e. "3.1803s") if the duration is longer than a second, otherwise it prints it in either ms, µs or ns (depending on the duration's length). This already helps readability a lot and it never omits information that is stored. This `Debug` impl does *not* respect the following formatting parameters: - fill/align/padding: difficult to implement, probably not worth it - alternate # flag: not clear what this should do
2018-05-06Added some simple documentation.kennytm-0/+8
2018-05-06Some final touches to ensure `./x.py test --stage 0 src/lib*` workskennytm-0/+3
2018-05-06Move the tests in src/libcore/slice/memchr.rs as well.kennytm-82/+86
2018-05-06Fix warning in `core::time` testsLukas Kalbertodt-4/+6
2018-05-06Move libcore/time tests from `time.rs` to `tests/time.rs`Lukas Kalbertodt-116/+123
All other tests of libcore reside in the tests/ directory, too. Apparently the tests of `time.rs` weren't run before, at least not by `x.py test src/libcore`.
2018-05-05Remove some transmutesest31-6/+4
2018-05-05Suggest more helpful formatting stringKornel-5/+6
2018-05-04Auto merge of #50398 - llogiq:memchr-nano-opt, r=nagisabors-13/+2
nano-optimization for memchr::repeat_byte This replaces the multiple shifts & bitwise or with a single multiplication In my benchmarks this performs equally well or better, especially on 64bit systems (it shaves a stable nanosecond on my skylake). This may go against conventional wisdom, but the shifts and bitwise ors cannot be pipelined because of hard data dependencies. While it may or may not be worthwile from an optimization standpoint, it also reduces code size, so there's basically no downside.
2018-05-04Rollup merge of #50406 - ExpHP:concat-nonzero-idents, r=dtolnaykennytm-2/+2
Forbid constructing empty identifiers from concat_idents The empty identifier is a [reserved identifier](https://github.com/rust-lang/rust/blob/8a37c75a3a661385cc607d934c70e86a9eaf5fd7/src/libsyntax_pos/symbol.rs#L300-L305) in rust, apparently used for black magicks like representing the crate root or somesuch... and therefore, being able to construct it is Ungood. Presumably. ...even if the macro that lets you construct it is so useless that you can't actually do any damage with it. (and believe me, I tried) Fixes #50403. **Note:** I noticed that when you try to do something similar with `proc_macro::Term`, the compiler actually catches it and flags the identifier as reserved. Perhaps a better solution would be to somehow have that same check applied here.
2018-05-03update concat_idents doc stubsMichael Lamparski-2/+2
2018-05-02Added comments providing justification for support of calling deref_* with ↵Brad Gibson-1/+5
wrong variant
2018-05-03Auto merge of #50369 - pftbest:unicode, r=SimonSapinbors-8/+8
Fix a warning in libcore on 16bit targets. This code is assuming that usize >= 32bits, but it is not the case on 16bit targets. It is producing a warning that can fail the compilation on MSP430 if deny(warnings) is enabled. It is very unlikely that someone would actually use this code on a microcontroller, but since unicode was merged into libcore we have to compile it on 16bit targets. I've tried to make sure that the code stays the same on x86, here is an assembly comparison: https://godbolt.org/g/wFw7dZ r? @SimonSapin
2018-05-02nano-optimization for memchr::repeat_byteAndre Bogus-13/+2
2018-05-01Fix a warning in libcore on 16bit targets.Vadzim Dambrouski-8/+8
This code is assuming that usize >= 32bits, but it is not the case on 16bit targets. It is producing a warning that will fail the compilation on MSP430 if deny(warnings) is enabled. It is very unlikely that someone would actually use this code on a microcontroller, but since unicode was merged into libcore we have compile it on 16bit targets.
2018-05-01Auto merge of #49724 - kennytm:range-inc-start-end-methods, r=Kimundibors-7/+82
Introduce RangeInclusive::{new, start, end} methods and make the fields private. cc #49022