Skip to content

Commit 405c616

Browse files
committed
Use consistent terminology for byte string literals
Avoid confusion with binary integer literals and binary operator expressions in libsyntax
1 parent 69c3b39 commit 405c616

File tree

25 files changed

+69
-69
lines changed

25 files changed

+69
-69
lines changed

src/grammar/RustLexer.g4

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ tokens {
1313
BINOPEQ, AT, DOT, DOTDOT, DOTDOTDOT, COMMA, SEMI, COLON,
1414
MOD_SEP, RARROW, FAT_ARROW, LPAREN, RPAREN, LBRACKET, RBRACKET,
1515
LBRACE, RBRACE, POUND, DOLLAR, UNDERSCORE, LIT_CHAR, LIT_BYTE,
16-
LIT_INTEGER, LIT_FLOAT, LIT_STR, LIT_STR_RAW, LIT_BINARY,
17-
LIT_BINARY_RAW, QUESTION, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT,
16+
LIT_INTEGER, LIT_FLOAT, LIT_STR, LIT_STR_RAW, LIT_BYTE_STR,
17+
LIT_BYTE_STR_RAW, QUESTION, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT,
1818
COMMENT, SHEBANG, UTF8_BOM
1919
}
2020

@@ -148,8 +148,8 @@ LIT_STR
148148
: '"' ('\\\n' | '\\\r\n' | '\\' CHAR_ESCAPE | .)*? '"' SUFFIX?
149149
;
150150

151-
LIT_BINARY : 'b' LIT_STR ;
152-
LIT_BINARY_RAW : 'b' LIT_STR_RAW ;
151+
LIT_BYTE_STR : 'b' LIT_STR ;
152+
LIT_BYTE_STR_RAW : 'b' LIT_STR_RAW ;
153153

154154
/* this is a bit messy */
155155

src/grammar/lexer.l

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ while { return WHILE; }
200200
<ltorchar><<EOF>> { BEGIN(INITIAL); return -1; }
201201

202202
b\x22 { BEGIN(bytestr); yymore(); }
203-
<bytestr>\x22 { BEGIN(suffix); return LIT_BINARY; }
203+
<bytestr>\x22 { BEGIN(suffix); return LIT_BYTE_STR; }
204204

205205
<bytestr><<EOF>> { return -1; }
206206
<bytestr>\\[n\nrt\\\x27\x220] { yymore(); }
@@ -210,7 +210,7 @@ b\x22 { BEGIN(bytestr); yymore(); }
210210
<bytestr>(.|\n) { yymore(); }
211211

212212
br\x22 { BEGIN(rawbytestr_nohash); yymore(); }
213-
<rawbytestr_nohash>\x22 { BEGIN(suffix); return LIT_BINARY_RAW; }
213+
<rawbytestr_nohash>\x22 { BEGIN(suffix); return LIT_BYTE_STR_RAW; }
214214
<rawbytestr_nohash>(.|\n) { yymore(); }
215215
<rawbytestr_nohash><<EOF>> { return -1; }
216216

@@ -228,7 +228,7 @@ br/# {
228228
end_hashes++;
229229
if (end_hashes == num_hashes) {
230230
BEGIN(INITIAL);
231-
return LIT_BINARY_RAW;
231+
return LIT_BYTE_STR_RAW;
232232
}
233233
}
234234
yymore();
@@ -237,7 +237,7 @@ br/# {
237237
end_hashes = 1;
238238
if (end_hashes == num_hashes) {
239239
BEGIN(INITIAL);
240-
return LIT_BINARY_RAW;
240+
return LIT_BYTE_STR_RAW;
241241
}
242242
yymore();
243243
}

