From 405c616eaf4e58a8bed67924c364c8e9c83b2581 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 3 Sep 2015 10:54:53 +0300 Subject: [PATCH 01/14] Use consistent terminology for byte string literals Avoid confusion with binary integer literals and binary operator expressions in libsyntax --- src/grammar/RustLexer.g4 | 8 ++++---- src/grammar/lexer.l | 8 ++++---- src/grammar/parser-lalr.y | 12 ++++++------ src/grammar/tokens.h | 4 ++-- src/grammar/verify.rs | 16 ++++++++-------- src/librustc/middle/const_eval.rs | 10 +++++----- src/librustc_front/hir.rs | 2 +- src/librustc_front/lowering.rs | 4 ++-- src/librustc_front/print/pprust.rs | 2 +- src/librustc_trans/trans/consts.rs | 4 ++-- src/librustc_typeck/check/_match.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/html/highlight.rs | 2 +- src/libsyntax/ast.rs | 2 +- src/libsyntax/ext/concat.rs | 4 ++-- src/libsyntax/ext/source_util.rs | 2 +- src/libsyntax/parse/lexer/mod.rs | 8 ++++---- src/libsyntax/parse/mod.rs | 4 ++-- src/libsyntax/parse/parser.rs | 12 ++++++------ src/libsyntax/parse/token.rs | 8 ++++---- src/libsyntax/print/pprust.rs | 6 +++--- src/test/compile-fail/concat.rs | 4 ++-- src/test/parse-fail/bad-lit-suffixes.rs | 8 ++++---- .../run-make/symbols-are-reasonable/Makefile | 2 +- 25 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/grammar/RustLexer.g4 b/src/grammar/RustLexer.g4 index f062d33f25e2..5c13295451c7 100644 --- a/src/grammar/RustLexer.g4 +++ b/src/grammar/RustLexer.g4 @@ -13,8 +13,8 @@ tokens { BINOPEQ, AT, DOT, DOTDOT, DOTDOTDOT, COMMA, SEMI, COLON, MOD_SEP, RARROW, FAT_ARROW, LPAREN, RPAREN, LBRACKET, RBRACKET, LBRACE, RBRACE, POUND, DOLLAR, UNDERSCORE, LIT_CHAR, LIT_BYTE, - LIT_INTEGER, LIT_FLOAT, LIT_STR, LIT_STR_RAW, LIT_BINARY, - LIT_BINARY_RAW, QUESTION, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT, + LIT_INTEGER, LIT_FLOAT, LIT_STR, LIT_STR_RAW, LIT_BYTE_STR, + LIT_BYTE_STR_RAW, QUESTION, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT, COMMENT, SHEBANG, UTF8_BOM } @@ -148,8 +148,8 @@ LIT_STR : '"' ('\\\n' | '\\\r\n' | '\\' CHAR_ESCAPE | .)*? '"' SUFFIX? ; -LIT_BINARY : 'b' LIT_STR ; -LIT_BINARY_RAW : 'b' LIT_STR_RAW ; +LIT_BYTE_STR : 'b' LIT_STR ; +LIT_BYTE_STR_RAW : 'b' LIT_STR_RAW ; /* this is a bit messy */ diff --git a/src/grammar/lexer.l b/src/grammar/lexer.l index 719088aa44b6..dd7b1c74de74 100644 --- a/src/grammar/lexer.l +++ b/src/grammar/lexer.l @@ -200,7 +200,7 @@ while { return WHILE; } <> { BEGIN(INITIAL); return -1; } b\x22 { BEGIN(bytestr); yymore(); } -\x22 { BEGIN(suffix); return LIT_BINARY; } +\x22 { BEGIN(suffix); return LIT_BYTE_STR; } <> { return -1; } \\[n\nrt\\\x27\x220] { yymore(); } @@ -210,7 +210,7 @@ b\x22 { BEGIN(bytestr); yymore(); } (.|\n) { yymore(); } br\x22 { BEGIN(rawbytestr_nohash); yymore(); } -\x22 { BEGIN(suffix); return LIT_BINARY_RAW; } +\x22 { BEGIN(suffix); return LIT_BYTE_STR_RAW; } (.|\n) { yymore(); } <> { return -1; } @@ -228,7 +228,7 @@ br/# { end_hashes++; if (end_hashes == num_hashes) { BEGIN(INITIAL); - return LIT_BINARY_RAW; + return LIT_BYTE_STR_RAW; } } yymore(); @@ -237,7 +237,7 @@ br/# { end_hashes = 1; if (end_hashes == num_hashes) { BEGIN(INITIAL); - return LIT_BINARY_RAW; + return LIT_BYTE_STR_RAW; } yymore(); } diff --git a/src/grammar/parser-lalr.y b/src/grammar/parser-lalr.y index abdef4aa5ac8..75d9d28242f4 100644 --- a/src/grammar/parser-lalr.y +++ b/src/grammar/parser-lalr.y @@ -52,8 +52,8 @@ extern char *yytext; %token LIT_FLOAT %token LIT_STR %token LIT_STR_RAW -%token LIT_BINARY -%token LIT_BINARY_RAW +%token LIT_BYTE_STR +%token LIT_BYTE_STR_RAW %token IDENT %token UNDERSCORE %token LIFETIME @@ -1772,8 +1772,8 @@ lit str : LIT_STR { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("CookedStr")); } | LIT_STR_RAW { $$ = mk_node("LitStr", 1, mk_atom(yytext), mk_atom("RawStr")); } -| LIT_BINARY { $$ = mk_node("LitBinary", 1, mk_atom(yytext), mk_atom("BinaryStr")); } -| LIT_BINARY_RAW { $$ = mk_node("LitBinary", 1, mk_atom(yytext), mk_atom("RawBinaryStr")); } +| LIT_BYTE_STR { $$ = mk_node("LitByteStr", 1, mk_atom(yytext), mk_atom("ByteStr")); } +| LIT_BYTE_STR_RAW { $$ = mk_node("LitByteStr", 1, mk_atom(yytext), mk_atom("RawByteStr")); } ; maybe_ident @@ -1815,8 +1815,8 @@ unpaired_token | LIT_FLOAT { $$ = mk_atom(yytext); } | LIT_STR { $$ = mk_atom(yytext); } | LIT_STR_RAW { $$ = mk_atom(yytext); } -| LIT_BINARY { $$ = mk_atom(yytext); } -| LIT_BINARY_RAW { $$ = mk_atom(yytext); } +| LIT_BYTE_STR { $$ = mk_atom(yytext); } +| LIT_BYTE_STR_RAW { $$ = mk_atom(yytext); } | IDENT { $$ = mk_atom(yytext); } | UNDERSCORE { $$ = mk_atom(yytext); } | LIFETIME { $$ = mk_atom(yytext); } diff --git a/src/grammar/tokens.h b/src/grammar/tokens.h index 4457e3f8b5aa..081bd0502596 100644 --- a/src/grammar/tokens.h +++ b/src/grammar/tokens.h @@ -38,8 +38,8 @@ enum Token { LIT_FLOAT, LIT_STR, LIT_STR_RAW, - LIT_BINARY, - LIT_BINARY_RAW, + LIT_BYTE_STR, + LIT_BYTE_STR_RAW, IDENT, UNDERSCORE, LIFETIME, diff --git a/src/grammar/verify.rs b/src/grammar/verify.rs index 3235389f1d19..6709479b2b5b 100644 --- a/src/grammar/verify.rs +++ b/src/grammar/verify.rs @@ -107,8 +107,8 @@ fn parse_token_list(file: &str) -> HashMap { "OR" => token::BinOp(token::Or), "GT" => token::Gt, "LE" => token::Le, - "LIT_BINARY" => token::Literal(token::Binary(Name(0)), None), - "LIT_BINARY_RAW" => token::Literal(token::BinaryRaw(Name(0), 0), None), + "LIT_BYTE_STR" => token::Literal(token::ByteStr(Name(0)), None), + "LIT_BYTE_STR_RAW" => token::Literal(token::ByteStrRaw(Name(0), 0), None), "QUESTION" => token::Question, "SHEBANG" => token::Shebang(Name(0)), _ => continue, @@ -137,8 +137,8 @@ fn str_to_binop(s: &str) -> token::BinOpToken { } } -/// Assuming a string/binary literal, strip out the leading/trailing -/// hashes and surrounding quotes/raw/binary prefix. +/// Assuming a string/byte string literal, strip out the leading/trailing +/// hashes and surrounding quotes/raw/byte prefix. fn fix(mut lit: &str) -> ast::Name { if lit.char_at(0) == 'r' { if lit.char_at(1) == 'b' { @@ -205,8 +205,8 @@ fn parse_antlr_token(s: &str, tokens: &HashMap, surrogate_ token::DocComment(..) => token::DocComment(nm), token::Literal(token::Integer(..), n) => token::Literal(token::Integer(nm), n), token::Literal(token::Float(..), n) => token::Literal(token::Float(nm), n), - token::Literal(token::Binary(..), n) => token::Literal(token::Binary(nm), n), - token::Literal(token::BinaryRaw(..), n) => token::Literal(token::BinaryRaw(fix(content), + token::Literal(token::ByteStr(..), n) => token::Literal(token::ByteStr(nm), n), + token::Literal(token::ByteStrRaw(..), n) => token::Literal(token::ByteStrRaw(fix(content), count(content)), n), token::Ident(..) => token::Ident(ast::Ident { name: nm, ctxt: 0 }, token::ModName), @@ -340,8 +340,8 @@ fn main() { token::Literal(token::Float(..), _), token::Literal(token::Str_(..), _), token::Literal(token::StrRaw(..), _), - token::Literal(token::Binary(..), _), - token::Literal(token::BinaryRaw(..), _), + token::Literal(token::ByteStr(..), _), + token::Literal(token::ByteStrRaw(..), _), token::Ident(..), token::Lifetime(..), token::Interpolated(..), diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 039a9e55523f..e1cf6ace8432 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -269,7 +269,7 @@ pub enum ConstVal { Int(i64), Uint(u64), Str(InternedString), - Binary(Rc>), + ByteStr(Rc>), Bool(bool), Struct(ast::NodeId), Tuple(ast::NodeId), @@ -283,7 +283,7 @@ impl ConstVal { Int(_) => "positive integer", Uint(_) => "unsigned integer", Str(_) => "string literal", - Binary(_) => "binary array", + ByteStr(_) => "byte string literal", Bool(_) => "boolean", Struct(_) => "struct", Tuple(_) => "tuple", @@ -1175,8 +1175,8 @@ fn cast_const<'tcx>(tcx: &ty::ctxt<'tcx>, val: ConstVal, ty: Ty) -> CastResult { fn lit_to_const(lit: &hir::Lit, ty_hint: Option) -> ConstVal { match lit.node { hir::LitStr(ref s, _) => Str((*s).clone()), - hir::LitBinary(ref data) => { - Binary(data.clone()) + hir::LitByteStr(ref data) => { + ByteStr(data.clone()) } hir::LitByte(n) => Uint(n as u64), hir::LitChar(n) => Uint(n as u64), @@ -1214,7 +1214,7 @@ pub fn compare_const_vals(a: &ConstVal, b: &ConstVal) -> Option { } (&Str(ref a), &Str(ref b)) => a.cmp(b), (&Bool(a), &Bool(b)) => a.cmp(&b), - (&Binary(ref a), &Binary(ref b)) => a.cmp(b), + (&ByteStr(ref a), &ByteStr(ref b)) => a.cmp(b), _ => return None }) } diff --git a/src/librustc_front/hir.rs b/src/librustc_front/hir.rs index 6d7bef32ff72..6ea5fc2d6c87 100644 --- a/src/librustc_front/hir.rs +++ b/src/librustc_front/hir.rs @@ -838,7 +838,7 @@ pub enum Lit_ { /// A string literal (`"foo"`) LitStr(InternedString, StrStyle), /// A byte string (`b"foo"`) - LitBinary(Rc>), + LitByteStr(Rc>), /// A byte char (`b'f'`) LitByte(u8), /// A character literal (`'a'`) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index c723a027d050..aa7545d52d11 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -664,7 +664,7 @@ pub fn lower_lit(l: &Lit) -> hir::Lit { Spanned { node: match l.node { LitStr(ref i, s) => hir::LitStr(i.clone(), lower_string_style(s)), - LitBinary(ref b) => hir::LitBinary(b.clone()), + LitByteStr(ref b) => hir::LitByteStr(b.clone()), LitByte(u) => hir::LitByte(u), LitChar(c) => hir::LitChar(c), LitInt(u, ref t) => hir::LitInt(u, lower_lit_int_type(t)), @@ -680,7 +680,7 @@ pub fn unlower_lit(l: &hir::Lit) -> Lit { Spanned { node: match l.node { hir::LitStr(ref i, s) => LitStr(i.clone(), unlower_string_style(s)), - hir::LitBinary(ref b) => LitBinary(b.clone()), + hir::LitByteStr(ref b) => LitByteStr(b.clone()), hir::LitByte(u) => LitByte(u), hir::LitChar(c) => LitChar(c), hir::LitInt(u, ref t) => LitInt(u, unlower_lit_int_type(t)), diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs index eeb1f2e167a0..38dded781e1e 100644 --- a/src/librustc_front/print/pprust.rs +++ b/src/librustc_front/print/pprust.rs @@ -2549,7 +2549,7 @@ impl<'a> State<'a> { hir::LitBool(val) => { if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") } } - hir::LitBinary(ref v) => { + hir::LitByteStr(ref v) => { let mut escaped: String = String::new(); for &ch in v.iter() { escaped.extend(ascii::escape_default(ch) diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index b707c48adc88..d139819a79f9 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -94,8 +94,8 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &hir::Lit) } hir::LitBool(b) => C_bool(cx, b), hir::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()), - hir::LitBinary(ref data) => { - addr_of(cx, C_bytes(cx, &data[..]), "binary") + hir::LitByteStr(ref data) => { + addr_of(cx, C_bytes(cx, &data[..]), "byte_str") } } } diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index a17d97a824a7..f6f7586de5c5 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -56,7 +56,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, // They can denote both statically and dynamically sized byte arrays let mut pat_ty = expr_ty; if let hir::ExprLit(ref lt) = lt.node { - if let hir::LitBinary(_) = lt.node { + if let hir::LitByteStr(_) = lt.node { let expected_ty = structurally_resolved_type(fcx, pat.span, expected); if let ty::TyRef(_, mt) = expected_ty.sty { if let ty::TySlice(_) = mt.ty.sty { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c838243a2bad..a5fc9ce6a958 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2633,7 +2633,7 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, match lit.node { hir::LitStr(..) => tcx.mk_static_str(), - hir::LitBinary(ref v) => { + hir::LitByteStr(ref v) => { tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic), tcx.mk_array(tcx.types.u8, v.len())) } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5510d3ee0642..7ef359787e87 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2518,7 +2518,7 @@ impl ToSource for syntax::codemap::Span { fn lit_to_string(lit: &hir::Lit) -> String { match lit.node { hir::LitStr(ref st, _) => st.to_string(), - hir::LitBinary(ref data) => format!("{:?}", data), + hir::LitByteStr(ref data) => format!("{:?}", data), hir::LitByte(b) => { let mut res = String::from("b'"); for c in (b as char).escape_default() { diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 3facaef7b287..cca365d16c85 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -131,7 +131,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, match lit { // text literals token::Byte(..) | token::Char(..) | - token::Binary(..) | token::BinaryRaw(..) | + token::ByteStr(..) | token::ByteStrRaw(..) | token::Str_(..) | token::StrRaw(..) => "string", // number literals diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 25a3540c7436..ce3989b5bba4 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>), + LitByteStr(Rc>), /// 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 754c73a9d783..71430b7aad59 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 8da36b2c1e1f..25063e7b0d6f 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 019a8404dfb0..a0e170b4ace4 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 c5a73601d895..269f8bdd98ac 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> { +pub fn byte_str_lit(lit: &str) -> Rc> { 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> { } } - // 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 0772d124db8e..337e855f9009 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 bd4792554381..ca92a37d8c35 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 b93a244df130..341b177923ce 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) diff --git a/src/test/compile-fail/concat.rs b/src/test/compile-fail/concat.rs index dc31126e6d6e..e29c6ac5d5e9 100644 --- a/src/test/compile-fail/concat.rs +++ b/src/test/compile-fail/concat.rs @@ -9,8 +9,8 @@ // except according to those terms. fn main() { - concat!(b'f'); //~ ERROR: cannot concatenate a binary literal - concat!(b"foo"); //~ ERROR: cannot concatenate a binary literal + concat!(b'f'); //~ ERROR: cannot concatenate a byte string literal + concat!(b"foo"); //~ ERROR: cannot concatenate a byte string literal concat!(foo); //~ ERROR: expected a literal concat!(foo()); //~ ERROR: expected a literal } diff --git a/src/test/parse-fail/bad-lit-suffixes.rs b/src/test/parse-fail/bad-lit-suffixes.rs index a2ee2f6e88ca..d5985fcebeb2 100644 --- a/src/test/parse-fail/bad-lit-suffixes.rs +++ b/src/test/parse-fail/bad-lit-suffixes.rs @@ -20,10 +20,10 @@ extern {} fn main() { - ""suffix; //~ ERROR str literal with a suffix is invalid - b""suffix; //~ ERROR binary str literal with a suffix is invalid - r#""#suffix; //~ ERROR str literal with a suffix is invalid - br#""#suffix; //~ ERROR binary str literal with a suffix is invalid + ""suffix; //~ ERROR string literal with a suffix is invalid + b""suffix; //~ ERROR byte string literal with a suffix is invalid + r#""#suffix; //~ ERROR string literal with a suffix is invalid + br#""#suffix; //~ ERROR byte string literal with a suffix is invalid 'a'suffix; //~ ERROR char literal with a suffix is invalid b'a'suffix; //~ ERROR byte literal with a suffix is invalid diff --git a/src/test/run-make/symbols-are-reasonable/Makefile b/src/test/run-make/symbols-are-reasonable/Makefile index 89f610dee17d..c668ffc5832b 100644 --- a/src/test/run-make/symbols-are-reasonable/Makefile +++ b/src/test/run-make/symbols-are-reasonable/Makefile @@ -11,5 +11,5 @@ all: $(RUSTC) lib.rs --emit=asm --crate-type=staticlib # just check for symbol declarations with the names we're expecting. grep 'str[0-9][0-9]*:' $(OUT) - grep 'binary[0-9][0-9]*:' $(OUT) + grep 'byte_str[0-9][0-9]*:' $(OUT) grep 'vtable[0-9][0-9]*' $(OUT) From 8b2b9498306eaabf5a56a4bbf19340e0ee654030 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 3 Sep 2015 21:05:35 +0200 Subject: [PATCH 02/14] book: replace comma with a more suitable character --- src/doc/trpl/the-stack-and-the-heap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/the-stack-and-the-heap.md b/src/doc/trpl/the-stack-and-the-heap.md index e7e98c5828c1..6cf8e45ae1fd 100644 --- a/src/doc/trpl/the-stack-and-the-heap.md +++ b/src/doc/trpl/the-stack-and-the-heap.md @@ -38,7 +38,7 @@ local variables and some other information. This is called a ‘stack frame’, for the purpose of this tutorial, we’re going to ignore the extra information and just consider the local variables we’re allocating. So in this case, when `main()` is run, we’ll allocate a single 32-bit integer for our stack frame. -This is automatically handled for you, as you can see, we didn’t have to write +This is automatically handled for you, as you can see; we didn’t have to write any special Rust code or anything. When the function is over, its stack frame gets deallocated. This happens From 83aee74fce004106571cf27c320c117263055cee Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 3 Sep 2015 22:13:50 +0300 Subject: [PATCH 03/14] reference grammar: loop label should be optional This adds missing `?` marks to productions for loops and break/continue. It also adds missing option label to while let loop --- src/doc/grammar.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index 3aa89cba0314..76f544e10757 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -636,31 +636,31 @@ lambda_expr : '|' ident_list '|' expr ; ### While loops ```antlr -while_expr : [ lifetime ':' ] "while" no_struct_literal_expr '{' block '}' ; +while_expr : [ lifetime ':' ] ? "while" no_struct_literal_expr '{' block '}' ; ``` ### Infinite loops ```antlr -loop_expr : [ lifetime ':' ] "loop" '{' block '}'; +loop_expr : [ lifetime ':' ] ? "loop" '{' block '}'; ``` ### Break expressions ```antlr -break_expr : "break" [ lifetime ]; +break_expr : "break" [ lifetime ] ?; ``` ### Continue expressions ```antlr -continue_expr : "continue" [ lifetime ]; +continue_expr : "continue" [ lifetime ] ?; ``` ### For expressions ```antlr -for_expr : [ lifetime ':' ] "for" pat "in" no_struct_literal_expr '{' block '}' ; +for_expr : [ lifetime ':' ] ? "for" pat "in" no_struct_literal_expr '{' block '}' ; ``` ### If expressions @@ -694,7 +694,7 @@ else_tail : "else" [ if_expr | if_let_expr | '{' block '}' ] ; ### While let loops ```antlr -while_let_expr : "while" "let" pat '=' expr '{' block '}' ; +while_let_expr : [ lifetime ':' ] ? "while" "let" pat '=' expr '{' block '}' ; ``` ### Return expressions From 3525a13fea02169b4a02de722a5201296dc4ac8e Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 3 Sep 2015 21:14:01 +0200 Subject: [PATCH 04/14] book: "word" feels more suitable than "name" Also, add missing comma --- src/doc/trpl/the-stack-and-the-heap.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/the-stack-and-the-heap.md b/src/doc/trpl/the-stack-and-the-heap.md index e7e98c5828c1..5a39c94c0c36 100644 --- a/src/doc/trpl/the-stack-and-the-heap.md +++ b/src/doc/trpl/the-stack-and-the-heap.md @@ -51,7 +51,7 @@ we’ll throw them all away at the same time as well, we can get rid of it very fast too. The downside is that we can’t keep values around if we need them for longer -than a single function. We also haven’t talked about what that name, ‘stack’ +than a single function. We also haven’t talked about what the word, ‘stack’, means. To do that, we need a slightly more complicated example: ```rust From 986f523b89924b4ba47daf0beee283a65d26f355 Mon Sep 17 00:00:00 2001 From: benshu Date: Thu, 3 Sep 2015 21:17:59 +0200 Subject: [PATCH 05/14] Take method invocation semantics out of chapter on deref coercion. --- src/doc/trpl/deref-coercions.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/doc/trpl/deref-coercions.md b/src/doc/trpl/deref-coercions.md index b7011100971a..beb65c4ce358 100644 --- a/src/doc/trpl/deref-coercions.md +++ b/src/doc/trpl/deref-coercions.md @@ -89,8 +89,8 @@ Vectors can `Deref` to a slice. ## Deref and method calls -`Deref` will also kick in when calling a method. In other words, these are -the same two things in Rust: +`Deref` will also kick in when calling a method. Consider the following +example. ```rust struct Foo; @@ -99,13 +99,13 @@ impl Foo { fn foo(&self) { println!("Foo"); } } -let f = Foo; +let f = &&Foo; f.foo(); ``` -Even though `f` isn’t a reference, and `foo` takes `&self`, this works. -That’s because these things are the same: +Even though `f` is a `&&Foo` and `foo` takes `&self`, this works. That’s +because these things are the same: ```rust,ignore f.foo(); From 000fe0072675c932fd6036944aa3ed9fa77a6331 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 3 Sep 2015 22:19:56 +0300 Subject: [PATCH 06/14] reference grammar: remove duplicate else_tail rule --- src/doc/grammar.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index 3aa89cba0314..68c292490101 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -688,7 +688,6 @@ match_pat : pat [ '|' pat ] * [ "if" expr ] ? ; ```antlr if_let_expr : "if" "let" pat '=' expr '{' block '}' else_tail ? ; -else_tail : "else" [ if_expr | if_let_expr | '{' block '}' ] ; ``` ### While let loops From 59f2343bdb68d7fd3a253769e3dcb40d906b9eae Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 3 Sep 2015 22:25:47 +0300 Subject: [PATCH 07/14] reference grammar: remove procedure_type --- src/doc/grammar.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index 3aa89cba0314..8e1913df4a41 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -754,8 +754,6 @@ return_expr : "return" expr ? ; ```antlr closure_type := [ 'unsafe' ] [ '<' lifetime-list '>' ] '|' arg-list '|' [ ':' bound-list ] [ '->' type ] -procedure_type := 'proc' [ '<' lifetime-list '>' ] '(' arg-list ')' - [ ':' bound-list ] [ '->' type ] lifetime-list := lifetime | lifetime ',' lifetime-list arg-list := ident ':' type | ident ':' type ',' arg-list bound-list := bound | bound '+' bound-list From 197cec6ed90852408006e2dfdde91cbf5533cc23 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 3 Sep 2015 21:40:19 +0200 Subject: [PATCH 08/14] book: Rust is a language, so no need to mention that fact here --- src/doc/trpl/choosing-your-guarantees.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/choosing-your-guarantees.md b/src/doc/trpl/choosing-your-guarantees.md index 68812f342f13..f14b09c25b25 100644 --- a/src/doc/trpl/choosing-your-guarantees.md +++ b/src/doc/trpl/choosing-your-guarantees.md @@ -1,6 +1,6 @@ % Choosing your Guarantees -One important feature of Rust as language is that it lets us control the costs and guarantees +One important feature of Rust is that it lets us control the costs and guarantees of a program. There are various “wrapper type” abstractions in the Rust standard library which embody @@ -40,7 +40,7 @@ allowed to share references to this by the regular borrowing rules, checked at c [box]: ../std/boxed/struct.Box.html -## `&T` and `&mut T` +## `&T` and `&mut T` These are immutable and mutable references respectively. They follow the “read-write lock” pattern, such that one may either have only one mutable reference to some data, or any number of From 23956ae1f410b6a7697b55ac738e7ec27e9e727c Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 3 Sep 2015 21:54:00 +0200 Subject: [PATCH 09/14] book: improve flow --- src/doc/trpl/choosing-your-guarantees.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/trpl/choosing-your-guarantees.md b/src/doc/trpl/choosing-your-guarantees.md index 68812f342f13..af18296cdaaf 100644 --- a/src/doc/trpl/choosing-your-guarantees.md +++ b/src/doc/trpl/choosing-your-guarantees.md @@ -18,9 +18,9 @@ Before proceeding, it is highly recommended that one reads about [ownership][own ## `Box` -[`Box`][box] is pointer which is “owned”, or a “box”. While it can hand -out references to the contained data, it is the only owner of the data. In particular, when -something like the following occurs: +[`Box`][box] is an “owned” pointer, or a “box”. While it can hand +out references to the contained data, it is the only owner of the data. In particular, consider +the following: ```rust let x = Box::new(1); @@ -40,7 +40,7 @@ allowed to share references to this by the regular borrowing rules, checked at c [box]: ../std/boxed/struct.Box.html -## `&T` and `&mut T` +## `&T` and `&mut T` These are immutable and mutable references respectively. They follow the “read-write lock” pattern, such that one may either have only one mutable reference to some data, or any number of From 355847f5c13be35c12bfe879cadc58d6cbc2798f Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 3 Sep 2015 22:06:23 +0200 Subject: [PATCH 10/14] doc: reduce indentation of examples to 4 spaces Also, add trailing commas --- src/liballoc/rc.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index b1fb5be4d21b..2f92fb7bac5f 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -51,7 +51,7 @@ //! fn main() { //! // Create a reference counted Owner. //! let gadget_owner : Rc = Rc::new( -//! Owner { name: String::from("Gadget Man") } +//! Owner { name: String::from("Gadget Man") } //! ); //! //! // Create Gadgets belonging to gadget_owner. To increment the reference @@ -102,13 +102,13 @@ //! //! struct Owner { //! name: String, -//! gadgets: RefCell>> +//! gadgets: RefCell>>, //! // ...other fields //! } //! //! struct Gadget { //! id: i32, -//! owner: Rc +//! owner: Rc, //! // ...other fields //! } //! @@ -117,10 +117,10 @@ //! // Owner's vector of Gadgets inside a RefCell so that we can mutate it //! // through a shared reference. //! let gadget_owner : Rc = Rc::new( -//! Owner { -//! name: "Gadget Man".to_string(), -//! gadgets: RefCell::new(Vec::new()) -//! } +//! Owner { +//! name: "Gadget Man".to_string(), +//! gadgets: RefCell::new(Vec::new()), +//! } //! ); //! //! // Create Gadgets belonging to gadget_owner as before. From 6cdba4f7664de5a0dc7f030a69f6f3f84172f601 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 3 Sep 2015 22:14:28 +0200 Subject: [PATCH 11/14] book: it is RwLock, not RWLock --- src/doc/trpl/choosing-your-guarantees.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/choosing-your-guarantees.md b/src/doc/trpl/choosing-your-guarantees.md index 68812f342f13..7260b229f97f 100644 --- a/src/doc/trpl/choosing-your-guarantees.md +++ b/src/doc/trpl/choosing-your-guarantees.md @@ -40,7 +40,7 @@ allowed to share references to this by the regular borrowing rules, checked at c [box]: ../std/boxed/struct.Box.html -## `&T` and `&mut T` +## `&T` and `&mut T` These are immutable and mutable references respectively. They follow the “read-write lock” pattern, such that one may either have only one mutable reference to some data, or any number of @@ -243,7 +243,7 @@ Many of the types above cannot be used in a threadsafe manner. Particularly, `Rc `RefCell`, which both use non-atomic reference counts (_atomic_ reference counts are those which can be incremented from multiple threads without causing a data race), cannot be used this way. This makes them cheaper to use, but we need thread safe versions of these too. They exist, in the form of -`Arc` and `Mutex`/`RWLock` +`Arc` and `Mutex`/`RwLock` Note that the non-threadsafe types _cannot_ be sent between threads, and this is checked at compile time. From f7d5c25b3db26f24470d5dd2ec2f4aa38fde7032 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 3 Sep 2015 23:42:33 +0300 Subject: [PATCH 12/14] reference grammar: whitespace cleanup --- src/doc/grammar.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index 3aa89cba0314..a09e7fad0e87 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -281,7 +281,7 @@ type_path_tail : '<' type_expr [ ',' type_expr ] + '>' ## Macros ```antlr -expr_macro_rules : "macro_rules" '!' ident '(' macro_rule * ')' ';' +expr_macro_rules : "macro_rules" '!' ident '(' macro_rule * ')' ';' | "macro_rules" '!' ident '{' macro_rule * '}' ; macro_rule : '(' matcher * ')' "=>" '(' transcriber * ')' ';' ; matcher : '(' matcher * ')' | '[' matcher * ']' From 73a6199248528291bfdfbfb33529f21edd7f4ee2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 4 Sep 2015 00:29:47 +0300 Subject: [PATCH 13/14] reference grammar: fix item definition extern_block should extern_block_item --- src/doc/grammar.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/grammar.md b/src/doc/grammar.md index 3aa89cba0314..b43dd38ff166 100644 --- a/src/doc/grammar.md +++ b/src/doc/grammar.md @@ -306,7 +306,7 @@ transcriber : '(' transcriber * ')' | '[' transcriber * ']' ```antlr item : vis ? mod_item | fn_item | type_item | struct_item | enum_item - | const_item | static_item | trait_item | impl_item | extern_block ; + | const_item | static_item | trait_item | impl_item | extern_block_item ; ``` ### Type Parameters From 17fde3a34d8dfa07378cbff0f2552b41071e032f Mon Sep 17 00:00:00 2001 From: christopherdumas Date: Thu, 3 Sep 2015 14:39:34 -0700 Subject: [PATCH 14/14] Removed incorrect reference from #28196 --- src/doc/reference.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index dbcfafaf1c17..900d1306e050 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3200,16 +3200,6 @@ let z = match x { &0 => "zero", _ => "some" }; assert_eq!(y, z); ``` -A pattern that's just an identifier, like `Nil` in the previous example, could -either refer to an enum variant that's in scope, or bind a new variable. The -compiler resolves this ambiguity by forbidding variable bindings that occur in -`match` patterns from shadowing names of variants that are in scope. For -example, wherever `List` is in scope, a `match` pattern would not be able to -bind `Nil` as a new name. The compiler interprets a variable pattern `x` as a -binding _only_ if there is no variant named `x` in scope. A convention you can -use to avoid conflicts is simply to name variants with upper-case letters, and -local variables with lower-case letters. - Multiple match patterns may be joined with the `|` operator. A range of values may be specified with `...`. For example: