about summary refs log tree commit diff
path: root/src/libcore/num
AgeCommit message (Collapse)AuthorLines
2015-03-25Change lint names to pluralsNick Cameron-13/+13
2015-03-25Add trivial cast lints.Nick Cameron-0/+13
This permits all coercions to be performed in casts, but adds lints to warn in those cases. Part of this patch moves cast checking to a later stage of type checking. We acquire obligations to check casts as part of type checking where we previously checked them. Once we have type checked a function or module, then we check any cast obligations which have been acquired. That means we have more type information available to check casts (this was crucial to making coercions work properly in place of some casts), but it means that casts cannot feed input into type inference. [breaking change] * Adds two new lints for trivial casts and trivial numeric casts, these are warn by default, but can cause errors if you build with warnings as errors. Previously, trivial numeric casts and casts to trait objects were allowed. * The unused casts lint has gone. * Interactions between casting and type inference have changed in subtle ways. Two ways this might manifest are: - You may need to 'direct' casts more with extra type information, for example, in some cases where `foo as _ as T` succeeded, you may now need to specify the type for `_` - Casts do not influence inference of integer types. E.g., the following used to type check: ``` let x = 42; let y = &x as *const u32; ``` Because the cast would inform inference that `x` must have type `u32`. This no longer applies and the compiler will fallback to `i32` for `x` and thus there will be a type error in the cast. The solution is to add more type information: ``` let x: u32 = 42; let y = &x as *const u32; ```
2015-03-23Add #![feature] attributes to doctestsBrian Anderson-2/+26
2015-03-20Auto merge of #23254 - jbcrail:saturating-math-docs, r=steveklabnikbors-0/+20
This was added for #23241.
2015-03-18Register new snapshotsAlex Crichton-974/+954
2015-03-17Rollup merge of #23385 - tamird:cleanup-whitespace, r=alexcrichtonManish Goregaokar-1/+0
r? @alexcrichton Conflicts: src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs
2015-03-17Rollup merge of #23329 - jbcrail:rm-syntax-highlight, r=sanxiynManish Goregaokar-18/+18
As suggested by @steveklabnik in #23254, I removed the redundant Rust syntax highlighting from the documentation.
2015-03-16impl {i,u}{8,16,32,64,size}Jorge Aparicio-0/+990
2015-03-15Strip all leading/trailing newlinesTamir Duberstein-1/+0
2015-03-13Remove explicit syntax highlight from docs.Joseph Crail-18/+18
2015-03-11Example -> ExamplesSteve Klabnik-17/+17
This brings comments in line with https://github.com/rust-lang/rfcs/blob/master/text/0505-api-comment-conventions.md#using-markdown
2015-03-11Add docs for saturating integer arithmetic.Joseph Crail-0/+20
This was added for #23241.
2015-03-09Auto merge of #23219 - Manishearth:rollup, r=Manishearthbors-1/+1
2015-03-08Register new snapshots (270a677)Manish Goregaokar-22/+0
2015-03-07indicate from_str_radix is codeFuGangqiang-1/+1
2015-03-06Add #[allow_internal_unstable] to track stability for macros better.Huon Wilson-0/+2
Unstable items used in a macro expansion will now always trigger stability warnings, *unless* the unstable items are directly inside a macro marked with `#[allow_internal_unstable]`. IOW, the compiler warns unless the span of the unstable item is a subspan of the definition of a macro marked with that attribute. E.g. #[allow_internal_unstable] macro_rules! foo { ($e: expr) => {{ $e; unstable(); // no warning only_called_by_foo!(); }} } macro_rules! only_called_by_foo { () => { unstable() } // warning } foo!(unstable()) // warning The unstable inside `foo` is fine, due to the attribute. But the `unstable` inside `only_called_by_foo` is not, since that macro doesn't have the attribute, and the `unstable` passed into `foo` is also not fine since it isn't contained in the macro itself (that is, even though it is only used directly in the macro). In the process this makes the stability tracking much more precise, e.g. previously `println!("{}", unstable())` got no warning, but now it does. As such, this is a bug fix that may cause [breaking-change]s. The attribute is definitely feature gated, since it explicitly allows side-stepping the feature gating system.
2015-03-03Accommodate arith-overflow in `core::num`, `std::num`, `coretest::num`.Felix S. Klock II-6/+22
* `core::num`: adjust `UnsignedInt::is_power_of_two`, `UnsignedInt::next_power_of_two`, `Int::pow`. In particular for `Int::pow`: (1.) do not panic when `base` overflows if `acc` never observes the overflowed `base`, and (2.) if `acc` does observe the overflowed `base`, make sure we only panic if we would have otherwise (e.g. during a computation of `base * base`). * also in `core::num`: avoid underflow during computation of `uint::MAX`. * `std::num`: adjust tests `uint::test_uint_from_str_overflow`, `uint::test_uint_to_str_overflow`, `strconv` * `coretest::num`: adjust `test::test_int_from_str_overflow`.
2015-03-03Added `OverflowingOps` trait to core::num::wrapping.Felix S. Klock II-0/+147
These return the result of the operation *plus* an overflow/underflow bit. This can make it easier to write operations where you want to chain some arithmetic together, but also want to return a flag signalling if overflow every occurred.
2015-03-03Add `core::num::wrapping` and fix overflow errors.James Miller-0/+156
Many of the core rust libraries have places that rely on integer wrapping behaviour. These places have been altered to use the wrapping_* methods: * core::hash::sip - A number of macros * core::str - The `maximal_suffix` method in `TwoWaySearcher` * rustc::util::nodemap - Implementation of FnvHash * rustc_back::sha2 - A number of macros and other places * rand::isaac - Isaac64Rng, changed to use the Wrapping helper type Some places had "benign" underflow. This is when underflow or overflow occurs, but the unspecified value is not used due to other conditions. * collections::bit::Bitv - underflow when `self.nbits` is zero. * collections::hash::{map,table} - Underflow when searching an empty table. Did cause undefined behaviour in this case due to an out-of-bounds ptr::offset based on the underflowed index. However the resulting pointers would never be read from. * syntax::ext::deriving::encodable - Underflow when calculating the index of the last field in a variant with no fields. These cases were altered to avoid the underflow, often by moving the underflowing operation to a place where underflow could not happen. There was one case that relied on the fact that unsigned arithmetic and two's complement arithmetic are identical with wrapping semantics. This was changed to use the wrapping_* methods. Finally, the calculation of variant discriminants could overflow if the preceeding discriminant was `U64_MAX`. The logic in `rustc::middle::ty` for this was altered to avoid the overflow completely, while the remaining places were changed to use wrapping methods. This is because `rustc::middle::ty::enum_variants` now throws an error when the calculated discriminant value overflows a `u64`. This behaviour can be triggered by the following code: ``` enum Foo { A = U64_MAX, B } ``` This commit also implements the remaining integer operators for Wrapped<T>.
2015-03-02core: Audit num module for int/uintBrian Anderson-55/+115
* count_ones/zeros, trailing_ones/zeros return u32, not usize * rotate_left/right take u32, not usize * RADIX, MANTISSA_DIGITS, DIGITS, BITS, BYTES are u32, not usize Doesn't touch pow because there's another PR for it. [breaking-change]
2015-03-02Rollup merge of #22504 - GuillaumeGomez:audit-integer-libcore, r=ManishearthManish Goregaokar-41/+0
Part of #22240.
2015-03-01Fix errors, remove unused filesGuillaumeGomez-41/+0
2015-03-01Make Int::pow() take exp as u32 instead usizeGuillaume Gomez-1/+2
2015-02-24Stop parsing "-" as integer, fixes #22745Michał Krasnoborski-0/+1
2015-02-15Rollup merge of #22339 - petrochenkov:int, r=huonwManish Goregaokar-4/+4
Some function signatures have changed, so this is a [breaking-change]. In particular, radixes and numerical values of digits are represented by `u32` now. Part of #22240
2015-02-15Fix the falloutVadim Petrochenkov-4/+4
2015-02-13Remove `_VALUE` from the float extremes constants.Huon Wilson-11/+37
In `std::f32` and `std::f64`: - `MIN_VALUE` → `MIN` - `MAX_VALUE` → `MAX` - `MIN_POS_VALUE` → `MIN_POSITIVE` This matches the corresponding integer constants. [breaking-change]
2015-01-30Test fixes and rebase conflictsAlex Crichton-4/+4
Also some tidying up of a bunch of crate attributes
2015-01-30rollup merge of #21718: alexcrichton/stabilize-from-strAlex Crichton-51/+123
This commits adds an associated type to the `FromStr` trait representing an error payload for parses which do not succeed. The previous return value, `Option<Self>` did not allow for this form of payload. After the associated type was added, the following attributes were applied: * `FromStr` is now stable * `FromStr::Err` is now stable * `FromStr::from_str` is now stable * `StrExt::parse` is now stable * `FromStr for bool` is now stable * `FromStr for $float` is now stable * `FromStr for $integral` is now stable * Errors returned from stable `FromStr` implementations are stable * Errors implement `Display` and `Error` (both impl blocks being `#[stable]`) Closes #15138
2015-01-30std: Stabilize FromStr and parseAlex Crichton-51/+123
This commits adds an associated type to the `FromStr` trait representing an error payload for parses which do not succeed. The previous return value, `Option<Self>` did not allow for this form of payload. After the associated type was added, the following attributes were applied: * `FromStr` is now stable * `FromStr::Err` is now stable * `FromStr::from_str` is now stable * `StrExt::parse` is now stable * `FromStr for bool` is now stable * `FromStr for $float` is now stable * `FromStr for $integral` is now stable * Errors returned from stable `FromStr` implementations are stable * Errors implement `Display` and `Error` (both impl blocks being `#[stable]`) Closes #15138
2015-01-30fix falloutJorge Aparicio-2/+2
2015-01-29s/Show/Debug/gJorge Aparicio-1/+1
2015-01-25Merge remote-tracking branch 'rust-lang/master'Brian Anderson-10/+10
Conflicts: src/libcore/cmp.rs src/libcore/fmt/mod.rs src/libcore/iter.rs src/libcore/marker.rs src/libcore/num/f32.rs src/libcore/num/f64.rs src/libcore/result.rs src/libcore/str/mod.rs src/librustc/lint/builtin.rs src/librustc/lint/context.rs src/libstd/sync/mpsc/mod.rs src/libstd/sync/poison.rs
2015-01-25Moving away from deprecated i/u suffixes in libcoreAlfie John-10/+10
2015-01-23grandfathered -> rust1Brian Anderson-59/+59
2015-01-23Deprecated attributes don't take 'feature' names and are paired with ↵Brian Anderson-32/+64
stable/unstable Conflicts: src/libcore/atomic.rs src/libcore/finally.rs src/test/auxiliary/inherited_stability.rs src/test/auxiliary/lint_stability.rs
2015-01-23Set unstable feature names appropriatelyBrian Anderson-57/+57
* `core` - for the core crate * `hash` - hashing * `io` - io * `path` - path * `alloc` - alloc crate * `rand` - rand crate * `collections` - collections crate * `std_misc` - other parts of std * `test` - test crate * `rustc_private` - everything else
2015-01-21Remove 'since' from unstable attributesBrian Anderson-57/+57
2015-01-21Add 'feature' and 'since' to stability attributesBrian Anderson-148/+178
2015-01-17Register new snapshots.Eduard Burtescu-13/+8
2015-01-08Improvements to feature stagingBrian Anderson-22/+22
This gets rid of the 'experimental' level, removes the non-staged_api case (i.e. stability levels for out-of-tree crates), and lets the staged_api attributes use 'unstable' and 'deprecated' lints. This makes the transition period to the full feature staging design a bit nicer.
2015-01-07Test fixes and rebase conflictsAlex Crichton-2/+6
2015-01-07rollup merge of #20721: japaric/snapAlex Crichton-2/+2
Conflicts: src/libcollections/vec.rs src/libcore/fmt/mod.rs src/librustc/lint/builtin.rs src/librustc/session/config.rs src/librustc_trans/trans/base.rs src/librustc_trans/trans/context.rs src/librustc_trans/trans/type_.rs src/librustc_typeck/check/_match.rs src/librustdoc/html/format.rs src/libsyntax/std_inject.rs src/libsyntax/util/interner.rs src/test/compile-fail/mut-pattern-mismatched.rs
2015-01-07rollup merge of #20708: aturon/new-int-modulesAlex Crichton-6/+53
Conflicts: src/libserialize/lib.rs
2015-01-07use slicing sugarJorge Aparicio-2/+2
2015-01-08Rename `target_word_size` to `target_pointer_width`Nick Cameron-6/+9
Closes #20421 [breaking-change]
2015-01-07Add isize, usize modules, deprecate int, uint modulesAaron Turon-6/+53
This PR introduces `isize` and `usize` modules to `core` and `std`, and deprecates the existing `int` and `uint` modules. The rustdoc primitive type links now point to these new modules. Due to deprecation this is a: [breaking-change]
2015-01-06rollup merge of #20607: nrc/kindsAlex Crichton-2/+2
Conflicts: src/libcore/array.rs src/libcore/cell.rs src/libcore/prelude.rs src/libstd/path/posix.rs src/libstd/prelude/v1.rs src/test/compile-fail/dst-sized-trait-param.rs
2015-01-07markers -> markerNick Cameron-2/+2
2015-01-07Replace full slice notation with index callsNick Cameron-2/+2