src/grammar/parser-lalr.y

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ extern char *yytext;
5252
%token LIT_FLOAT
5353
%token LIT_STR
5454
%token LIT_STR_RAW
55-
%token LIT_BINARY
56-
%token LIT_BINARY_RAW
55+
%token LIT_BYTE_STR
56+
%token LIT_BYTE_STR_RAW
5757
%token IDENT
5858
%token UNDERSCORE
5959
%token LIFETIME
@@ -1772,8 +1772,8 @@ lit
17721772
str
17731773
: LIT_STR { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("CookedStr")); }
17741774
| LIT_STR_RAW { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("RawStr")); }
1775-
| LIT_BINARY { $$ = mk_node("LitBinary", 1, mk_atom(yytext), mk_atom("BinaryStr")); }
1776-
| LIT_BINARY_RAW { $$ = mk_node("LitBinary", 1, mk_atom(yytext), mk_atom("RawBinaryStr")); }
1775+
| LIT_BYTE_STR { $$ = mk_node("LitByteStr", 1, mk_atom(yytext), mk_atom("ByteStr")); }
1776+
| LIT_BYTE_STR_RAW { $$ = mk_node("LitByteStr", 1, mk_atom(yytext), mk_atom("RawByteStr")); }
17771777
;
17781778

17791779
maybe_ident
@@ -1815,8 +1815,8 @@ unpaired_token
18151815
| LIT_FLOAT { $$ = mk_atom(yytext); }
18161816
| LIT_STR { $$ = mk_atom(yytext); }
18171817
| LIT_STR_RAW { $$ = mk_atom(yytext); }
1818-
| LIT_BINARY { $$ = mk_atom(yytext); }
1819-
| LIT_BINARY_RAW { $$ = mk_atom(yytext); }
1818+
| LIT_BYTE_STR { $$ = mk_atom(yytext); }
1819+
| LIT_BYTE_STR_RAW { $$ = mk_atom(yytext); }
18201820
| IDENT { $$ = mk_atom(yytext); }
18211821
| UNDERSCORE { $$ = mk_atom(yytext); }
18221822
| LIFETIME { $$ = mk_atom(yytext); }

src/grammar/tokens.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ enum Token {
3838
LIT_FLOAT,
3939
LIT_STR,
4040
LIT_STR_RAW,
41-
LIT_BINARY,
42-
LIT_BINARY_RAW,
41+
LIT_BYTE_STR,
42+
LIT_BYTE_STR_RAW,
4343
IDENT,
4444
UNDERSCORE,
4545
LIFETIME,

src/grammar/verify.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
107107
"OR" => token::BinOp(token::Or),
108108
"GT" => token::Gt,
109109
"LE" => token::Le,
110-
"LIT_BINARY" => token::Literal(token::Binary(Name(0)), None),
111-
"LIT_BINARY_RAW" => token::Literal(token::BinaryRaw(Name(0), 0), None),
110+
"LIT_BYTE_STR" => token::Literal(token::ByteStr(Name(0)), None),
111+
"LIT_BYTE_STR_RAW" => token::Literal(token::ByteStrRaw(Name(0), 0), None),
112112
"QUESTION" => token::Question,
113113
"SHEBANG" => token::Shebang(Name(0)),
114114
_ => continue,
@@ -137,8 +137,8 @@ fn str_to_binop(s: &str) -> token::BinOpToken {
137137
}
138138
}
139139

