diff options
| author | Jakub Bukaj <jakub@jakub.cc> | 2014-11-18 00:23:55 +0100 |
|---|---|---|
| committer | Jakub Bukaj <jakub@jakub.cc> | 2014-11-18 00:23:55 +0100 |
| commit | db4d60afb0d17c9bff72bb7b6c3754c0e6d3f2b5 (patch) | |
| tree | 075f7946fe635b611e4474e4589229a5833be094 /src/libsyntax | |
| parent | 7137c2cc83526e1f74af472380e625fc7c552826 (diff) | |
| parent | 197a0ac481ae6d154c0966b21849432f1b32c28f (diff) | |
| download | rust-db4d60afb0d17c9bff72bb7b6c3754c0e6d3f2b5.tar.gz rust-db4d60afb0d17c9bff72bb7b6c3754c0e6d3f2b5.zip | |
rollup merge of #18911: canndrew/slice_shift_char
`slice_shift_char` splits a `str` into it's leading `char` and the remainder of the `str`. Currently, it returns a `(Option<char>, &str)` such that:
"bar".slice_shift_char() => (Some('b'), "ar")
"ar".slice_shift_char() => (Some('a'), "r")
"r".slice_shift_char() => (Some('r'), "")
"".slice_shift_char() => (None, "")
This is a little odd. Either a `str` can be split into both a head and a tail or it cannot. So the return type should be `Option<(char, &str)>`. With the current behaviour, in the case of the empty string, the `str` returned is meaningless - it is always the empty string.
This PR changes `slice_shift_char` so that:
"bar".slice_shift_char() => Some(('b', "ar"))
"ar".slice_shift_char() => Some(('a', "r"))
"r".slice_shift_char() => Some(('r', ""))
"".slice_shift_char() => None
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/asm.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 8027d9bfd8a..d04144ef26e 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -97,8 +97,8 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) // cannot be shared with any other operand (usually when // a register is clobbered early.) let output = match constraint.get().slice_shift_char() { - (Some('='), _) => None, - (Some('+'), operand) => { + Some(('=', _)) => None, + Some(('+', operand)) => { Some(token::intern_and_get_ident(format!( "={}", operand).as_slice())) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 390a5cc68d3..81f3d977e13 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1855,7 +1855,7 @@ impl<'a> State<'a> { try!(self.commasep(Inconsistent, a.outputs.as_slice(), |s, &(ref co, ref o, is_rw)| { match co.get().slice_shift_char() { - (Some('='), operand) if is_rw => { + Some(('=', operand)) if is_rw => { try!(s.print_string(format!("+{}", operand).as_slice(), ast::CookedStr)) } |
