diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2015-09-03 20:10:07 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2015-09-03 20:10:07 -0400 |
| commit | 055c23da7bd36b5aee4ffb2176dae9b2d9d7d109 (patch) | |
| tree | fa40206f6389cd2024c73ee14838a90459aa47f3 /src/libsyntax | |
| parent | 1b908be9a0d7aaf8f18854db1ffef7b8df10dfeb (diff) | |
| parent | 405c616eaf4e58a8bed67924c364c8e9c83b2581 (diff) | |
| download | rust-055c23da7bd36b5aee4ffb2176dae9b2d9d7d109.tar.gz rust-055c23da7bd36b5aee4ffb2176dae9b2d9d7d109.zip | |
Rollup merge of #28167 - petrochenkov:bytelit, r=nikomatsakis
Avoid confusion with binary integer literals and binary operator expressions in libsyntax
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/concat.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 6 |
8 files changed, 23 insertions, 23 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 25a3540c743..ce3989b5bba 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1190,7 +1190,7 @@ pub enum Lit_ { /// A string literal (`"foo"`) LitStr(InternedString, StrStyle), /// A byte string (`b"foo"`) - LitBinary(Rc<Vec<u8>>), + LitByteStr(Rc<Vec<u8>>), /// A byte char (`b'f'`) LitByte(u8), /// A character literal (`'a'`) diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index 754c73a9d78..71430b7aad5 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -50,8 +50,8 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, accumulator.push_str(&format!("{}", b)); } ast::LitByte(..) | - ast::LitBinary(..) => { - cx.span_err(e.span, "cannot concatenate a binary literal"); + ast::LitByteStr(..) => { + cx.span_err(e.span, "cannot concatenate a byte string literal"); } } } diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 8da36b2c1e1..25063e7b0d6 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -189,7 +189,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let filename = format!("{}", file.display()); cx.codemap().new_filemap_and_lines(&filename, ""); - base::MacEager::expr(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes)))) + base::MacEager::expr(cx.expr_lit(sp, ast::LitByteStr(Rc::new(bytes)))) } } } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 019a8404dfb..a0e170b4ace 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1304,7 +1304,7 @@ impl<'a> StringReader<'a> { } let id = if valid { self.name_from(start) } else { token::intern("??") }; self.bump(); - return token::Binary(id); + return token::ByteStr(id); } fn scan_raw_byte_string(&mut self) -> token::Lit { @@ -1355,7 +1355,7 @@ impl<'a> StringReader<'a> { self.bump(); } self.bump(); - return token::BinaryRaw(self.name_from_to(content_start_bpos, + return token::ByteStrRaw(self.name_from_to(content_start_bpos, content_end_bpos), hash_count); } @@ -1546,7 +1546,7 @@ mod tests { test!("'a'", Char, "a"); test!("b'a'", Byte, "a"); test!("\"a\"", Str_, "a"); - test!("b\"a\"", Binary, "a"); + test!("b\"a\"", ByteStr, "a"); test!("1234", Integer, "1234"); test!("0b101", Integer, "0b101"); test!("0xABC", Integer, "0xABC"); @@ -1560,7 +1560,7 @@ mod tests { token::Literal(token::StrRaw(token::intern("raw"), 3), Some(token::intern("suffix")))); assert_eq!(setup(&mk_sh(), "br###\"raw\"###suffix".to_string()).next_token().tok, - token::Literal(token::BinaryRaw(token::intern("raw"), 3), + token::Literal(token::ByteStrRaw(token::intern("raw"), 3), Some(token::intern("suffix")))); } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index c5a73601d89..269f8bdd98a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -499,7 +499,7 @@ pub fn byte_lit(lit: &str) -> (u8, usize) { } } -pub fn binary_lit(lit: &str) -> Rc<Vec<u8>> { +pub fn byte_str_lit(lit: &str) -> Rc<Vec<u8>> { let mut res = Vec::with_capacity(lit.len()); // FIXME #8372: This could be a for-loop if it didn't borrow the iterator @@ -517,7 +517,7 @@ pub fn binary_lit(lit: &str) -> Rc<Vec<u8>> { } } - // binary literals *must* be ASCII, but the escapes don't have to be + // byte string literals *must* be ASCII, but the escapes don't have to be let mut chars = lit.bytes().enumerate().peekable(); loop { match chars.next() { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 0772d124db8..337e855f900 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -34,7 +34,7 @@ use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst}; use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, ItemDefaultImpl}; use ast::{ItemExternCrate, ItemUse}; use ast::{LifetimeDef, Lit, Lit_}; -use ast::{LitBool, LitChar, LitByte, LitBinary}; +use ast::{LitBool, LitChar, LitByte, LitByteStr}; use ast::{LitStr, LitInt, Local}; use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces}; use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, MatchSource}; @@ -1543,11 +1543,11 @@ impl<'a> Parser<'a> { token::intern_and_get_ident(&parse::raw_str_lit(&s.as_str())), ast::RawStr(n))) } - token::Binary(i) => - (true, LitBinary(parse::binary_lit(&i.as_str()))), - token::BinaryRaw(i, _) => + token::ByteStr(i) => + (true, LitByteStr(parse::byte_str_lit(&i.as_str()))), + token::ByteStrRaw(i, _) => (true, - LitBinary(Rc::new(i.to_string().into_bytes()))), + LitByteStr(Rc::new(i.to_string().into_bytes()))), }; if suffix_illegal { @@ -5826,7 +5826,7 @@ impl<'a> Parser<'a> { match try!(self.parse_optional_str()) { Some((s, style, suf)) => { let sp = self.last_span; - self.expect_no_suffix(sp, "str literal", suf); + self.expect_no_suffix(sp, "string literal", suf); Ok((s, style)) } _ => Err(self.fatal("expected string literal")) diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index bd479255438..ca92a37d8c3 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -82,8 +82,8 @@ pub enum Lit { Float(ast::Name), Str_(ast::Name), StrRaw(ast::Name, usize), /* raw str delimited by n hash symbols */ - Binary(ast::Name), - BinaryRaw(ast::Name, usize), /* raw binary str delimited by n hash symbols */ + ByteStr(ast::Name), + ByteStrRaw(ast::Name, usize), /* raw byte str delimited by n hash symbols */ } impl Lit { @@ -93,8 +93,8 @@ impl Lit { Char(_) => "char", Integer(_) => "integer", Float(_) => "float", - Str_(_) | StrRaw(..) => "str", - Binary(_) | BinaryRaw(..) => "binary str" + Str_(_) | StrRaw(..) => "string", + ByteStr(_) | ByteStrRaw(..) => "byte string" } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index b93a244df13..341b177923c 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -259,8 +259,8 @@ pub fn token_to_string(tok: &Token) -> String { token::StrRaw(s, n) => format!("r{delim}\"{string}\"{delim}", delim=repeat("#", n), string=s), - token::Binary(v) => format!("b\"{}\"", v), - token::BinaryRaw(s, n) => format!("br{delim}\"{string}\"{delim}", + token::ByteStr(v) => format!("b\"{}\"", v), + token::ByteStrRaw(s, n) => format!("br{delim}\"{string}\"{delim}", delim=repeat("#", n), string=s), }; @@ -2887,7 +2887,7 @@ impl<'a> State<'a> { ast::LitBool(val) => { if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") } } - ast::LitBinary(ref v) => { + ast::LitByteStr(ref v) => { let mut escaped: String = String::new(); for &ch in v.iter() { escaped.extend(ascii::escape_default(ch) |
