Skip to content

Commit 3b2e53d

Browse files
committed
syntax: Copy unstable str::slice_shift_char into libsyntax
1 parent e4b8064 commit 3b2e53d

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +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::slice_shift_char;
3031

3132
use std::ascii;
3233
use std::io::{self, Write, Read};
@@ -1873,7 +1874,7 @@ impl<'a> State<'a> {
18731874

18741875
try!(self.commasep(Inconsistent, &a.outputs,
18751876
|s, &(ref co, ref o, is_rw)| {
1876-
match co.slice_shift_char() {
1877+
match slice_shift_char(co) {
18771878
Some(('=', operand)) if is_rw => {
18781879
try!(s.print_string(&format!("+{}", operand),
18791880
ast::CookedStr))

src/libsyntax/str.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// FIXME: This was copied from core/str/mod.rs because it is currently unstable.
1112
pub fn char_at(s: &str, byte: usize) -> char {
1213
s[byte..].chars().next().unwrap()
1314
}
15+
16+
// FIXME: This was copied from core/str/mod.rs because it is currently unstable.
17+
#[inline]
18+
pub fn slice_shift_char(s: &str) -> Option<(char, &str)> {
19+
if s.is_empty() {
20+
None
21+
} else {
22+
let ch = char_at(s, 0);
23+
Some((ch, &s[ch.len_utf8()..]))
24+
}
25+
}

0 commit comments

Comments
 (0)