Skip to content

Commit 0b6b7bc

Browse files
committed
---
yaml --- r: 220891 b: refs/heads/auto c: 05e2f86 h: refs/heads/master i: 220889: 229ca06 220887: 0f01977 v: v3
1 parent 2f51042 commit 0b6b7bc

File tree

10 files changed

+47
-211
lines changed

10 files changed

+47
-211
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: ef04b07239d75f2b6bb66f18855f3af695d76e1c
11+
refs/heads/auto: 05e2f8665d3d25744058c2477ef59dc9022fc144
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/libcore/fmt/num.rs

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,18 @@ use fmt;
2020
use num::Zero;
2121
use ops::{Div, Rem, Sub};
2222
use str;
23-
use slice;
24-
use ptr;
25-
use mem;
2623

2724
#[doc(hidden)]
2825
trait Int: Zero + PartialEq + PartialOrd + Div<Output=Self> + Rem<Output=Self> +
2926
Sub<Output=Self> + Copy {
3027
fn from_u8(u: u8) -> Self;
3128
fn to_u8(&self) -> u8;
32-
fn to_u32(&self) -> u32;
33-
fn to_u64(&self) -> u64;
3429
}
3530

3631
macro_rules! doit {
3732
($($t:ident)*) => ($(impl Int for $t {
3833
fn from_u8(u: u8) -> $t { u as $t }
3934
fn to_u8(&self) -> u8 { *self as u8 }
40-
fn to_u32(&self) -> u32 { *self as u32 }
41-
fn to_u64(&self) -> u64 { *self as u64 }
4235
})*)
4336
}
4437
doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize }
@@ -195,7 +188,6 @@ macro_rules! radix_fmt {
195188
}
196189
}
197190
}
198-
199191
macro_rules! int_base {
200192
($Trait:ident for $T:ident as $U:ident -> $Radix:ident) => {
201193
#[stable(feature = "rust1", since = "1.0.0")]
@@ -217,16 +209,17 @@ macro_rules! debug {
217209
}
218210
}
219211
}
220-
221212
macro_rules! integer {
222213
($Int:ident, $Uint:ident) => {
214+
int_base! { Display for $Int as $Int -> Decimal }
223215
int_base! { Binary for $Int as $Uint -> Binary }
224216
int_base! { Octal for $Int as $Uint -> Octal }
225217
int_base! { LowerHex for $Int as $Uint -> LowerHex }
226218
int_base! { UpperHex for $Int as $Uint -> UpperHex }
227219
radix_fmt! { $Int as $Int, fmt_int }
228220
debug! { $Int }
229221

222+
int_base! { Display for $Uint as $Uint -> Decimal }
230223
int_base! { Binary for $Uint as $Uint -> Binary }
231224
int_base! { Octal for $Uint as $Uint -> Octal }
232225
int_base! { LowerHex for $Uint as $Uint -> LowerHex }
@@ -240,80 +233,3 @@ integer! { i8, u8 }
240233
integer! { i16, u16 }
241234
integer! { i32, u32 }
242235
integer! { i64, u64 }
243-
244-
const DEC_DIGITS_LUT: &'static[u8] =
245-
b"0001020304050607080910111213141516171819\
246-
2021222324252627282930313233343536373839\
247-
4041424344454647484950515253545556575859\
248-
6061626364656667686970717273747576777879\
249-
8081828384858687888990919293949596979899";
250-
251-
macro_rules! impl_Display {
252-
($($t:ident),*: $conv_fn:ident) => ($(
253-
impl fmt::Display for $t {
254-
#[allow(unused_comparisons)]
255-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
256-
let is_positive = *self >= 0;
257-
let mut n = if is_positive {
258-
self.$conv_fn()
259-
} else {
260-
// convert the negative num to positive by summing 1 to it's 2 complement
261-
(!self.$conv_fn()).wrapping_add(1)
262-
};
263-
let mut buf: [u8; 20] = unsafe { mem::uninitialized() };
264-
let mut curr = buf.len() as isize;
265-
let buf_ptr = buf.as_mut_ptr();
266-
let lut_ptr = DEC_DIGITS_LUT.as_ptr();
267-
268-
unsafe {
269-
// eagerly decode 4 characters at a time
270-
if <$t>::max_value() as u64 >= 10000 {
271-
while n >= 10000 {
272-
let rem = (n % 10000) as isize;
273-
n /= 10000;
274-
275-
let d1 = (rem / 100) << 1;
276-
let d2 = (rem % 100) << 1;
277-
curr -= 4;
278-
ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2);
279-
ptr::copy_nonoverlapping(lut_ptr.offset(d2), buf_ptr.offset(curr + 2), 2);
280-
}
281-
}
282-
283-
// if we reach here numbers are <= 9999, so at most 4 chars long
284-
let mut n = n as isize; // possibly reduce 64bit math
285-
286-
// decode 2 more chars, if > 2 chars
287-
if n >= 100 {
288-
let d1 = (n % 100) << 1;
289-
n /= 100;
290-
curr -= 2;
291-
ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2);
292-
}
293-
294-
// decode last 1 or 2 chars
295-
if n < 10 {
296-
curr -= 1;
297-
*buf_ptr.offset(curr) = (n as u8) + 48;
298-
} else {
299-
let d1 = n << 1;
300-
curr -= 2;
301-
ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2);
302-
}
303-
}
304-
305-
let buf_slice = unsafe {
306-
str::from_utf8_unchecked(
307-
slice::from_raw_parts(buf_ptr.offset(curr), buf.len() - curr as usize))
308-
};
309-
f.pad_integral(is_positive, "", buf_slice)
310-
}
311-
})*);
312-
}
313-
314-
impl_Display!(i8, u8, i16, u16, i32, u32: to_u32);
315-
impl_Display!(i64, u64: to_u64);
316-
#[cfg(target_pointer_width = "32")]
317-
impl_Display!(isize, usize: to_u32);
318-
#[cfg(target_pointer_width = "64")]
319-
impl_Display!(isize, usize: to_u64);

