Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RFC495 semantics for slice patterns #32202

Merged
merged 15 commits into from
Jun 9, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use the slice_pat hack in libstd too
  • Loading branch information
arielb1 committed Jun 8, 2016
commit f0174fcbee229c67ebfdae9012628891a55be7aa
12 changes: 12 additions & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
21 changes: 6 additions & 15 deletions src/libstd/sys/common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/sys/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
_ => {}
}

Expand Down