diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-31 10:15:26 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-31 10:15:26 -0700 |
| commit | 5d0beb7d85e8e711334c7fb6f2c5da270e5200cb (patch) | |
| tree | cd6181ba8612c9233c3a47aaf5e956a5610c348e /src/libsyntax | |
| parent | b3317d68910900f135f9f38e43a7a699bc736b4a (diff) | |
| parent | 232424d9952700682373ccf2d578109f401ff023 (diff) | |
| download | rust-5d0beb7d85e8e711334c7fb6f2c5da270e5200cb.tar.gz rust-5d0beb7d85e8e711334c7fb6f2c5da270e5200cb.zip | |
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
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 11 |
3 files changed, 11 insertions, 9 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f815e8e7843..ce1539c62f8 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -66,6 +66,7 @@ use parse::lexer; use ptr::P; use std::fmt; +#[allow(deprecated)] use std::num::Int; use std::rc::Rc; use serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -1141,6 +1142,7 @@ pub enum Sign { } impl Sign { + #[allow(deprecated)] // Int pub fn new<T:Int>(n: T) -> Sign { if n < Int::zero() { Minus diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 532b632fac8..bcb265af926 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -20,7 +20,6 @@ use std::borrow::{IntoCow, Cow}; use std::char; use std::fmt; use std::mem::replace; -use std::num; use std::rc::Rc; pub use ext::tt::transcribe::{TtReader, new_tt_reader, new_tt_reader_with_doc_flag}; @@ -622,8 +621,8 @@ impl<'a> StringReader<'a> { // find the integer representing the name self.scan_digits(base); - let encoded_name : u32 = self.with_str_from(start_bpos, |s| { - num::from_str_radix(s, 10).unwrap_or_else(|_| { + let encoded_name: u32 = self.with_str_from(start_bpos, |s| { + u32::from_str_radix(s, 10).unwrap_or_else(|_| { panic!("expected digits representing a name, got {:?}, {}, range [{:?},{:?}]", s, whence, start_bpos, self.last_pos); }) @@ -641,7 +640,7 @@ impl<'a> StringReader<'a> { let start_bpos = self.last_pos; self.scan_digits(base); let encoded_ctxt : ast::SyntaxContext = self.with_str_from(start_bpos, |s| { - num::from_str_radix(s, 10).unwrap_or_else(|_| { + u32::from_str_radix(s, 10).unwrap_or_else(|_| { panic!("expected digits representing a ctxt, got {:?}, {}", s, whence); }) }); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index bea42a88bf5..544862a374a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -21,6 +21,7 @@ use std::cell::{Cell, RefCell}; use std::fs::File; use std::io::Read; use std::iter; +#[allow(deprecated)] // Int use std::num::Int; use std::path::{Path, PathBuf}; use std::rc::Rc; @@ -372,7 +373,7 @@ pub fn maybe_aborted<T>(result: T, p: Parser) -> T { /// well. Can take any slice prefixed by a character escape. Returns the /// character and the number of characters consumed. pub fn char_lit(lit: &str) -> (char, isize) { - use std::{num, char}; + use std::char; let mut chars = lit.chars(); let c = match (chars.next(), chars.next()) { @@ -399,7 +400,7 @@ pub fn char_lit(lit: &str) -> (char, isize) { let msg2 = &msg[..]; fn esc(len: usize, lit: &str) -> Option<(char, isize)> { - num::from_str_radix(&lit[2..len], 16).ok() + u32::from_str_radix(&lit[2..len], 16).ok() .and_then(char::from_u32) .map(|x| (x, len as isize)) } @@ -408,7 +409,7 @@ pub fn char_lit(lit: &str) -> (char, isize) { if lit.as_bytes()[2] == b'{' { let idx = lit.find('}').expect(msg2); let subslice = &lit[3..idx]; - num::from_str_radix(subslice, 16).ok() + u32::from_str_radix(subslice, 16).ok() .and_then(char::from_u32) .map(|x| (x, subslice.chars().count() as isize + 4)) } else { @@ -582,7 +583,7 @@ pub fn byte_lit(lit: &str) -> (u8, usize) { b'\'' => b'\'', b'0' => b'\0', _ => { - match ::std::num::from_str_radix::<u64>(&lit[2..4], 16).ok() { + match u64::from_str_radix(&lit[2..4], 16).ok() { Some(c) => if c > 0xFF { panic!(err(2)) @@ -733,7 +734,7 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) -> debug!("integer_lit: the type is {:?}, base {:?}, the new string is {:?}, the original \ string was {:?}, the original suffix was {:?}", ty, base, s, orig, suffix); - let res: u64 = match ::std::num::from_str_radix(s, base).ok() { + let res = match u64::from_str_radix(s, base).ok() { Some(r) => r, None => { sd.span_err(sp, "int literal is too large"); 0 } }; |
