Add a b"xx" byte string literal of type &'static [u8].

This commit is contained in:
Simon Sapin 2014-06-07 15:32:01 +01:00
parent bccdba0296
commit d7e01b5809
12 changed files with 185 additions and 70 deletions

View file

@ -0,0 +1,23 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-tidy-tab
static FOO: &'static [u8] = b"\f"; //~ ERROR unknown byte escape
pub fn main() {
b"\f"; //~ ERROR unknown byte escape
b"\x0Z"; //~ ERROR illegal character in numeric character escape: Z
b"é"; //~ ERROR byte constant must be ASCII
b"a //~ ERROR unterminated double quote byte string
}

View file

@ -10,6 +10,7 @@
fn main() {
concat!(b'f'); //~ ERROR: cannot concatenate a binary literal
concat!(b"foo"); //~ ERROR: cannot concatenate a binary literal
concat!(foo); //~ ERROR: expected a literal
concat!(foo()); //~ ERROR: expected a literal
}

View file

@ -10,6 +10,7 @@
static FOO: u8 = b'\xF0';
static BAR: &'static [u8] = b"a\xF0\t";
pub fn main() {
assert_eq!(b'a', 97u8);
@ -35,4 +36,15 @@ pub fn main() {
b'a' .. b'z' => {},
_ => fail!()
}
assert_eq!(b"a\n\r\t\\\'\"\0\xF0",
&[97u8, 10u8, 13u8, 9u8, 92u8, 39u8, 34u8, 0u8, 240u8]);
assert_eq!(b"a\
b", &[97u8, 98u8]);
assert_eq!(BAR, &[97u8, 240u8, 9u8]);
match &[97u8, 10u8] {
b"a\n" => {},
_ => fail!(),
}
}