rollup merge of #23549: aturon/stab-num
This commit stabilizes the `std::num` module: * The `Int` and `Float` traits are deprecated in favor of (1) the newly-added inherent methods and (2) the generic traits available in rust-lang/num. * The `Zero` and `One` traits are reintroduced in `std::num`, which together with various other traits allow you to recover the most common forms of generic programming. * The `FromStrRadix` trait, and associated free function, is deprecated in favor of inherent implementations. * A wide range of methods and constants for both integers and floating point numbers are now `#[stable]`, having been adjusted for integer guidelines. * `is_positive` and `is_negative` are renamed to `is_sign_positive` and `is_sign_negative`, in order to address #22985 * The `Wrapping` type is moved to `std::num` and stabilized; `WrappingOps` is deprecated in favor of inherent methods on the integer types, and direct implementation of operations on `Wrapping<X>` for each concrete integer type `X`. Closes #22985 Closes #21069 [breaking-change] r? @alexcrichton
This commit is contained in:
commit
5d0beb7d85
48 changed files with 997 additions and 1263 deletions
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
extern crate libc;
|
||||
|
||||
use std::num::Int;
|
||||
|
||||
struct Foo {
|
||||
x: usize,
|
||||
b: bool, //~ ERROR: struct field is never used
|
||||
|
|
|
|||
|
|
@ -15,9 +15,10 @@ pub fn main() {
|
|||
let _ = 0u32..10i32;
|
||||
//~^ ERROR start and end of range have incompatible types
|
||||
|
||||
// Float => does not implement iterator.
|
||||
for i in 0f32..42f32 {}
|
||||
//~^ ERROR the trait `core::num::Int` is not implemented for the type `f32`
|
||||
// Bool => does not implement iterator.
|
||||
for i in false..true {}
|
||||
//~^ ERROR the trait
|
||||
//~^^ ERROR the trait
|
||||
|
||||
// Unsized type.
|
||||
let arr: &[_] = &[1, 2, 3];
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@
|
|||
|
||||
#![feature(core)]
|
||||
|
||||
use std::num::Int;
|
||||
use std::ops::Add;
|
||||
|
||||
extern "C" fn foo<T: WrappingOps>(a: T, b: T) -> T { a.wrapping_add(b) }
|
||||
extern "C" fn foo<T: Add>(a: T, b: T) -> T::Output { a + b }
|
||||
|
||||
fn main() {
|
||||
assert_eq!(99u8, foo(255u8, 100u8));
|
||||
assert_eq!(99u16, foo(65535u16, 100u16));
|
||||
assert_eq!(100u8, foo(0u8, 100u8));
|
||||
assert_eq!(100u16, foo(0u16, 100u16));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue