Skip to content

Commit bf26f26

Browse files
committed
syntax: Copy unstable str::slice_shift_char into libsyntax
1 parent d1556b9 commit bf26f26

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/libsyntax/ext/asm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use feature_gate;
2222
use parse::token::InternedString;
2323
use parse::token;
2424
use ptr::P;
25+
use str::slice_shift_char;
2526

2627
enum State {
2728
Asm,
@@ -109,7 +110,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
109110
// It's the opposite of '=&' which means that the memory
110111
// cannot be shared with any other operand (usually when
111112
// a register is clobbered early.)
112-
let output = match constraint.slice_shift_char() {
113+
let output = match slice_shift_char(&constraint) {
113114
Some(('=', _)) => None,
114115
Some(('+', operand)) => {
115116
Some(token::intern_and_get_ident(&format!(

src/libsyntax/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#![feature(rustc_private)]
3232
#![feature(staged_api)]
3333
#![feature(unicode)]
34-
#![feature(str_char)]
3534

3635
extern crate arena;
3736
extern crate fmt_macros;

src/libsyntax/print/pprust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use print::pp::{Breaks, eof};
2727
use print::pp::Breaks::{Consistent, Inconsistent};
2828
use ptr::P;
2929
use std_inject;
30-
use str::{escape_default, escape_default_string};
30+
use str::{escape_default, escape_default_string, slice_shift_char};
3131

3232
use std::ascii;
3333
use std::io::{self, Write, Read};
@@ -1909,7 +1909,7 @@ impl<'a> State<'a> {
19091909

19101910
try!(self.commasep(Inconsistent, &a.outputs,
19111911
|s, &(ref co, ref o, is_rw)| {
1912-
match co.slice_shift_char() {
1912+
match slice_shift_char(co) {
19131913
Some(('=', operand)) if is_rw => {
19141914
try!(s.print_string(&format!("+{}", operand),
19151915
ast::CookedStr))

src/libsyntax/str.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@
1010

1111
use std::mem::transmute;
1212

13+
// FIXME: This was copied from core/str/mod.rs because it is currently unstable.
1314
pub fn char_at(s: &str, byte: usize) -> char {
1415
s[byte..].chars().next().unwrap()
1516
}
1617

18+
// FIXME: This was copied from core/str/mod.rs because it is currently unstable.
19+
#[inline]
20+
pub fn slice_shift_char(s: &str) -> Option<(char, &str)> {
21+
if s.is_empty() {
22+
None
23+
} else {
24+
let ch = char_at(s, 0);
25+
Some((ch, &s[ch.len_utf8()..]))
26+
}
27+
}
28+
1729
// FIXME: This was copied from core/char.rs because it is currenty unstable.
1830
pub fn escape_unicode(ch: char) -> EscapeUnicode {
1931
EscapeUnicode { c: ch, state: EscapeUnicodeState::Backslash }

0 commit comments

Comments
 (0)