summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2018-05-21Add doc comments mentioning unspecified behaviour upon exhaustionvarkor-1/+10
2018-05-21Stabilise into_innervarkor-0/+13
2018-05-21Stabilise inclusive_range_methodsvarkor-11/+3
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-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-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
2018-04-30Auto merge of #48925 - zackmdavis:fn_must_stabilize, r=nikomatsakisbors-1/+1
stabilize `#[must_use]` for functions and must-use comparison operators (RFC 1940) r? @nikomatsakis
2018-05-01new() should be const; start()/end() after iteration is unspecified.kennytm-1/+17
2018-05-01Removed direct field usage of RangeInclusive in rustc itself.kennytm-5/+6
2018-05-01Rollup merge of #50316 - ehuss:fix-doc-links, r=frewsxcvkennytm-0/+4
Fix some broken links in docs.
2018-05-01Rollup merge of #50233 - mark-i-m:const_vec, r=kennytmkennytm-3/+2
Make `Vec::new` a `const fn` `RawVec::empty/_in` are a hack. They're there because `if size_of::<T> == 0 { !0 } else { 0 }` is not allowed in `const` yet. However, because `RawVec` is unstable, the `empty/empty_in` constructors can be removed when #49146 is done...
2018-04-30Make the fields of RangeInclusive private.kennytm-2/+60
Added new()/start()/end() methods to RangeInclusive. Changed the lowering of `..=` to use RangeInclusive::new().
2018-04-29Fix some broken links in docs.Eric Huss-0/+4
2018-04-29Auto merge of #50217 - z4v1er:patch-1, r=aturonbors-1/+0
Fix typo
2018-04-28stabilize `#[must_use]` for functions and must-use operatorsZack M. Davis-1/+1
This is in the matter of RFC 1940 and tracking issue #43302.
2018-04-28Auto merge of #50149 - aaronaaeng:master, r=estebankbors-0/+13
Added warning for unused arithmetic expressions The compiler now displays a warning when a binary arithmetic operation is evaluated but not used. This resolves #50124 by following the instructions outlined in the issue. The changes are as follows: - Added new pattern matching for unused arithmetic expressions in `src/librustc_lint/unused.rs` - Added `#[must_use]` attributes to the binary operation methods in `src/libcore/internal_macros.rs` - Added `#[must_use]` attributes to the non-assigning binary operators in `src/libcore/ops/arith.rs`
2018-04-28Rollup merge of #49858 - dmizuk:unique-doc-hidden, r=steveklabnikkennytm-0/+1
std: Mark `ptr::Unique` with `#[doc(hidden)]` `Unique` is now perma-unstable, so let's hide its docs.
2018-04-26Add more doc aliasesGuillaume Gomez-0/+33
2018-04-25Make Vec::new constMark Mansi-3/+2
2018-04-25Fix typez4v1er-1/+0
2018-04-24Rollup merge of #50185 - dmizuk:mod_euc-fix-overflow, r=kennytmkennytm-1/+11
core: Fix overflow in `int::mod_euc` when `self < 0 && rhs == MIN` This commit removes usage of `abs`, which overflows when `self == MIN`.
2018-04-24Rollup merge of #49970 - SimonSapin:deprecate, r=sfacklerkennytm-0/+15
Deprecate Read::chars and char::decode_utf8 Per FCP: * https://github.com/rust-lang/rust/issues/27802#issuecomment-377537778 * https://github.com/rust-lang/rust/issues/33906#issuecomment-377534308
2018-04-24Rollup merge of #49906 - kennytm:stable-unreachable, r=sfacklerkennytm-16/+69
Stabilize `std::hint::unreachable_unchecked`. Closes #43751.
2018-04-24Rollup merge of #49727 - stjepang:cell-update, r=SimonSapinkennytm-0/+39
Add Cell::update This commit adds a new method `Cell::update`, which applies a function to the value inside the cell. Previously discussed in: https://github.com/rust-lang/rfcs/issues/2171 ### Motivation Updating `Cell`s is currently a bit verbose. Here are several real examples (taken from rustc and crossbeam): ```rust self.print_fuel.set(self.print_fuel.get() + 1); self.diverges.set(self.diverges.get() | Diverges::Always); let guard_count = self.guard_count.get(); self.guard_count.set(guard_count.checked_add(1).unwrap()); if guard_count == 0 { // ... } ``` With the addition of the new method `Cell::update`, this code can be simplified to: ```rust self.print_fuel.update(|x| x + 1); self.diverges.update(|x| x | Diverges::Always); if self.guard_count.update(|x| x.checked_add(1).unwrap()) == 1 { // ... } ``` ### Unresolved questions 1. Should we return the old value instead of the new value (like in `fetch_add` and `fetch_update`)? 2. Should the return type simply be `()`? 3. Naming: `update` vs `modify` vs `mutate` etc. cc @SimonSapin
2018-04-23Assign the tracking issueStjepan Glavina-1/+1
2018-04-24core: Minor cleanupDaiki Mizukami-1/+1
2018-04-23Clarify the docs for Cell::updateStjepan Glavina-2/+3
2018-04-24core: Fix overflow in `int::mod_euc` when `self < 0 && rhs == MIN`Daiki Mizukami-1/+11
2018-04-22Make must_use lint cover all binary/unary operatorsAaron Aaeng-0/+13
2018-04-22Remove Alloc::oomSteven Fackler-26/+0
2018-04-22Replace GlobalAlloc::oom with a lang itemSteven Fackler-11/+0
2018-04-22Auto merge of #50109 - SimonSapin:copy, r=sfacklerbors-1/+1
Implement Copy for std::alloc::Layout Fixes https://github.com/rust-lang/rust/issues/48458
2018-04-22Auto merge of #49757 - GuillaumeGomez:never-search, r=QuietMisdreavusbors-0/+25
Add specific never search Fixes #49529. r? @QuietMisdreavus
2018-04-22Auto merge of #49896 - SimonSapin:inherent, r=alexcrichtonbors-112/+3838
Add inherent methods in libcore for [T], [u8], str, f32, and f64 # Background Primitive types are defined by the language, they don’t have a type definition like `pub struct Foo { … }` in any crate. So they don’t “belong” to any crate as far as `impl` coherence is concerned, and on principle no crate would be able to define inherent methods for them, without a trait. Since we want these types to have inherent methods anyway, the standard library (with cooperation from the compiler) bends this rule with code like [`#[lang = "u8"] impl u8 { /*…*/ }`](https://github.com/rust-lang/rust/blob/1.25.0/src/libcore/num/mod.rs#L2244-L2245). The `#[lang]` attribute is permanently-unstable and never intended to be used outside of the standard library. Each lang item can only be defined once. Before this PR there is one impl-coherence-rule-bending lang item per primitive type (plus one for `[u8]`, which overlaps with `[T]`). And so one `impl` block each. These blocks for `str`, `[T]` and `[u8]` are in liballoc rather than libcore because *some* of the methods (like `<[T]>::to_vec(&self) -> Vec<T> where T: Clone`) need a global memory allocator which we don’t want to make a requirement in libcore. Similarly, `impl f32` and `impl f64` are in libstd because some of the methods are based on FFI calls to C’s `libm` and we want, as much as possible, libcore not to require “runtime support”. In libcore, the methods of `str` and `[T]` that don’t allocate are made available through two **unstable traits** `StrExt` and `SliceExt` (so the traits can’t be *named* by programs on the Stable release channel) that have **stable methods** and are re-exported in the libcore prelude (so that programs on Stable can *call* these methods anyway). Non-allocating `[u8]` methods are not available in libcore: https://github.com/rust-lang/rust/issues/45803. Some `f32` and `f64` methods are in an unstable `core::num::Float` trait with stable methods, but that one is **not in the libcore prelude**. (So as far as Stable programs are concerns it doesn’t exist, and I don’t know what the point was to mark these methods `#[stable]`.) https://github.com/rust-lang/rust/issues/32110 is the tracking issue for these unstable traits. # High-level proposal Since the standard library is already bending the rules, why not bend them *a little more*? By defining a few additional lang items, the compiler can allow the standard library to have *two* `impl` blocks (in different crates) for some primitive types. The `StrExt` and `SliceExt` traits still exist for now so that we can bootstrap from a previous-version compiler that doesn’t have these lang items yet, but they can be removed in next release cycle. (`Float` is used internally and needs to be public for libcore unit tests, but was already `#[doc(hidden)]`.) I don’t know if https://github.com/rust-lang/rust/issues/32110 should be closed by this PR, or only when the traits are entirely removed after we make a new bootstrap compiler. # Float methods Among the methods of the `core::num::Float` trait, three are based on LLVM intrinsics: `abs`, `signum`, and `powi`. PR https://github.com/rust-lang/rust/pull/27823 “Remove dependencies on libm functions from libcore” moved a bunch of `core::num::Float` methods back to libstd, but left these three behind. However they aren’t specifically discussed in the PR thread. The `compiler_builtins` crate defines `__powisf2` and `__powidf2` functions that look like implementations of `powi`, but I couldn’t find a connection with the `llvm.powi.f32` and `llvm.powi.f32` intrinsics by grepping through LLVM’s code. In discussion starting at https://github.com/rust-lang/rust/issues/32110#issuecomment-370647922 Alex says that we do not want methods in libcore that require “runtime support”, but it’s not clear whether that applies to these `abs`, `signum`, or `powi`. In doubt, I’ve **removed** them for the trait and moved them to inherent methods in libstd for now. We can move them back later (or in this PR) if we decide that’s appropriate. # Change details For users on the Stable release channel: * I believe this PR does not make any breaking change * Some methods for `[u8]`, `f32`, and `f64` are newly available to `#![no_std]` users (fixes https://github.com/rust-lang/rust/issues/45803) * There should be no visible change for `std` users in terms of what programs compile or what their behavior is. (Only in compiler error messages, possibly.) For Nightly users, additionally: * The unstable `StrExt` and `SliceExt` traits are gone * Their methods are now inherent methods of `str` and `[T]` (so only code that explicitly named the traits should be affected, not "normal" method calls) * The `abs`, `signum` and `powi` methods of the `Float` trait are gone * The `Float` trait’s unstable feature name changed to `float_internals` with no associated tracking issue, to reflect it being a permanently unstable implementation detail rather than a public API on a path to stabilization. * Its remaining methods are now inherent methods of `f32` and `f64`. ----- CC @rust-lang/libs for the API changes, @rust-lang/compiler for the new lang items
2018-04-21Auto merge of #50121 - pnkfelix:revert-stabilization-of-never-type-et-al, ↵bors-29/+27
r=alexcrichton Revert stabilization of never_type (!) et al Fix #49691 I *think* this correctly adopts @nikomatsakis 's desired fix of: * reverting stabilization of `!` and `TryFrom`, and * returning to the previous fallback semantics (i.e. it is once again dependent on whether the crate has opted into `#[feature(never_type)]`, * **without** attempting to put back in the previous future-proofing warnings regarding the change in fallback semantics. (I'll be away from computers for a week starting now, so any updates to this PR should be either pushed into it, or someone else should adopt the task of polishing this fix and put up their own PR.)
2018-04-21add more aliasesGuillaume Gomez-0/+25
2018-04-21Auto merge of #50039 - ExpHP:quick-50002, r=alexcrichtonbors-7/+2
smaller PR just to fix #50002 I pulled this out of #50010 to make it easier to backport to beta if necessary, considering that inclusive range syntax is stabilizing soon (?). It fixes a bug in `<str>::index_mut` with `(..=end)` ranges (#50002), which prior to this fix was not only unusable but also UB in the cases where it "worked" (it gave improperly truncated UTF-8). (not that I can imagine why anybody would *use* `<str>::index_mut`... but I'm not here to judge)
2018-04-21Make the unstable StrExt and SliceExt traits private to libcore in not(stage0)Simon Sapin-24/+36
`Float` still needs to be public for libcore unit tests.
2018-04-21Move intrinsics-based float methods out of libcore into libstdSimon Sapin-72/+0
Affected methods are `abs`, `signum`, and `powi`. CC https://github.com/rust-lang/rust/issues/32110#issuecomment-379503183
2018-04-21Add some f32 and f64 inherent methods in libcoreSimon Sapin-1/+580
… previously in the unstable core::num::Float trait. Per https://github.com/rust-lang/rust/issues/32110#issuecomment-379503183, the `abs`, `signum`, and `powi` methods are *not* included for now since they rely on LLVM intrinsics and we haven’t determined yet whether those instrinsics lower to calls to libm functions on any platform.