diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2016-06-08 09:19:44 +0300 |
|---|---|---|
| committer | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2016-06-09 00:38:38 +0300 |
| commit | f0174fcbee229c67ebfdae9012628891a55be7aa (patch) | |
| tree | a4d4ab0ecd2e14ba3637ad4349b3c57858e59055 | |
| parent | 9b1abf5c65d4019542ff3cf5daa15c0e22e7e012 (diff) | |
| download | rust-f0174fcbee229c67ebfdae9012628891a55be7aa.tar.gz rust-f0174fcbee229c67ebfdae9012628891a55be7aa.zip | |
use the slice_pat hack in libstd too
| -rw-r--r-- | src/libstd/lib.rs | 12 | ||||
| -rw-r--r-- | src/libstd/sys/common/wtf8.rs | 21 | ||||
| -rw-r--r-- | src/libstd/sys/windows/fs.rs | 6 |
3 files changed, 21 insertions, 18 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 7114d47e6e8..135ea8a5e7c 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -467,3 +467,15 @@ pub mod __rand { // the rustdoc documentation for primitive types. Using `include!` // because rustdoc only looks for these modules at the crate level. include!("primitive_docs.rs"); + +// FIXME(stage0): remove this after a snapshot +// HACK: this is needed because the interpretation of slice +// patterns changed between stage0 and now. +#[cfg(stage0)] +fn slice_pat<'a, 'b, T>(t: &'a &'b [T]) -> &'a &'b [T] { + t +} +#[cfg(not(stage0))] +fn slice_pat<'a, 'b, T>(t: &'a &'b [T]) -> &'b [T] { + *t +} diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 35e39531448..d705b8986d0 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -560,20 +560,15 @@ impl Wtf8 { } } - // FIXME(stage0): use slice patterns after snapshot #[inline] fn final_lead_surrogate(&self) -> Option<u16> { let len = self.len(); if len < 3 { return None } - if self.bytes[len-3] == 0xed && - self.bytes[len-2] >= 0xa0 && - self.bytes[len-2] <= 0xaf - { - Some(decode_surrogate(self.bytes[len-2], self.bytes[len-1])) - } else { - None + match ::slice_pat(&&self.bytes[(len - 3)..]) { + &[0xED, b2 @ 0xA0...0xAF, b3] => Some(decode_surrogate(b2, b3)), + _ => None } } @@ -583,13 +578,9 @@ impl Wtf8 { if len < 3 { return None } - if self.bytes[0] == 0xed && - self.bytes[1] >= 0xb0 && - self.bytes[1] <= 0xbf - { - Some(decode_surrogate(self.bytes[1], self.bytes[2])) - } else { - None + match ::slice_pat(&&self.bytes[..3]) { + &[0xED, b2 @ 0xB0...0xBF, b3] => Some(decode_surrogate(b2, b3)), + _ => None } } } diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 3cd45afaf01..c243e890526 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -117,10 +117,10 @@ impl Drop for FindNextFileHandle { impl DirEntry { fn new(root: &Arc<PathBuf>, wfd: &c::WIN32_FIND_DATAW) -> Option<DirEntry> { - match &wfd.cFileName[0..3] { + match ::slice_pat(&&wfd.cFileName[0..3]) { // check for '.' and '..' - [46, 0, ..] | - [46, 46, 0, ..] => return None, + &[46, 0, ..] | + &[46, 46, 0, ..] => return None, _ => {} } |