140-
/// Assuming a string/binary literal, strip out the leading/trailing
141-
/// hashes and surrounding quotes/raw/binary prefix.
140+
/// Assuming a string/byte string literal, strip out the leading/trailing
141+
/// hashes and surrounding quotes/raw/byte prefix.
142142
fn fix(mut lit: &str) -> ast::Name {
143143
if lit.char_at(0) == 'r' {
144144
if lit.char_at(1) == 'b' {
@@ -205,8 +205,8 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>, surrogate_
205205
token::DocComment(..) => token::DocComment(nm),
206206
token::Literal(token::Integer(..), n) => token::Literal(token::Integer(nm), n),
207207
token::Literal(token::Float(..), n) => token::Literal(token::Float(nm), n),
208-
token::Literal(token::Binary(..), n) => token::Literal(token::Binary(nm), n),
209-
token::Literal(token::BinaryRaw(..), n) => token::Literal(token::BinaryRaw(fix(content),
208+
token::Literal(token::ByteStr(..), n) => token::Literal(token::ByteStr(nm), n),
209+
token::Literal(token::ByteStrRaw(..), n) => token::Literal(token::ByteStrRaw(fix(content),
210210
count(content)), n),
211211
token::Ident(..) => token::Ident(ast::Ident { name: nm, ctxt: 0 },
212212
token::ModName),
@@ -340,8 +340,8 @@ fn main() {
340340
token::Literal(token::Float(..), _),
341341
token::Literal(token::Str_(..), _),
342342
token::Literal(token::StrRaw(..), _),
343-
token::Literal(token::Binary(..), _),
344-
token::Literal(token::BinaryRaw(..), _),
343+
token::Literal(token::ByteStr(..), _),
344+
token::Literal(token::ByteStrRaw(..), _),
345345
token::Ident(..),
346346
token::Lifetime(..),
347347
token::Interpolated(..),

src/librustc/middle/const_eval.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub enum ConstVal {
269269
Int(i64),
270270
Uint(u64),
271271
Str(InternedString),
272-
Binary(Rc<Vec<u8>>),
272+
ByteStr(Rc<Vec<u8>>),
273273
Bool(bool),
274274
Struct(ast::NodeId),
275275
Tuple(ast::NodeId),
@@ -283,7 +283,7 @@ impl ConstVal {
283283
Int(_) => "positive integer",
284284
Uint(_) => "unsigned integer",
285285
Str(_) => "string literal",
286-
Binary(_) => "binary array",
286+
ByteStr(_) => "byte string literal",
287287
Bool(_) => "boolean",
288288
Struct(_) => "struct",
289289
Tuple(_) => "tuple",
@@ -1175,8 +1175,8 @@ fn cast_const<'tcx>(tcx: &ty::ctxt<'tcx>, val: ConstVal, ty: Ty) -> CastResult {
11751175
fn lit_to_const(lit: &hir::Lit, ty_hint: Option<Ty>) -> ConstVal {
11761176
match lit.node {
11771177
hir::LitStr(ref s, _) => Str((*s).clone()),
1178-
hir::LitBinary(ref data) => {
1179-
Binary(data.clone())
1178+
hir::LitByteStr(ref data) => {
1179+
ByteStr(data.clone())
11801180
}
11811181
hir::LitByte(n) => Uint(n as u64),
11821182
hir::LitChar(n) => Uint(n as u64),
@@ -1214,7 +1214,7 @@ pub fn compare_const_vals(a: &ConstVal, b: &ConstVal) -> Option<Ordering> {
12141214
}
12151215
(&Str(ref a), &Str(ref b)) => a.cmp(b),
12161216
(&Bool(a), &Bool(b)) => a.cmp(&b),
1217-
(&Binary(ref a), &Binary(ref b)) => a.cmp(b),
1217+
(&ByteStr(ref a), &ByteStr(ref b)) => a.cmp(b),
12181218
_ => return None
12191219
})
12201220
}

src/librustc_front/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ pub enum Lit_ {
838838
/// A string literal (`"foo"`)
839839
LitStr(InternedString, StrStyle),
840840
/// A byte string (`b"foo"`)
841-
LitBinary(Rc<Vec<u8>>),
841+
LitByteStr(Rc<Vec<u8>>),
842842
/// A byte char (`b'f'`)
843843
LitByte(u8),
844844
/// A character literal (`'a'`)

src/librustc_front/lowering.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ pub fn lower_lit(l: &Lit) -> hir::Lit {
664664
Spanned {
665665
node: match l.node {
666666
LitStr(ref i, s) => hir::LitStr(i.clone(), lower_string_style(s)),
667-
LitBinary(ref b) => hir::LitBinary(b.clone()),
667+
LitByteStr(ref b) => hir::LitByteStr(b.clone()),
668668
LitByte(u) => hir::LitByte(u),
669669
LitChar(c) => hir::LitChar(c),
670670
LitInt(u, ref t) => hir::LitInt(u, lower_lit_int_type(t)),
@@ -680,7 +680,7 @@ pub fn unlower_lit(l: &hir::Lit) -> Lit {
680680
Spanned {
681681
node: match l.node {
682682
hir::LitStr(ref i, s) => LitStr(i.clone(), unlower_string_style(s)),
683-
hir::LitBinary(ref b) => LitBinary(b.clone()),
683+
hir::LitByteStr(ref b) => LitByteStr(b.clone()),
684684
hir::LitByte(u) => LitByte(u),
685685
hir::LitChar(c) => LitChar(c),
686686
hir::LitInt(u, ref t) => LitInt(u, unlower_lit_int_type(t)),

src/librustc_front/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,7 @@ impl<'a> State<'a> {
25492549
hir::LitBool(val) => {
25502550
if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") }
25512551
}
2552-
hir::LitBinary(ref v) => {
2552+
hir::LitByteStr(ref v) => {
25532553
let mut escaped: String = String::new();
25542554
for &ch in v.iter() {
25552555
escaped.extend(ascii::escape_default(ch)

src/librustc_trans/trans/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &hir::Lit)
9494
}
9595
hir::LitBool(b) => C_bool(cx, b),
9696
hir::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
97-
hir::LitBinary(ref data) => {
98-
addr_of(cx, C_bytes(cx, &data[..]), "binary")
97+
hir::LitByteStr(ref data) => {
98+
addr_of(cx, C_bytes(cx, &data[..]), "byte_str")
9999
}
100100
}
101101
}

src/librustc_typeck/check/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
5656
// They can denote both statically and dynamically sized byte arrays
5757
let mut pat_ty = expr_ty;
5858
if let hir::ExprLit(ref lt) = lt.node {
59-
if let hir::LitBinary(_) = lt.node {
59+
if let hir::LitByteStr(_) = lt.node {
6060
let expected_ty = structurally_resolved_type(fcx, pat.span, expected);
6161
if let ty::TyRef(_, mt) = expected_ty.sty {
6262
if let ty::TySlice(_) = mt.ty.sty {

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
26332633

26342634
match lit.node {
26352635
hir::LitStr(..) => tcx.mk_static_str(),
2636-
hir::LitBinary(ref v) => {
2636+
hir::LitByteStr(ref v) => {
26372637
tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic),
26382638
tcx.mk_array(tcx.types.u8, v.len()))
26392639
}

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2518,7 +2518,7 @@ impl ToSource for syntax::codemap::Span {
25182518
fn lit_to_string(lit: &hir::Lit) -> String {
25192519
match lit.node {
25202520
hir::LitStr(ref st, _) => st.to_string(),
2521-
hir::LitBinary(ref data) => format!("{:?}", data),
2521+
hir::LitByteStr(ref data) => format!("{:?}", data),
25222522
hir::LitByte(b) => {
25232523
let mut res = String::from("b'");
25242524
for c in (b as char).escape_default() {

src/librustdoc/html/highlight.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
131131
match lit {
132132
// text literals
133133
token::Byte(..) | token::Char(..) |
134-
token::Binary(..) | token::BinaryRaw(..) |
134+
token::ByteStr(..) | token::ByteStrRaw(..) |
135135
token::Str_(..) | token::StrRaw(..) => "string",
136136

137137
// number literals

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ pub enum Lit_ {
11901190
/// A string literal (`"foo"`)
11911191
LitStr(InternedString, StrStyle),
11921192
/// A byte string (`b"foo"`)
1193-
LitBinary(Rc<Vec<u8>>),
1193+
LitByteStr(Rc<Vec<u8>>),
11941194
/// A byte char (`b'f'`)
11951195
LitByte(u8),
11961196
/// A character literal (`'a'`)

src/libsyntax/ext/concat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
5050
accumulator.push_str(&format!("{}", b));
5151
}
5252
ast::LitByte(..) |
53-
ast::LitBinary(..) => {
54-
cx.span_err(e.span, "cannot concatenate a binary literal");
53+
ast::LitByteStr(..) => {
54+
cx.span_err(e.span, "cannot concatenate a byte string literal");
5555
}
5656
}
5757
}

src/libsyntax/ext/source_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
189189
let filename = format!("{}", file.display());
190190
cx.codemap().new_filemap_and_lines(&filename, "");
191191

192-
base::MacEager::expr(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes))))
192+
base::MacEager::expr(cx.expr_lit(sp, ast::LitByteStr(Rc::new(bytes))))
193193
}
194194
}
195195
}

src/libsyntax/parse/lexer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ impl<'a> StringReader<'a> {
13041304
}
13051305
let id = if valid { self.name_from(start) } else { token::intern("??") };
13061306
self.bump();
1307-
return token::Binary(id);
1307+
return token::ByteStr(id);
13081308
}
13091309

13101310
fn scan_raw_byte_string(&mut self) -> token::Lit {
@@ -1355,7 +1355,7 @@ impl<'a> StringReader<'a> {
13551355
self.bump();
13561356
}
13571357
self.bump();
1358-
return token::BinaryRaw(self.name_from_to(content_start_bpos,
1358+
return token::ByteStrRaw(self.name_from_to(content_start_bpos,
13591359
content_end_bpos),
13601360
hash_count);
13611361
}
@@ -1546,7 +1546,7 @@ mod tests {
15461546
test!("'a'", Char, "a");
15471547
test!("b'a'", Byte, "a");
15481548
test!("\"a\"", Str_, "a");
1549-
test!("b\"a\"", Binary, "a");
1549+
test!("b\"a\"", ByteStr, "a");
15501550
test!("1234", Integer, "1234");
15511551
test!("0b101", Integer, "0b101");
15521552
test!("0xABC", Integer, "0xABC");
@@ -1560,7 +1560,7 @@ mod tests {
15601560
token::Literal(token::StrRaw(token::intern("raw"), 3),
15611561
Some(token::intern("suffix"))));
15621562
assert_eq!(setup(&mk_sh(), "br###\"raw\"###suffix".to_string()).next_token().tok,
1563-
token::Literal(token::BinaryRaw(token::intern("raw"), 3),
1563+
token::Literal(token::ByteStrRaw(token::intern("raw"), 3),
15641564
Some(token::intern("suffix"))));
15651565
}
15661566

src/libsyntax/parse/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ pub fn byte_lit(lit: &str) -> (u8, usize) {
499499
}
500500
}
501501

502-
pub fn binary_lit(lit: &str) -> Rc<Vec<u8>> {
502+
pub fn byte_str_lit(lit: &str) -> Rc<Vec<u8>> {
503503
let mut res = Vec::with_capacity(lit.len());
504504

505505
// 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>> {
517517
}
518518
}
519519

520-
// binary literals *must* be ASCII, but the escapes don't have to be
520+
// byte string literals *must* be ASCII, but the escapes don't have to be
521521
let mut chars = lit.bytes().enumerate().peekable();
522522
loop {
523523
match chars.next() {

src/libsyntax/parse/parser.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst};
3434
use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, ItemDefaultImpl};
3535
use ast::{ItemExternCrate, ItemUse};
3636
use ast::{LifetimeDef, Lit, Lit_};
37-
use ast::{LitBool, LitChar, LitByte, LitBinary};
37+
use ast::{LitBool, LitChar, LitByte, LitByteStr};
3838
use ast::{LitStr, LitInt, Local};
3939
use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces};
4040
use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, MatchSource};
@@ -1543,11 +1543,11 @@ impl<'a> Parser<'a> {
15431543
token::intern_and_get_ident(&parse::raw_str_lit(&s.as_str())),
15441544
ast::RawStr(n)))
15451545
}
1546-
token::Binary(i) =>
1547-
(true, LitBinary(parse::binary_lit(&i.as_str()))),
1548-
token::BinaryRaw(i, _) =>
1546+
token::ByteStr(i) =>
1547+
(true, LitByteStr(parse::byte_str_lit(&i.as_str()))),
1548+
token::ByteStrRaw(i, _) =>
15491549
(true,
1550-
LitBinary(Rc::new(i.to_string().into_bytes()))),
1550+
LitByteStr(Rc::new(i.to_string().into_bytes()))),
15511551
};
15521552

15531553
if suffix_illegal {
@@ -5826,7 +5826,7 @@ impl<'a> Parser<'a> {
58265826
match try!(self.parse_optional_str()) {
58275827
Some((s, style, suf)) => {
58285828
let sp = self.last_span;
5829-
self.expect_no_suffix(sp, "str literal", suf);
5829+
self.expect_no_suffix(sp, "string literal", suf);
58305830
Ok((s, style))
58315831
}
58325832
_ => Err(self.fatal("expected string literal"))

0 commit comments

Comments
 (0)