about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2019-12-06Move numeric `From` and `TryFrom` impls to `libcore/convert/num.rs`Simon Sapin-330/+332
This makes `libcore/num/mod.rs` slightly smaller. It’s still 4911 lines and not easy to navigate. This doesn’t change any public API.
2019-12-06Add `{f32,f64}::approx_unchecked_to<Int>` unsafe methodsSimon Sapin-2/+110
As discussed in https://github.com/rust-lang/rust/issues/10184 Currently, casting a floating point number to an integer with `as` is Undefined Behavior if the value is out of range. `-Z saturating-float-casts` fixes this soundness hole by making `as` “saturate” to the maximum or minimum value of the integer type (or zero for `NaN`), but has measurable negative performance impact in some benchmarks. There is some consensus in that thread for enabling saturation by default anyway, but provide an `unsafe fn` alternative for users who know through some other mean that their values are in range.
2019-12-06Make `core::convert` a directory-module with `mod.rs`Simon Sapin-0/+0
2019-12-06Rename to `then_some` and `then`varkor-10/+10
2019-12-06Fix libcore testsvarkor-4/+4
2019-12-06Rename `bool`'s `then` to `to_option`varkor-6/+6
2019-12-06Rollup merge of #67021 - elichai:2019-12-fmt, r=QuietMisdreavusYuki Okushi-5/+6
Fix docs for formatting delegations If you use the example in the docs right now it breaks all the options Formatters have to offer. i.e. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=214392ecc6eff73b4789c32568395f72 this should've padded the output with 4 zeros but didn't. with the new example it does work: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=3bdfb29f395230c5129c5f56dcfcb2a9 The only thing i'm not quite sure about is what's the right way to do it in a loop (altough non of the docs talk about it people are doing it in the wild and there were a couple of attempts to include in libcore) i.e. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4c4dca3c90ba36779ecd014f3899ab9c
2019-12-06Rollup merge of #66764 - estebank:reword-bad-collect, r=alexcrichtonYuki Okushi-2/+2
Tweak wording of `collect()` on bad target type Fix #60440.
2019-12-05Implement core::panic::Location::caller using #[track_caller].Adam Perry-0/+55
2019-12-05Rollup merge of #67055 - lqd:const_qualif, r=oli-obkMazdak Farrokhzad-0/+2
Make const-qualification look at more `const fn`s As explained in a lot more detail in #67053 this makes const-qualification not ignore the unstable const fns in libcore. r? @oli-obk cc @ecstatic-morse (Still a bit unsure about the `cfg`s here, for bootstrapping, does that seem correct ?) Fixes #67053.
2019-12-05Rollup merge of #67005 - andrewbanchich:master, r=joshtriplettMazdak Farrokhzad-1/+1
capitalize Rust Capitalize "Rust" in docs.
2019-12-05Rollup merge of #67002 - JayXon:patch-1, r=Dylan-DPCMazdak Farrokhzad-2/+2
Fix documentation of pattern for str::matches() Made it the same as rmatches()
2019-12-05libcore: rnable 2 unstable const fn featuresRemy Rakic-0/+2
So that we can bootstrap successfully
2019-12-05Document why Pin implementations aren't derivedKonrad Borowski-0/+6
2019-12-05Use deref target in Pin trait implementationsKonrad Borowski-17/+35
Using deref target instead of pointer itself avoids providing access to `&Rc<T>` for malicious implementations, which would allow calling `Rc::get_mut`. This is a breaking change necessary due to unsoundness, however the impact of it should be minimal. This only fixes the issue with malicious `PartialEq` implementations, other `Pin` soundness issues are still here. See <https://internals.rust-lang.org/t/unsoundness-in-pin/11311/73> for more details.
2019-12-04Fix docs for formatting delegationsElichai Turkel-5/+6
2019-12-04Auto merge of #66275 - oli-obk:organize-intrinsics-promotion-checks, r=RalfJungbors-0/+1
Organize intrinsics promotion checks cc @vertexclique supersedes #61835 r? @RalfJung
2019-12-03capitalize RustAndrew Banchich-1/+1
2019-12-03Fix documentation of pattern for str::matches()Sen Jiang-2/+2
Made it the same as rmatches()
2019-12-03Tweak wording of `collect()` on bad target typeEsteban Küber-2/+2
2019-12-03Rollup merge of #66941 - CAD97:nord, r=Dylan-DPCMazdak Farrokhzad-1/+0
Remove `ord` lang item At this point it seems to be unused, and just `partial_ord` is used instead. This removes the unused lang item.
2019-12-03Rollup merge of #66651 - Areredify:on-unimplemented-scope, r=davidtwcoMazdak Farrokhzad-3/+4
Add `enclosing scope` parameter to `rustc_on_unimplemented` Adds a new parameter to `#[rustc_on_unimplemented]`, `enclosing scope`, which highlights the function or closure scope with a message. The wip part refers to adding this annotation to `Try` trait to improve ergonomics (which I don't know how to do since I change both std and librustc) Closes #61709.
2019-12-03Check intrinsics for callability in const fnsMahmut Bulut-0/+1
2019-12-03Auto merge of #66256 - CAD97:patch-2, r=RalfJungbors-6/+7
Layout::pad_to_align is infallible As per [this comment](https://github.com/rust-lang/rust/issues/55724#issuecomment-441421651) (cc @glandium). > Per https://github.com/rust-lang/rust/blob/eb981a1/src/libcore/alloc.rs#L63-L65, `layout.size()` is always <= `usize::MAX - (layout.align() - 1)`. > > Which means: > > * The maximum value `layout.size()` can have is already aligned for `layout.align()` (`layout.align()` being a power of two, `usize::MAX - (layout.align() - 1)` is a multiple of `layout.align()`) > * Incidentally, any value smaller than that maximum value will align at most to that maximum value. > > IOW, `pad_to_align` can not return `Err(LayoutErr)`, except for the layout not respecting its invariants, but we shouldn't care about that. This PR makes `pad_to_align` return `Layout` directly, representing the fact that it cannot fail.
2019-12-02Document usage of unsafe blockKrishna Sai Veera Reddy-0/+1
2019-12-02Rollup merge of #66822 - RalfJung:miri-panic, r=oli-obkRalf Jung-1/+3
libunwind_panic: adjust miri panic hack We adjust the Miri hack in libpanic_unwind such that even with `cfg(miri)`, we build a version of libpanic_unwind that actually works. This is needed to resolve https://github.com/integer32llc/rust-playground/issues/548. r? @oli-obk @alexcrichton
2019-12-02stabilize Result::map_orLzu Tao-2/+1
2019-12-01Remove ord lang itemcad97-1/+0
2019-11-30Rollup merge of #66894 - dtolnay:prelude, r=CentrilMazdak Farrokhzad-3/+0
Remove unneeded prelude imports in libcore tests These three lines are from c82da7a54b9efb1a0ccbe11de66c71f547bf7db9 dating back to 2015. They cause problems when applying rustfmt to the codebase, because reordering wildcard imports can trigger new unused import warnings. As a minimized example, the following program compiles successfully: ```rust #![deny(unused_imports)] use std::fmt::Debug; use std::marker::Send; pub mod repro { use std::prelude::v1::*; use super::*; pub type D = dyn Debug; pub type S = dyn Send; } pub type S = dyn Send; ``` but putting it through rustfmt produces a program that fails to compile: ```rust #![deny(unused_imports)] use std::fmt::Debug; use std::marker::Send; pub mod repro { use super::*; use std::prelude::v1::*; pub type D = dyn Debug; pub type S = dyn Send; } pub type S = dyn Send; ``` The error is: ```console error: unused import: `std::prelude::v1::*` --> src/main.rs:8:9 | 8 | use std::prelude::v1::*; | ^^^^^^^^^^^^^^^^^^^ ```
2019-11-30Rollup merge of #66889 - dtolnay:fmt6, r=rkruppeMazdak Farrokhzad-1258/+1278
Make python-generated source files compatible with rustfmt This PR adjusts the generators for src/libcore/num/dec2flt/table.rs, src/libcore/unicode/printable.rs, and src/libcore/unicode/tables.rs to make it so running `rustfmt` on the generated files no longer needs to apply any changes. This involves tweaking the python scripts where reasonable to better match rustfmt's style, and adding `#[rustfmt::skip]` to big constant tables that there's no point having rustfmt rewrap. r? @Dylan-DPC
2019-11-30Rollup merge of #66705 - pitdicker:atomic_mut_ptr, r=KodrAusMazdak Farrokhzad-0/+74
Atomic as_mut_ptr I encountered the following pattern a few times: In Rust we use some atomic type like `AtomicI32`, and an FFI interface exposes this as `*mut i32` (or some similar `libc` type). It was not obvious to me if a just transmuting a pointer to the atomic was acceptable, or if this should use a cast that goes through an `UnsafeCell`. See https://github.com/rust-lang/rust/issues/66136#issuecomment-557802477 Transmuting the pointer directly: ```rust let atomic = AtomicI32::new(1); let ptr = &atomic as *const AtomicI32 as *mut i32; unsafe { ffi(ptr); } ``` A dance with `UnsafeCell`: ```rust let atomic = AtomicI32::new(1); unsafe { let ptr = (&*(&atomic as *const AtomicI32 as *const UnsafeCell<i32>)).get(); ffi(ptr); } ``` Maybe in the end both ways could be valid. But why not expose a direct method to get a pointer from the standard library? An `as_mut_ptr` method on atomics can be safe, because only the use of the resulting pointer is where things can get unsafe. I documented its use for FFI, and "Doing non-atomic reads and writes on the resulting integer can be a data race." The standard library could make use this method in a few places in the WASM module. cc @RalfJung as you answered my original question.
2019-11-30Fill tracking issuePaul Dicker-2/+2
2019-11-30Document why as_mut_ptr is safePaul Dicker-0/+12
2019-11-30libunwind_panic: adjust miri panic hackRalf Jung-1/+3
2019-11-29Remove unneeded prelude imports in libcore testsDavid Tolnay-3/+0
These three lines are from c82da7a54b9efb1a0ccbe11de66c71f547bf7db9 in 2015. They cause problems when applying rustfmt to the codebase, because reordering wildcard imports can trigger new unused import warnings. As a minimized example, the following program compiles successfully: #![deny(unused_imports)] use std::fmt::Debug; use std::marker::Send; pub mod repro { use std::prelude::v1::*; use super::*; pub type D = dyn Debug; pub type S = dyn Send; } pub type S = dyn Send; but putting it through rustfmt produces a program that fails to compile: #![deny(unused_imports)] use std::fmt::Debug; use std::marker::Send; pub mod repro { use super::*; use std::prelude::v1::*; pub type D = dyn Debug; pub type S = dyn Send; } pub type S = dyn Send; The error is: error: unused import: `std::prelude::v1::*` --> src/main.rs:8:9 | 8 | use std::prelude::v1::*; | ^^^^^^^^^^^^^^^^^^^
2019-11-29Make libcore/unicode/tables.rs compatible with rustfmtDavid Tolnay-29/+36
2019-11-29Make libcore/unicode/printable.rs compatible with rustfmtDavid Tolnay-4/+11
2019-11-29Make dec2flt_table compatible with rustfmtDavid Tolnay-1225/+1231
2019-11-29Optimize Ord trait implementation for boolKrishna Sai Veera Reddy-1/+18
Casting the booleans to `i8`s and converting their difference into `Ordering` generates better assembly than casting them to `u8`s and comparing them.
2019-11-29Rollup merge of #66872 - Mikotochan:patch-1, r=jonas-schievinkRalf Jung-1/+1
Minor documentation fix Fixed the documentation for any as is a trait rather than a type.
2019-11-29Rollup merge of #66837 - ohadravid:epsilon-doc, r=dtolnayRalf Jung-2/+2
Clarify `{f32,f64}::EPSILON` docs The doc for `EPSILON` says: > This is the difference between `1.0` and the next **largest** representable number. Which is a bit unclear. [Wikipedia](https://en.wikipedia.org/wiki/Machine_epsilon) says > Machine epsilon is defined as the difference between 1 and the next **larger** floating point number So this PR update the docs to match the Wikipedia version. The original PR also has this in a [comment](https://github.com/rust-lang/rust/pull/50919#discussion_r192600209).
2019-11-29Rollup merge of #66766 - RalfJung:panic-comments, r=SimonSapinRalf Jung-5/+16
Panic machinery comments and tweaks This is mostly more comments, but I also renamed some things: * `BoxMeUp::box_me_up` is not terribly descriptive, and since this is a "take"-style method (the argument is `&mut self` but the return type is fully owned, even though you can't tell from the type) I chose a name involving "take". * `continue_panic_fmt` was very confusing as it was entirely unclear what was being continued -- for some time I thought "continue" might be the same as "resume" for a panic, but that's something entirely different. So I renamed this to `begin_panic_handler`, matching the `begin_panic*` theme of the other entry points. r? @Dylan-DPC @SimonSapin
2019-11-29Rollup merge of #66379 - CreepySkeleton:patch-1, r=RalfJungRalf Jung-14/+24
Rephrase docs in for ptr These methods can be supplied with NULL just fine, this is the whole point of `Option<&T>` return type.
2019-11-29Minor documentation fixMikotochan-1/+1
Fixed the documentation for any as is a trait rather than a type.
2019-11-28Clarify `{f32,f64}::EPSILON` docsOhad Ravid-2/+2
2019-11-28Auto merge of #65013 - petertodd:2019-maybeuninit-debug, r=sfacklerbors-0/+9
Implement Debug for MaybeUninit Precedent: `UnsafeCell` implements `Debug` even though it can't actually display the value. I noticed this omission while writing the following: ``` #[derive(Debug)] pub struct SliceInitializer<'a, T> { marker: PhantomData<&'a mut T>, uninit: &'a mut [MaybeUninit<T>], written: usize, } ``` ...which currently unergonomically fails to compile. `UnsafeCell` does require `T: Debug`. Because of things like the above I think it'd be better to leave that requirement off. In fact, I'd also suggest removing that requirement for `UnsafeCell` too, which again I noticed in some low-level real world code.
2019-11-27Rollup merge of #66798 - bwignall:typo, r=varkorTyler Mandry-2/+2
Fix spelling typos Should be non-semantic. Uses https://en.wikipedia.org/wiki/Wikipedia:Lists_of_common_misspellings/For_machines to find likely typos.
2019-11-27Rollup merge of #66797 - mlodato517:mlodato517-array-doc-typo, r=Dylan-DPCTyler Mandry-1/+1
Fixes small typo in array docs r? @steveklabnik Fixes a small typo in the array documentation. Also, wasn't sure which [message](https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#pull-requests) to put this in, and will definitely update the commit message if it is supposed to be the PR description but for "safety" - r? @steveklabnik
2019-11-27Rollup merge of #66769 - fusion-engineering-forks:tau-constant, r=dtolnayTyler Mandry-0/+12
Add core::{f32,f64}::consts::TAU. ### **`τ`**
2019-11-27Use intra-doc linksCreepySkeleton-2/+2