branches/auto/src/libcore/num/mod.rs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use mem::size_of;
2424
use option::Option::{self, Some, None};
2525
use result::Result::{self, Ok, Err};
2626
use str::{FromStr, StrExt};
27-
use slice::SliceExt;
2827

2928
/// Provides intentionally-wrapped arithmetic on `T`.
3029
///
@@ -1449,30 +1448,19 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32)
14491448
-> Result<T, ParseIntError> {
14501449
use self::IntErrorKind::*;
14511450
use self::ParseIntError as PIE;
1452-
14531451
assert!(radix >= 2 && radix <= 36,
14541452
"from_str_radix_int: must lie in the range `[2, 36]` - found {}",
14551453
radix);
14561454

1457-
if src.is_empty() {
1458-
return Err(PIE { kind: Empty });
1459-
}
1460-
14611455
let is_signed_ty = T::from_u32(0) > T::min_value();
14621456

1463-
// all valid digits are ascii, so we will just iterate over the utf8 bytes
1464-
// and cast them to chars. .to_digit() will safely return None for anything
1465-
// other than a valid ascii digit for a the given radix, including the first-byte
1466-
// of multi-byte sequences
1467-
let src = src.as_bytes();
1468-
1469-
match (src[0], &src[1..]) {
1470-
(b'-', digits) if digits.is_empty() => Err(PIE { kind: Empty }),
1471-
(b'-', digits) if is_signed_ty => {
1457+
match src.slice_shift_char() {
1458+
Some(('-', "")) => Err(PIE { kind: Empty }),
1459+
Some(('-', src)) if is_signed_ty => {
14721460
// The number is negative
14731461
let mut result = T::from_u32(0);
1474-
for &c in digits {
1475-
let x = match (c as char).to_digit(radix) {
1462+
for c in src.chars() {
1463+
let x = match c.to_digit(radix) {
14761464
Some(x) => x,
14771465
None => return Err(PIE { kind: InvalidDigit }),
14781466
};
@@ -1487,14 +1475,11 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32)
14871475
}
14881476
Ok(result)
14891477
},
1490-
(c, digits) => {
1478+
Some((_, _)) => {
14911479
// The number is signed
1492-
let mut result = match (c as char).to_digit(radix) {
1493-
Some(x) => T::from_u32(x),
1494-
None => return Err(PIE { kind: InvalidDigit }),
1495-
};
1496-
for &c in digits {
1497-
let x = match (c as char).to_digit(radix) {
1480+
let mut result = T::from_u32(0);
1481+
for c in src.chars() {
1482+
let x = match c.to_digit(radix) {
14981483
Some(x) => x,
14991484
None => return Err(PIE { kind: InvalidDigit }),
15001485
};
@@ -1508,7 +1493,8 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32)
15081493
};
15091494
}
15101495
Ok(result)
1511-
}
1496+
},
1497+
None => Err(ParseIntError { kind: Empty }),
15121498
}
15131499
}
15141500

branches/auto/src/libcoretest/num/mod.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,7 @@ mod tests {
117117
}
118118

119119
#[test]
120-
fn test_invalid() {
121-
assert_eq!("--129".parse::<i8>().ok(), None);
122-
assert_eq!("Съешь".parse::<u8>().ok(), None);
123-
}
124-
125-
#[test]
126-
fn test_empty() {
127-
assert_eq!("-".parse::<i8>().ok(), None);
128-
assert_eq!("".parse::<u8>().ok(), None);
120+
fn test_int_from_minus_sign() {
121+
assert_eq!("-".parse::<i32>().ok(), None);
129122
}
130123
}

branches/auto/src/librustc_resolve/diagnostics.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,5 @@ register_diagnostics! {
321321
E0432, // unresolved import
322322
E0433, // failed to resolve
323323
E0434, // can't capture dynamic environment in a fn item
324-
E0435, // attempt to use a non-constant value in a constant
325-
E0437, // type is not a member of trait
326-
E0438, // const is not a member of trait
324+
E0435 // attempt to use a non-constant value in a constant
327325
}

branches/auto/src/librustc_resolve/lib.rs

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ pub enum ResolutionError<'a> {
123123
UndeclaredAssociatedType,
124124
/// error E0407: method is not a member of trait
125125
MethodNotMemberOfTrait(Name, &'a str),
126-
/// error E0437: type is not a member of trait
127-
TypeNotMemberOfTrait(Name, &'a str),
128-
/// error E0438: const is not a member of trait
129-
ConstNotMemberOfTrait(Name, &'a str),
130126
/// error E0408: variable `{}` from pattern #1 is not bound in pattern
131127
VariableNotBoundInPattern(Name, usize),
132128
/// error E0409: variable is bound with different mode in pattern #{} than in pattern #1
@@ -224,18 +220,6 @@ fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolver: &'b Resolver<'a, 'tcx>, span: syn
224220
method,
225221
trait_);
226222
},
227-
ResolutionError::TypeNotMemberOfTrait(type_, trait_) => {
228-
span_err!(resolver.session, span, E0437,
229-
"type `{}` is not a member of trait `{}`",
230-
type_,
231-
trait_);
232-
},
233-
ResolutionError::ConstNotMemberOfTrait(const_, trait_) => {
234-
span_err!(resolver.session, span, E0438,
235-
"const `{}` is not a member of trait `{}`",
236-
const_,
237-
trait_);
238-
},
239223
ResolutionError::VariableNotBoundInPattern(variable_name, pattern_number) => {
240224
span_err!(resolver.session, span, E0408,
241225
"variable `{}` from pattern #1 is not bound in pattern #{}",
@@ -2401,11 +2385,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
24012385
for impl_item in impl_items {
24022386
match impl_item.node {
24032387
ConstImplItem(..) => {
2404-
// If this is a trait impl, ensure the const
2388+
// If this is a trait impl, ensure the method
24052389
// exists in trait
24062390
this.check_trait_item(impl_item.ident.name,
2407-
impl_item.span,
2408-
|n, s| ResolutionError::ConstNotMemberOfTrait(n, s));
2391+
impl_item.span);
24092392
this.with_constant_rib(|this| {
24102393
visit::walk_impl_item(this, impl_item);
24112394
});
@@ -2414,8 +2397,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
24142397
// If this is a trait impl, ensure the method
24152398
// exists in trait
24162399
this.check_trait_item(impl_item.ident.name,
2417-
impl_item.span,
2418-
|n, s| ResolutionError::MethodNotMemberOfTrait(n, s));
2400+
impl_item.span);
24192401

24202402
// We also need a new scope for the method-
24212403
// specific type parameters.
@@ -2428,11 +2410,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
24282410
});
24292411
}
24302412
TypeImplItem(ref ty) => {
2431-
// If this is a trait impl, ensure the type
2413+
// If this is a trait impl, ensure the method
24322414
// exists in trait
24332415
this.check_trait_item(impl_item.ident.name,
2434-
impl_item.span,
2435-
|n, s| ResolutionError::TypeNotMemberOfTrait(n, s));
2416+
impl_item.span);
24362417

24372418
this.visit_ty(ty);
24382419
}
@@ -2445,15 +2426,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
24452426
});
24462427
}
24472428

2448-
fn check_trait_item<F>(&self, name: Name, span: Span, err: F)
2449-
where F: FnOnce(Name, &str) -> ResolutionError {
2429+
fn check_trait_item(&self, name: Name, span: Span) {
24502430
// If there is a TraitRef in scope for an impl, then the method must be in the trait.
24512431
if let Some((did, ref trait_ref)) = self.current_trait_ref {
24522432
if !self.trait_item_map.contains_key(&(name, did)) {
24532433
let path_str = path_names_to_string(&trait_ref.path, 0);
24542434
resolve_error(self,
24552435
span,
2456-
err(name, &*path_str));
2436+
ResolutionError::MethodNotMemberOfTrait(name,
2437+
&*path_str));
24572438
}
24582439
}
24592440
}

0 commit comments

Comments
 (0)