From 891ada9be16451e46268ea0924c1710596e7ddbb Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sat, 1 Feb 2014 15:54:41 +1100 Subject: [PATCH] syntax: convert LitBinary from @[u8] to Rc<~[u8]>. --- src/librustc/middle/trans/consts.rs | 2 +- src/librustdoc/clean.rs | 2 +- src/libsyntax/ast.rs | 3 ++- src/libsyntax/ext/source_util.rs | 6 ++---- src/libsyntax/print/pprust.rs | 4 ++-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 8f69b3cc2f2d..a8b0da802668 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -75,7 +75,7 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::Lit) ast::LitBool(b) => C_bool(b), ast::LitNil => C_nil(), ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()), - ast::LitBinary(data) => C_binary_slice(cx, data), + ast::LitBinary(ref data) => C_binary_slice(cx, *data.borrow()), } } diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index 94e5273fced5..8220be104616 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -1151,7 +1151,7 @@ impl ToSource for syntax::codemap::Span { fn lit_to_str(lit: &ast::Lit) -> ~str { match lit.node { ast::LitStr(ref st, _) => st.get().to_owned(), - ast::LitBinary(data) => format!("{:?}", data.as_slice()), + ast::LitBinary(ref data) => format!("{:?}", data.borrow().as_slice()), ast::LitChar(c) => ~"'" + std::char::from_u32(c).unwrap().to_str() + "'", ast::LitInt(i, _t) => i.to_str(), ast::LitUint(u, _t) => u.to_str(), diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index fd8e9dbfa67c..dcac134329c2 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -20,6 +20,7 @@ use parse::token; use std::cell::RefCell; use std::hashmap::HashMap; use std::option::Option; +use std::rc::Rc; use std::to_str::ToStr; use extra::serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -724,7 +725,7 @@ pub type Lit = Spanned; #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum Lit_ { LitStr(InternedString, StrStyle), - LitBinary(@[u8]), + LitBinary(Rc<~[u8]>), LitChar(u32), LitInt(i64, IntTy), LitUint(u64, UintTy), diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 44f3bb379f63..f3f947ec00d3 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -22,6 +22,7 @@ use print::pprust; use std::io; use std::io::File; +use std::rc::Rc; use std::str; // These macros all relate to the file system; they either return @@ -135,8 +136,6 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { - use std::at_vec; - let file = match get_single_str_from_tts(cx, sp, tts, "include_bin!") { Some(f) => f, None => return MacResult::dummy_expr() @@ -148,8 +147,7 @@ pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) return MacResult::dummy_expr(); } Ok(bytes) => { - let bytes = at_vec::to_managed_move(bytes); - base::MRExpr(cx.expr_lit(sp, ast::LitBinary(bytes))) + base::MRExpr(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes)))) } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 2e20560b9cac..bdef5e093f2f 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2212,10 +2212,10 @@ pub fn print_literal(s: &mut State, lit: &ast::Lit) { ast::LitBool(val) => { if val { word(&mut s.s, "true"); } else { word(&mut s.s, "false"); } } - ast::LitBinary(arr) => { + ast::LitBinary(ref arr) => { ibox(s, indent_unit); word(&mut s.s, "["); - commasep_cmnt(s, Inconsistent, arr, |s, u| word(&mut s.s, format!("{}", *u)), + commasep_cmnt(s, Inconsistent, *arr.borrow(), |s, u| word(&mut s.s, format!("{}", *u)), |_| lit.span); word(&mut s.s, "]"); end(s);