From 5c717a6fc21594569d9e64968cdcf2e88e372a07 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Fri, 11 Mar 2016 12:54:59 +0200 Subject: implement RFC495 semantics for slice patterns non-MIR translation is still not supported for these and will happily ICE. This is a [breaking-change] for many uses of slice_patterns. --- src/libstd/sys/common/wtf8.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 55e485e5811..5519230890c 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -560,15 +560,20 @@ impl Wtf8 { } } + // FIXME(stage0): use slice patterns after snapshot #[inline] fn final_lead_surrogate(&self) -> Option { let len = self.len(); if len < 3 { return None } - match &self.bytes[(len - 3)..] { - [0xED, b2 @ 0xA0...0xAF, b3] => Some(decode_surrogate(b2, b3)), - _ => 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 } } @@ -578,9 +583,13 @@ impl Wtf8 { if len < 3 { return None } - match &self.bytes[..3] { - [0xED, b2 @ 0xB0...0xBF, b3] => Some(decode_surrogate(b2, b3)), - _ => None + if self.bytes[len-3] == 0xed && + self.bytes[len-2] > 0xb0 && + self.bytes[len-2] <= 0xbf + { + Some(decode_surrogate(self.bytes[len-2], self.bytes[len-1])) + } else { + None } } } -- cgit 1.4.1-3-g733a5 From 8ac3b46cac46e88ee2025ca9c9c0b853fd632110 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Mon, 6 Jun 2016 00:20:15 +0300 Subject: address review comments --- src/librustc_trans/mir/lvalue.rs | 2 +- src/libstd/sys/common/wtf8.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/libstd') diff --git a/src/librustc_trans/mir/lvalue.rs b/src/librustc_trans/mir/lvalue.rs index 0c7eeafe86e..523dfef5a24 100644 --- a/src/librustc_trans/mir/lvalue.rs +++ b/src/librustc_trans/mir/lvalue.rs @@ -199,7 +199,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { let base_ty = self.lvalue_ty(lvalue); let llbasety = type_of::type_of(bcx.ccx(), base_ty).ptr_to(); let llbase = bcx.pointercast(llbase, llbasety); - (bcx.pointercast(llbase, llbasety), ptr::null_mut()) + (llbase, ptr::null_mut()) } ty::TySlice(..) => { assert!(tr_base.llextra != ptr::null_mut()); diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 5519230890c..35e39531448 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -568,7 +568,7 @@ impl Wtf8 { return None } if self.bytes[len-3] == 0xed && - self.bytes[len-2] > 0xa0 && + self.bytes[len-2] >= 0xa0 && self.bytes[len-2] <= 0xaf { Some(decode_surrogate(self.bytes[len-2], self.bytes[len-1])) @@ -583,11 +583,11 @@ impl Wtf8 { if len < 3 { return None } - if self.bytes[len-3] == 0xed && - self.bytes[len-2] > 0xb0 && - self.bytes[len-2] <= 0xbf + if self.bytes[0] == 0xed && + self.bytes[1] >= 0xb0 && + self.bytes[1] <= 0xbf { - Some(decode_surrogate(self.bytes[len-2], self.bytes[len-1])) + Some(decode_surrogate(self.bytes[1], self.bytes[2])) } else { None } -- cgit 1.4.1-3-g733a5 From a673cedf7bdc79a0b8dd3c831bef1698a0542365 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Mon, 6 Jun 2016 23:41:54 +0300 Subject: fix stdtest --- src/libstd/sync/mpsc/spsc_queue.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index ffd33f8518f..02506e7c2f3 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -265,15 +265,18 @@ mod tests { // Ensure the borrowchecker works match queue.peek() { - Some(vec) => match &**vec { - // Note that `pop` is not allowed here due to borrow - [1] => {} - _ => return + Some(vec) => { + assert_eq!(&*vec, &[1]); }, None => unreachable!() } - queue.pop(); + match queue.pop() { + Some(vec) => { + assert_eq!(&*vec, &[1]); + }, + None => unreachable!() + } } } -- cgit 1.4.1-3-g733a5 From f0174fcbee229c67ebfdae9012628891a55be7aa Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Wed, 8 Jun 2016 09:19:44 +0300 Subject: use the slice_pat hack in libstd too --- src/libstd/lib.rs | 12 ++++++++++++ src/libstd/sys/common/wtf8.rs | 21 ++++++--------------- src/libstd/sys/windows/fs.rs | 6 +++--- 3 files changed, 21 insertions(+), 18 deletions(-) (limited to 'src/libstd') 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 { 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, wfd: &c::WIN32_FIND_DATAW) -> Option { - 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, _ => {} } -- cgit 1.4.1-3-g733a5