diff options
| author | bors <bors@rust-lang.org> | 2013-06-12 18:10:49 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-06-12 18:10:49 -0700 |
| commit | da510bfb4a3f6ca805e849372f9bbe7b2b0f6a61 (patch) | |
| tree | cb272a50c99d8001304f044fd8a1128d30654b61 /src/libsyntax | |
| parent | 84bed9769b5d15871481b657860ad6a7d0a62f42 (diff) | |
| parent | 5ebffd46d5f7476c8124856c37538088da0c918e (diff) | |
| download | rust-da510bfb4a3f6ca805e849372f9bbe7b2b0f6a61.tar.gz rust-da510bfb4a3f6ca805e849372f9bbe7b2b0f6a61.zip | |
auto merge of #7086 : huonw/rust/5048, r=graydon
Fixes #5048. I'm sure this reduces memory usage, but I can't get cgroups to work properly to actually measure memory. (It doesn't appear to offer much speed improvement, but I'm fairly sure it's not slower.) This is quite huge, so it'd be nice to get a resolution soon.
Diffstat (limited to 'src/libsyntax')
38 files changed, 432 insertions, 451 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f27ae3b828c..e3182916723 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -84,7 +84,7 @@ pub type Mrk = uint; impl<S:Encoder> Encodable<S> for ident { fn encode(&self, s: &mut S) { - s.emit_str(*interner_get(self.name)); + s.emit_str(interner_get(self.name)); } } @@ -228,9 +228,9 @@ pub type meta_item = spanned<meta_item_>; #[deriving(Eq, Encodable, Decodable)] pub enum meta_item_ { - meta_word(@~str), - meta_list(@~str, ~[@meta_item]), - meta_name_value(@~str, lit), + meta_word(@str), + meta_list(@str, ~[@meta_item]), + meta_name_value(@str, lit), } pub type blk = spanned<blk_>; @@ -634,12 +634,12 @@ pub type lit = spanned<lit_>; #[deriving(Eq, Encodable, Decodable)] pub enum lit_ { - lit_str(@~str), + lit_str(@str), lit_int(i64, int_ty), lit_uint(u64, uint_ty), lit_int_unsuffixed(i64), - lit_float(@~str, float_ty), - lit_float_unsuffixed(@~str), + lit_float(@str, float_ty), + lit_float_unsuffixed(@str), lit_nil, lit_bool(bool), } @@ -819,10 +819,10 @@ pub enum asm_dialect { #[deriving(Eq, Encodable, Decodable)] pub struct inline_asm { - asm: @~str, - clobbers: @~str, - inputs: ~[(@~str, @expr)], - outputs: ~[(@~str, @expr)], + asm: @str, + clobbers: @str, + inputs: ~[(@str, @expr)], + outputs: ~[(@str, @expr)], volatile: bool, alignstack: bool, dialect: asm_dialect diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 430567e3e2f..ca91d3a4f8c 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -58,8 +58,8 @@ pub fn path_to_str_with_sep(p: &[path_elt], sep: &str, itr: @ident_interner) -> ~str { let strs = do p.map |e| { match *e { - path_mod(s) => copy *itr.get(s.name), - path_name(s) => copy *itr.get(s.name) + path_mod(s) => itr.get(s.name), + path_name(s) => itr.get(s.name) } }; strs.connect(sep) @@ -68,9 +68,9 @@ pub fn path_to_str_with_sep(p: &[path_elt], sep: &str, itr: @ident_interner) pub fn path_ident_to_str(p: &path, i: ident, itr: @ident_interner) -> ~str { if p.is_empty() { //FIXME /* FIXME (#2543) */ copy *i - copy *itr.get(i.name) + itr.get(i.name).to_owned() } else { - fmt!("%s::%s", path_to_str(*p, itr), *itr.get(i.name)) + fmt!("%s::%s", path_to_str(*p, itr), itr.get(i.name)) } } @@ -80,8 +80,8 @@ pub fn path_to_str(p: &[path_elt], itr: @ident_interner) -> ~str { pub fn path_elt_to_str(pe: path_elt, itr: @ident_interner) -> ~str { match pe { - path_mod(s) => copy *itr.get(s.name), - path_name(s) => copy *itr.get(s.name) + path_mod(s) => itr.get(s.name).to_owned(), + path_name(s) => itr.get(s.name).to_owned() } } @@ -359,16 +359,16 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { } Some(&node_method(m, _, path)) => { fmt!("method %s in %s (id=%?)", - *itr.get(m.ident.name), path_to_str(*path, itr), id) + itr.get(m.ident.name), path_to_str(*path, itr), id) } Some(&node_trait_method(ref tm, _, path)) => { let m = ast_util::trait_method_to_ty_method(&**tm); fmt!("method %s in %s (id=%?)", - *itr.get(m.ident.name), path_to_str(*path, itr), id) + itr.get(m.ident.name), path_to_str(*path, itr), id) } Some(&node_variant(ref variant, _, path)) => { fmt!("variant %s in %s (id=%?)", - *itr.get(variant.node.name.name), path_to_str(*path, itr), id) + itr.get(variant.node.name.name), path_to_str(*path, itr), id) } Some(&node_expr(expr)) => { fmt!("expr %s (id=%?)", pprust::expr_to_str(expr, itr), id) @@ -384,7 +384,7 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { fmt!("arg (id=%?)", id) } Some(&node_local(ident)) => { - fmt!("local (id=%?, name=%s)", id, *itr.get(ident.name)) + fmt!("local (id=%?, name=%s)", id, itr.get(ident.name)) } Some(&node_block(_)) => { fmt!("block") diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 904f35bce5a..d4aa9229319 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -28,7 +28,7 @@ use core::iterator::IteratorUtil; pub fn path_name_i(idents: &[ident]) -> ~str { // FIXME: Bad copies (#2543 -- same for everything else that says "bad") - idents.map(|i| copy *token::interner_get(i.name)).connect("::") + idents.map(|i| token::interner_get(i.name)).connect("::") } pub fn path_to_ident(p: @Path) -> ident { copy *p.idents.last() } @@ -815,7 +815,7 @@ mod test { assert_eq!(copy s,~[14]); } - // convert a list of uints to an @~[ident] + // convert a list of uints to an @[ident] // (ignores the interner completely) fn uints_to_idents (uints: &~[uint]) -> @~[ident] { @uints.map(|u|{ ident {name:*u, ctxt: empty_ctxt} }) diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index da5874f7b05..1bf21c18886 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -26,23 +26,23 @@ use extra; /* Constructors */ -pub fn mk_name_value_item_str(name: @~str, value: @~str) +pub fn mk_name_value_item_str(name: @str, value: @str) -> @ast::meta_item { let value_lit = dummy_spanned(ast::lit_str(value)); mk_name_value_item(name, value_lit) } -pub fn mk_name_value_item(name: @~str, value: ast::lit) +pub fn mk_name_value_item(name: @str, value: ast::lit) -> @ast::meta_item { @dummy_spanned(ast::meta_name_value(name, value)) } -pub fn mk_list_item(name: @~str, items: ~[@ast::meta_item]) -> +pub fn mk_list_item(name: @str, items: ~[@ast::meta_item]) -> @ast::meta_item { @dummy_spanned(ast::meta_list(name, items)) } -pub fn mk_word_item(name: @~str) -> @ast::meta_item { +pub fn mk_word_item(name: @str) -> @ast::meta_item { @dummy_spanned(ast::meta_word(name)) } @@ -52,13 +52,13 @@ pub fn mk_attr(item: @ast::meta_item) -> ast::attribute { is_sugared_doc: false }) } -pub fn mk_sugared_doc_attr(text: ~str, +pub fn mk_sugared_doc_attr(text: @str, lo: BytePos, hi: BytePos) -> ast::attribute { let style = doc_comment_style(text); - let lit = spanned(lo, hi, ast::lit_str(@text)); + let lit = spanned(lo, hi, ast::lit_str(text)); let attr = ast::attribute_ { style: style, - value: @spanned(lo, hi, ast::meta_name_value(@~"doc", lit)), + value: @spanned(lo, hi, ast::meta_name_value(@"doc", lit)), is_sugared_doc: true }; spanned(lo, hi, attr) @@ -78,8 +78,8 @@ pub fn attr_metas(attrs: &[ast::attribute]) -> ~[@ast::meta_item] { pub fn desugar_doc_attr(attr: &ast::attribute) -> ast::attribute { if attr.node.is_sugared_doc { let comment = get_meta_item_value_str(attr.node.value).get(); - let meta = mk_name_value_item_str(@~"doc", - @strip_doc_comment_decoration(*comment)); + let meta = mk_name_value_item_str(@"doc", + strip_doc_comment_decoration(comment).to_managed()); mk_attr(meta) } else { *attr @@ -88,11 +88,11 @@ pub fn desugar_doc_attr(attr: &ast::attribute) -> ast::attribute { /* Accessors */ -pub fn get_attr_name(attr: &ast::attribute) -> @~str { +pub fn get_attr_name(attr: &ast::attribute) -> @str { get_meta_item_name(attr.node.value) } -pub fn get_meta_item_name(meta: @ast::meta_item) -> @~str { +pub fn get_meta_item_name(meta: @ast::meta_item) -> @str { match meta.node { ast::meta_word(n) => n, ast::meta_name_value(n, _) => n, @@ -104,7 +104,7 @@ pub fn get_meta_item_name(meta: @ast::meta_item) -> @~str { * Gets the string value if the meta_item is a meta_name_value variant * containing a string, otherwise none */ -pub fn get_meta_item_value_str(meta: @ast::meta_item) -> Option<@~str> { +pub fn get_meta_item_value_str(meta: @ast::meta_item) -> Option<@str> { match meta.node { ast::meta_name_value(_, v) => { match v.node { @@ -130,7 +130,7 @@ pub fn get_meta_item_list(meta: @ast::meta_item) * a tuple containing the name and string value, otherwise `none` */ pub fn get_name_value_str_pair(item: @ast::meta_item) - -> Option<(@~str, @~str)> { + -> Option<(@str, @str)> { match attr::get_meta_item_value_str(item) { Some(value) => { let name = attr::get_meta_item_name(item); @@ -147,7 +147,7 @@ pub fn get_name_value_str_pair(item: @ast::meta_item) pub fn find_attrs_by_name(attrs: &[ast::attribute], name: &str) -> ~[ast::attribute] { do vec::filter_mapped(attrs) |a| { - if name == *get_attr_name(a) { + if name == get_attr_name(a) { Some(*a) } else { None @@ -160,7 +160,7 @@ pub fn find_meta_items_by_name(metas: &[@ast::meta_item], name: &str) -> ~[@ast::meta_item] { let mut rs = ~[]; for metas.each |mi| { - if name == *get_meta_item_name(*mi) { + if name == get_meta_item_name(*mi) { rs.push(*mi) } } @@ -214,7 +214,7 @@ pub fn attrs_contains_name(attrs: &[ast::attribute], name: &str) -> bool { } pub fn first_attr_value_str_by_name(attrs: &[ast::attribute], name: &str) - -> Option<@~str> { + -> Option<@str> { let mattrs = find_attrs_by_name(attrs, name); if mattrs.len() > 0 { @@ -232,7 +232,7 @@ fn last_meta_item_by_name(items: &[@ast::meta_item], name: &str) } pub fn last_meta_item_value_str_by_name(items: &[@ast::meta_item], name: &str) - -> Option<@~str> { + -> Option<@str> { match last_meta_item_by_name(items, name) { Some(item) => { @@ -282,7 +282,7 @@ pub fn remove_meta_items_by_name(items: ~[@ast::meta_item], name: &str) -> ~[@ast::meta_item] { return vec::filter_mapped(items, |item| { - if name != *get_meta_item_name(*item) { + if name != get_meta_item_name(*item) { Some(*item) } else { None @@ -316,8 +316,8 @@ pub fn find_inline_attr(attrs: &[ast::attribute]) -> inline_attr { // FIXME (#2809)---validate the usage of #[inline] and #[inline(always)] do attrs.iter().fold(ia_none) |ia,attr| { match attr.node.value.node { - ast::meta_word(@~"inline") => ia_hint, - ast::meta_list(@~"inline", ref items) => { + ast::meta_word(s) if "inline" == s => ia_hint, + ast::meta_list(s, ref items) if "inline" == s => { if !find_meta_items_by_name(*items, "always").is_empty() { ia_always } else if !find_meta_items_by_name(*items, "never").is_empty() { @@ -341,7 +341,7 @@ pub fn require_unique_names(diagnostic: @span_handler, // FIXME: How do I silence the warnings? --pcw (#2619) if !set.insert(name) { diagnostic.span_fatal(meta.span, - fmt!("duplicate meta item `%s`", *name)); + fmt!("duplicate meta item `%s`", name)); } } } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 68403b2c608..0c09a001d48 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -184,7 +184,7 @@ pub struct Loc { // Actually, *none* of the clients use the filename *or* file field; // perhaps they should just be removed. pub struct LocWithOpt { - filename: ~str, + filename: FileName, line: uint, col: CharPos, file: Option<@FileMap>, @@ -193,7 +193,7 @@ pub struct LocWithOpt { // used to be structural records. Better names, anyone? pub struct FileMapAndLine {fm: @FileMap, line: uint} pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos} -pub struct NameAndSpan {name: ~str, span: Option<span>} +pub struct NameAndSpan {name: @str, span: Option<span>} impl to_bytes::IterBytes for NameAndSpan { fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { @@ -227,7 +227,7 @@ impl to_bytes::IterBytes for ExpnInfo { } } -pub type FileName = ~str; +pub type FileName = @str; pub struct FileLines { @@ -261,7 +261,7 @@ pub struct FileMap { /// Extra information used by qquote substr: FileSubstr, /// The complete source code - src: @~str, + src: @str, /// The start position of this source in the CodeMap start_pos: BytePos, /// Locations of lines beginnings in the source code @@ -316,14 +316,14 @@ impl CodeMap { } /// Add a new FileMap to the CodeMap and return it - pub fn new_filemap(&self, filename: FileName, src: @~str) -> @FileMap { + pub fn new_filemap(&self, filename: FileName, src: @str) -> @FileMap { return self.new_filemap_w_substr(filename, FssNone, src); } pub fn new_filemap_w_substr(&self, filename: FileName, substr: FileSubstr, - src: @~str) + src: @str) -> @FileMap { let files = &mut *self.files; let start_pos = if files.len() == 0 { @@ -362,7 +362,7 @@ impl CodeMap { match (loc.file.substr) { FssNone => LocWithOpt { - filename: /* FIXME (#2543) */ copy loc.file.name, + filename: loc.file.name, line: loc.line, col: loc.col, file: Some(loc.file)}, @@ -421,8 +421,8 @@ impl CodeMap { begin.pos.to_uint(), end.pos.to_uint()).to_owned(); } - pub fn get_filemap(&self, filename: ~str) -> @FileMap { - for self.files.each |fm| { if fm.name == filename { return *fm; } } + pub fn get_filemap(&self, filename: &str) -> @FileMap { + for self.files.each |fm| { if filename == fm.name { return *fm; } } //XXjdm the following triggers a mismatched type bug // (or expected function, found _|_) fail!(); // ("asking for " + filename + " which we don't know about"); @@ -532,7 +532,7 @@ mod test { #[test] fn t1 () { let cm = CodeMap::new(); - let fm = cm.new_filemap(~"blork.rs",@~"first line.\nsecond line"); + let fm = cm.new_filemap(@"blork.rs",@"first line.\nsecond line"); fm.next_line(BytePos(0)); assert_eq!(&fm.get_line(0),&~"first line."); // TESTING BROKEN BEHAVIOR: @@ -544,7 +544,7 @@ mod test { #[should_fail] fn t2 () { let cm = CodeMap::new(); - let fm = cm.new_filemap(~"blork.rs",@~"first line.\nsecond line"); + let fm = cm.new_filemap(@"blork.rs",@"first line.\nsecond line"); // TESTING *REALLY* BROKEN BEHAVIOR: fm.next_line(BytePos(0)); fm.next_line(BytePos(10)); diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 1a2569ef787..36100e3f52f 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -306,8 +306,8 @@ fn highlight_lines(cm: @codemap::CodeMap, fn print_macro_backtrace(cm: @codemap::CodeMap, sp: span) { for sp.expn_info.iter().advance |ei| { - let ss = ei.callee.span.map_default(@~"", |span| @cm.span_to_str(*span)); - print_diagnostic(*ss, note, + let ss = ei.callee.span.map_default(~"", |span| cm.span_to_str(*span)); + print_diagnostic(ss, note, fmt!("in expansion of %s!", ei.callee.name)); let ss = cm.span_to_str(ei.call_site); print_diagnostic(ss, note, "expansion site"); diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index f9f9f7216a4..0394ccb3efb 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -45,7 +45,7 @@ pub fn expand_asm(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) cx.cfg(), tts.to_owned()); - let mut asm = ~""; + let mut asm = @""; let mut outputs = ~[]; let mut inputs = ~[]; let mut cons = ~""; @@ -113,7 +113,7 @@ pub fn expand_asm(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) p.eat(&token::COMMA); } - let clob = ~"~{" + *p.parse_str() + "}"; + let clob = fmt!("~{%s}", p.parse_str()); clobs.push(clob); } @@ -122,11 +122,11 @@ pub fn expand_asm(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) Options => { let option = p.parse_str(); - if "volatile" == *option { + if "volatile" == option { volatile = true; - } else if "alignstack" == *option { + } else if "alignstack" == option { alignstack = true; - } else if "intel" == *option { + } else if "intel" == option { dialect = ast::asm_intel; } @@ -176,8 +176,8 @@ pub fn expand_asm(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) MRExpr(@ast::expr { id: cx.next_id(), node: ast::expr_inline_asm(ast::inline_asm { - asm: @asm, - clobbers: @cons, + asm: asm, + clobbers: cons.to_managed(), inputs: inputs, outputs: outputs, volatile: volatile, diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 73f68735bcd..8e30a5880d5 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -33,7 +33,7 @@ use core::hashmap::HashMap; // ast::mac_invoc_tt. pub struct MacroDef { - name: ~str, + name: @str, ext: SyntaxExtension } @@ -308,18 +308,18 @@ impl ExtCtxt { pub fn set_trace_macros(&self, x: bool) { *self.trace_mac = x } - pub fn str_of(&self, id: ast::ident) -> ~str { - copy *ident_to_str(&id) + pub fn str_of(&self, id: ast::ident) -> @str { + ident_to_str(&id) } pub fn ident_of(&self, st: &str) -> ast::ident { str_to_ident(st) } } -pub fn expr_to_str(cx: @ExtCtxt, expr: @ast::expr, err_msg: ~str) -> ~str { +pub fn expr_to_str(cx: @ExtCtxt, expr: @ast::expr, err_msg: ~str) -> @str { match expr.node { ast::expr_lit(l) => match l.node { - ast::lit_str(s) => copy *s, + ast::lit_str(s) => s, _ => cx.span_fatal(l.span, err_msg) }, _ => cx.span_fatal(expr.span, err_msg) @@ -350,7 +350,7 @@ pub fn check_zero_tts(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree], pub fn get_single_str_from_tts(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree], - name: &str) -> ~str { + name: &str) -> @str { if tts.len() != 1 { cx.span_fatal(sp, fmt!("%s takes 1 argument.", name)); } @@ -538,25 +538,25 @@ mod test { #[test] fn testenv () { let mut a = HashMap::new(); - a.insert (@~"abc",@15); + a.insert (@"abc",@15); let m = MapChain::new(~a); - m.insert (@~"def",@16); - // FIXME: #4492 (ICE) assert_eq!(m.find(&@~"abc"),Some(@15)); - // .... assert_eq!(m.find(&@~"def"),Some(@16)); - assert_eq!(*(m.find(&@~"abc").get()),15); - assert_eq!(*(m.find(&@~"def").get()),16); + m.insert (@"def",@16); + // FIXME: #4492 (ICE) assert_eq!(m.find(&@"abc"),Some(@15)); + // .... assert_eq!(m.find(&@"def"),Some(@16)); + assert_eq!(*(m.find(&@"abc").get()),15); + assert_eq!(*(m.find(&@"def").get()),16); let n = m.push_frame(); // old bindings are still present: - assert_eq!(*(n.find(&@~"abc").get()),15); - assert_eq!(*(n.find(&@~"def").get()),16); - n.insert (@~"def",@17); + assert_eq!(*(n.find(&@"abc").get()),15); + assert_eq!(*(n.find(&@"def").get()),16); + n.insert (@"def",@17); // n shows the new binding - assert_eq!(*(n.find(&@~"abc").get()),15); - assert_eq!(*(n.find(&@~"def").get()),17); + assert_eq!(*(n.find(&@"abc").get()),15); + assert_eq!(*(n.find(&@"def").get()),17); // ... but m still has the old ones - // FIXME: #4492: assert_eq!(m.find(&@~"abc"),Some(@15)); - // FIXME: #4492: assert_eq!(m.find(&@~"def"),Some(@16)); - assert_eq!(*(m.find(&@~"abc").get()),15); - assert_eq!(*(m.find(&@~"def").get()),16); + // FIXME: #4492: assert_eq!(m.find(&@"abc"),Some(@15)); + // FIXME: #4492: assert_eq!(m.find(&@"def"),Some(@16)); + assert_eq!(*(m.find(&@"abc").get()),15); + assert_eq!(*(m.find(&@"def").get()),16); } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 324b909fbb0..dc31a248065 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -126,8 +126,8 @@ pub trait AstBuilder { fn expr_vec(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr; fn expr_vec_uniq(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr; fn expr_vec_slice(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr; - fn expr_str(&self, sp: span, s: ~str) -> @ast::expr; - fn expr_str_uniq(&self, sp: span, s: ~str) -> @ast::expr; + fn expr_str(&self, sp: span, s: @str) -> @ast::expr; + fn expr_str_uniq(&self, sp: span, s: @str) -> @ast::expr; fn expr_unreachable(&self, span: span) -> @ast::expr; @@ -215,9 +215,9 @@ pub trait AstBuilder { fn attribute(&self, sp: span, mi: @ast::meta_item) -> ast::attribute; - fn meta_word(&self, sp: span, w: ~str) -> @ast::meta_item; - fn meta_list(&self, sp: span, name: ~str, mis: ~[@ast::meta_item]) -> @ast::meta_item; - fn meta_name_value(&self, sp: span, name: ~str, value: ast::lit_) -> @ast::meta_item; + fn meta_word(&self, sp: span, w: @str) -> @ast::meta_item; + fn meta_list(&self, sp: span, name: @str, mis: ~[@ast::meta_item]) -> @ast::meta_item; + fn meta_name_value(&self, sp: span, name: @str, value: ast::lit_) -> @ast::meta_item; fn view_use(&self, sp: span, vis: ast::visibility, vp: ~[@ast::view_path]) -> @ast::view_item; @@ -521,10 +521,10 @@ impl AstBuilder for @ExtCtxt { fn expr_vec_slice(&self, sp: span, exprs: ~[@ast::expr]) -> @ast::expr { self.expr_vstore(sp, self.expr_vec(sp, exprs), ast::expr_vstore_slice) } - fn expr_str(&self, sp: span, s: ~str) -> @ast::expr { - self.expr_lit(sp, ast::lit_str(@s)) + fn expr_str(&self, sp: span, s: @str) -> @ast::expr { + self.expr_lit(sp, ast::lit_str(s)) } - fn expr_str_uniq(&self, sp: span, s: ~str) -> @ast::expr { + fn expr_str_uniq(&self, sp: span, s: @str) -> @ast::expr { self.expr_vstore(sp, self.expr_str(sp, s), ast::expr_vstore_uniq) } @@ -540,8 +540,8 @@ impl AstBuilder for @ExtCtxt { self.ident_of("fail_with"), ], ~[ - self.expr_str(span, ~"internal error: entered unreachable code"), - self.expr_str(span, copy loc.file.name), + self.expr_str(span, @"internal error: entered unreachable code"), + self.expr_str(span, loc.file.name), self.expr_uint(span, loc.line), ]) } @@ -791,14 +791,14 @@ impl AstBuilder for @ExtCtxt { }) } - fn meta_word(&self, sp: span, w: ~str) -> @ast::meta_item { - @respan(sp, ast::meta_word(@w)) + fn meta_word(&self, sp: span, w: @str) -> @ast::meta_item { + @respan(sp, ast::meta_word(w)) } - fn meta_list(&self, sp: span, name: ~str, mis: ~[@ast::meta_item]) -> @ast::meta_item { - @respan(sp, ast::meta_list(@name, mis)) + fn meta_list(&self, sp: span, name: @str, mis: ~[@ast::meta_item]) -> @ast::meta_item { + @respan(sp, ast::meta_list(name, mis)) } - fn meta_name_value(&self, sp: span, name: ~str, value: ast::lit_) -> @ast::meta_item { - @respan(sp, ast::meta_name_value(@name, respan(sp, value))) + fn meta_name_value(&self, sp: span, name: @str, value: ast::lit_) -> @ast::meta_item { + @respan(sp, ast::meta_name_value(name, respan(sp, value))) } fn view_use(&self, sp: span, diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 2081f262825..abea7912fc8 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -72,7 +72,7 @@ fn decodable_substructure(cx: @ExtCtxt, span: span, }; let read_struct_field = cx.ident_of("read_struct_field"); - let getarg = |name: ~str, field: uint| { + let getarg = |name: @str, field: uint| { cx.expr_method_call(span, blkdecoder, read_struct_field, ~[cx.expr_str(span, name), cx.expr_uint(span, field), @@ -86,7 +86,7 @@ fn decodable_substructure(cx: @ExtCtxt, span: span, } else { let mut fields = vec::with_capacity(n); for uint::range(0, n) |i| { - fields.push(getarg(fmt!("_field%u", i), i)); + fields.push(getarg(fmt!("_field%u", i).to_managed(), i)); } cx.expr_call_ident(span, substr.type_ident, fields) } diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 2d24de553d6..d7e64caa5c8 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -127,7 +127,7 @@ fn encodable_substructure(cx: @ExtCtxt, span: span, for fields.eachi |i, f| { let (name, val) = match *f { (Some(id), e, _) => (cx.str_of(id), e), - (None, e, _) => (fmt!("_field%u", i), e) + (None, e, _) => (fmt!("_field%u", i).to_managed(), e) }; let enc = cx.expr_method_call(span, val, encode, ~[blkencoder]); let lambda = cx.lambda_expr_1(span, enc, blkarg); diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 078fd4231ca..5d07171bbb1 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -364,7 +364,7 @@ impl<'self> TraitDef<'self> { let doc_attr = cx.attribute( span, cx.meta_name_value(span, - ~"doc", ast::lit_str(@~"Automatically derived."))); + @"doc", ast::lit_str(@"Automatically derived."))); cx.item( span, ::parse::token::special_idents::clownshoes_extensions, diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index c091ab8b617..606e372a25d 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -82,23 +82,23 @@ pub fn expand_meta_deriving(cx: @ExtCtxt, meta_word(tname) => { macro_rules! expand(($func:path) => ($func(cx, titem.span, titem, in_items))); - match *tname { - ~"Clone" => expand!(clone::expand_deriving_clone), - ~"DeepClone" => expand!(clone::expand_deriving_deep_clone), + match tname.as_slice() { + "Clone" => expand!(clone::expand_deriving_clone), + "DeepClone" => expand!(clone::expand_deriving_deep_clone), - ~"IterBytes" => expand!(iter_bytes::expand_deriving_iter_bytes), + "IterBytes" => expand!(iter_bytes::expand_deriving_iter_bytes), - ~"Encodable" => expand!(encodable::expand_deriving_encodable), - ~"Decodable" => expand!(decodable::expand_deriving_decodable), + "Encodable" => expand!(encodable::expand_deriving_encodable), + "Decodable" => expand!(decodable::expand_deriving_decodable), - ~"Eq" => expand!(eq::expand_deriving_eq), - ~"TotalEq" => expand!(totaleq::expand_deriving_totaleq), - ~"Ord" => expand!(ord::expand_deriving_ord), - ~"TotalOrd" => expand!(totalord::expand_deriving_totalord), + "Eq" => expand!(eq::expand_deriving_eq), + "TotalEq" => expand!(totaleq::expand_deriving_totaleq), + "Ord" => expand!(ord::expand_deriving_ord), + "TotalOrd" => expand!(totalord::expand_deriving_totalord), - ~"Rand" => expand!(rand::expand_deriving_rand), + "Rand" => expand!(rand::expand_deriving_rand), - ~"ToStr" => expand!(to_str::expand_deriving_to_str), + "ToStr" => expand!(to_str::expand_deriving_to_str), ref tname => { cx.span_err(titem.span, fmt!("unknown \ diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 4d074b4d0e6..34be6fc8143 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -33,8 +33,8 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) // Option<str> rather than just an maybe-empty string. let e = match os::getenv(var) { - None => cx.expr_str(sp, ~""), - Some(ref s) => cx.expr_str(sp, copy *s) + None => cx.expr_str(sp, @""), + Some(s) => cx.expr_str(sp, s.to_managed()) }; MRExpr(e) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index fe751d279d2..7ca8ab911de 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -57,7 +57,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, None => { cx.span_fatal( pth.span, - fmt!("macro undefined: '%s'", *extnamestr)) + fmt!("macro undefined: '%s'", extnamestr)) } Some(@SE(NormalTT(SyntaxExpanderTT{ expander: exp, @@ -66,7 +66,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, cx.bt_push(ExpandedFrom(CallInfo { call_site: s, callee: NameAndSpan { - name: copy *extnamestr, + name: extnamestr, span: exp_sp, }, })); @@ -79,7 +79,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, pth.span, fmt!( "non-expr macro in expr pos: %s", - *extnamestr + extnamestr ) ) } @@ -95,7 +95,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, _ => { cx.span_fatal( pth.span, - fmt!("'%s' is not a tt-style macro", *extnamestr) + fmt!("'%s' is not a tt-style macro", extnamestr) ) } } @@ -132,12 +132,12 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv, do item.attrs.rev_iter().fold(~[*item]) |items, attr| { let mname = attr::get_attr_name(attr); - match (*extsbox).find(&intern(*mname)) { + match (*extsbox).find(&intern(mname)) { Some(@SE(ItemDecorator(dec_fn))) => { cx.bt_push(ExpandedFrom(CallInfo { call_site: attr.span, callee: NameAndSpan { - name: /*bad*/ copy *mname, + name: mname, span: None } })); @@ -201,7 +201,7 @@ pub fn expand_item(extsbox: @mut SyntaxEnv, // does this attribute list contain "macro_escape" ? pub fn contains_macro_escape (attrs: &[ast::attribute]) -> bool { - attrs.any(|attr| "macro_escape" == *attr::get_attr_name(attr)) + attrs.any(|attr| "macro_escape" == attr::get_attr_name(attr)) } // Support for item-position macro invocations, exactly the same @@ -221,19 +221,19 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv, let extnamestr = ident_to_str(extname); let expanded = match (*extsbox).find(&extname.name) { None => cx.span_fatal(pth.span, - fmt!("macro undefined: '%s!'", *extnamestr)), + fmt!("macro undefined: '%s!'", extnamestr)), Some(@SE(NormalTT(ref expand))) => { if it.ident != parse::token::special_idents::invalid { cx.span_fatal(pth.span, fmt!("macro %s! expects no ident argument, \ - given '%s'", *extnamestr, - *ident_to_str(&it.ident))); + given '%s'", extnamestr, + ident_to_str(&it.ident))); } cx.bt_push(ExpandedFrom(CallInfo { call_site: it.span, callee: NameAndSpan { - name: copy *extnamestr, + name: extnamestr, span: expand.span } })); @@ -243,26 +243,25 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv, if it.ident == parse::token::special_idents::invalid { cx.span_fatal(pth.span, fmt!("macro %s! expects an ident argument", - *extnamestr)); + extnamestr)); } cx.bt_push(ExpandedFrom(CallInfo { call_site: it.span, callee: NameAndSpan { - name: copy *extnamestr, + name: extnamestr, span: expand.span } })); ((*expand).expander)(cx, it.span, it.ident, tts) } _ => cx.span_fatal( - it.span, fmt!("%s! is not legal in item position", *extnamestr)) + it.span, fmt!("%s! is not legal in item position", extnamestr)) }; let maybe_it = match expanded { MRItem(it) => fld.fold_item(it), MRExpr(_) => cx.span_fatal(pth.span, - ~"expr macro in item position: " - + *extnamestr), + fmt!("expr macro in item position: %s", extnamestr)), MRAny(_, item_maker, _) => item_maker().chain(|i| {fld.fold_item(i)}), MRDef(ref mdef) => { insert_macro(*extsbox,intern(mdef.name), @SE((*mdef).ext)); @@ -319,13 +318,13 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, let extnamestr = ident_to_str(extname); let (fully_expanded, sp) = match (*extsbox).find(&extname.name) { None => - cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extnamestr)), + cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", extnamestr)), Some(@SE(NormalTT( SyntaxExpanderTT{expander: exp, span: exp_sp}))) => { cx.bt_push(ExpandedFrom(CallInfo { call_site: sp, - callee: NameAndSpan { name: copy *extnamestr, span: exp_sp } + callee: NameAndSpan { name: extnamestr, span: exp_sp } })); let expanded = match exp(cx, mac.span, tts) { MRExpr(e) => @@ -334,7 +333,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, MRAny(_,_,stmt_mkr) => stmt_mkr(), _ => cx.span_fatal( pth.span, - fmt!("non-stmt macro in stmt pos: %s", *extnamestr)) + fmt!("non-stmt macro in stmt pos: %s", extnamestr)) }; //keep going, outside-in @@ -355,7 +354,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, _ => { cx.span_fatal(pth.span, - fmt!("'%s' is not a tt-style macro", *extnamestr)) + fmt!("'%s' is not a tt-style macro", extnamestr)) } }; @@ -414,7 +413,7 @@ fn get_block_info(exts : SyntaxEnv) -> BlockInfo { match exts.find_in_topmost_frame(&intern(special_block_name)) { Some(@BlockInfo(bi)) => bi, _ => fail!(fmt!("special identifier %? was bound to a non-BlockInfo", - @~" block")) + @" block")) } } @@ -456,9 +455,9 @@ pub fn new_span(cx: @ExtCtxt, sp: span) -> span { // the default compilation environment. It would be much nicer to use // a mechanism like syntax_quote to ensure hygiene. -pub fn core_macros() -> ~str { +pub fn core_macros() -> @str { return -~"pub mod macros { +@"pub mod macros { macro_rules! ignore (($($x:tt)*) => (())) macro_rules! error ( @@ -679,7 +678,7 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess, node: attribute_ { style: attr_outer, value: @spanned { - node: meta_word(@~"macro_escape"), + node: meta_word(@"macro_escape"), span: codemap::dummy_sp(), }, is_sugared_doc: false, @@ -687,8 +686,8 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess, } ]; - let cm = match parse_item_from_source_str(~"<core-macros>", - @core_macros(), + let cm = match parse_item_from_source_str(@"<core-macros>", + core_macros(), copy cfg, attrs, parse_sess) { @@ -764,11 +763,11 @@ mod test { // make sure that fail! is present #[test] fn fail_exists_test () { - let src = ~"fn main() { fail!(\"something appropriately gloomy\");}"; + let src = @"fn main() { fail!(\"something appropriately gloomy\");}"; let sess = parse::new_parse_sess(None); let crate_ast = parse::parse_crate_from_source_str( - ~"<test>", - @src, + @"<test>", + src, ~[],sess); expand_crate(sess,~[],crate_ast); } @@ -779,12 +778,12 @@ mod test { // make sure that macros can leave scope #[should_fail] #[test] fn macros_cant_escape_fns_test () { - let src = ~"fn bogus() {macro_rules! z (() => (3+4))}\ + let src = @"fn bogus() {macro_rules! z (() => (3+4))}\ fn inty() -> int { z!() }"; let sess = parse::new_parse_sess(None); let crate_ast = parse::parse_crate_from_source_str( - ~"<test>", - @src, + @"<test>", + src, ~[],sess); // should fail: expand_crate(sess,~[],crate_ast); @@ -793,12 +792,12 @@ mod test { // make sure that macros can leave scope for modules #[should_fail] #[test] fn macros_cant_escape_mods_test () { - let src = ~"mod foo {macro_rules! z (() => (3+4))}\ + let src = @"mod foo {macro_rules! z (() => (3+4))}\ fn inty() -> int { z!() }"; let sess = parse::new_parse_sess(None); let crate_ast = parse::parse_crate_from_source_str( - ~"<test>", - @src, + @"<test>", + src, ~[],sess); // should fail: expand_crate(sess,~[],crate_ast); @@ -806,19 +805,19 @@ mod test { // macro_escape modules shouldn't cause macros to leave scope #[test] fn macros_can_escape_flattened_mods_test () { - let src = ~"#[macro_escape] mod foo {macro_rules! z (() => (3+4))}\ + let src = @"#[macro_escape] mod foo {macro_rules! z (() => (3+4))}\ fn inty() -> int { z!() }"; let sess = parse::new_parse_sess(None); let crate_ast = parse::parse_crate_from_source_str( - ~"<test>", - @src, + @"<test>", + src, ~[], sess); // should fail: expand_crate(sess,~[],crate_ast); } #[test] fn core_macros_must_parse () { - let src = ~" + let src = @" pub mod macros { macro_rules! ignore (($($x:tt)*) => (())) @@ -828,9 +827,9 @@ mod test { let sess = parse::new_parse_sess(None); let cfg = ~[]; let item_ast = parse::parse_item_from_source_str( - ~"<test>", - @src, - cfg,~[make_dummy_attr (@~"macro_escape")],sess); + @"<test>", + src, + cfg,~[make_dummy_attr (@"macro_escape")],sess); match item_ast { Some(_) => (), // success None => fail!("expected this to parse") @@ -838,9 +837,9 @@ mod test { } #[test] fn test_contains_flatten (){ - let attr1 = make_dummy_attr (@~"foo"); - let attr2 = make_dummy_attr (@~"bar"); - let escape_attr = make_dummy_attr (@~"macro_escape"); + let attr1 = make_dummy_attr (@"foo"); + let attr2 = make_dummy_attr (@"bar"); + let escape_attr = make_dummy_attr (@"macro_escape"); let attrs1 = ~[attr1, escape_attr, attr2]; assert_eq!(contains_macro_escape (attrs1),true); let attrs2 = ~[attr1,attr2]; @@ -848,7 +847,7 @@ mod test { } // make a "meta_word" outer attribute with the given name - fn make_dummy_attr(s: @~str) -> ast::attribute { + fn make_dummy_attr(s: @str) -> ast::attribute { spanned { span:codemap::dummy_sp(), node: attribute_ { @@ -864,7 +863,7 @@ mod test { #[test] fn renaming () { - let maybe_item_ast = string_to_item(@~"fn a() -> int { let b = 13; b }"); + let maybe_item_ast = string_to_item(@"fn a() -> int { let b = 13; b }"); let item_ast = match maybe_item_ast { Some(x) => x, None => fail!("test case fail") @@ -887,7 +886,7 @@ mod test { #[test] fn pat_idents(){ - let pat = string_to_pat(@~"(a,Foo{x:c @ (b,9),y:Bar(4,d)})"); + let pat = string_to_pat(@"(a,Foo{x:c @ (b,9),y:Bar(4,d)})"); let pat_idents = new_name_finder(); let idents = @mut ~[]; ((*pat_idents).visit_pat)(pat, (idents, mk_vt(pat_idents))); diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index b2ec3684b70..74496ac5359 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -274,12 +274,13 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, then there's no need for it to be mutable */ if i == 0 { stms.push(cx.stmt_let(fmt_sp, npieces > 1, - ident, cx.expr_str_uniq(fmt_sp, s))); + ident, cx.expr_str_uniq(fmt_sp, s.to_managed()))); } else { // we call the push_str function because the // bootstrap doesnt't seem to work if we call the // method. - let args = ~[cx.expr_mut_addr_of(fmt_sp, buf()), cx.expr_str(fmt_sp, s)]; + let args = ~[cx.expr_mut_addr_of(fmt_sp, buf()), + cx.expr_str(fmt_sp, s.to_managed())]; let call = cx.expr_call_global(fmt_sp, ~[core_ident, str_ident, @@ -303,7 +304,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span, must be initialized as an empty string */ if i == 0 { stms.push(cx.stmt_let(fmt_sp, true, ident, - cx.expr_str_uniq(fmt_sp, ~""))); + cx.expr_str_uniq(fmt_sp, @""))); } stms.push(cx.stmt_expr(make_new_conv(cx, fmt_sp, conv, args[n], buf()))); diff --git a/src/libsyntax/ext/pipes/check.rs b/src/libsyntax/ext/pipes/check.rs index 694a7c1cf84..c1b9b051ec9 100644 --- a/src/libsyntax/ext/pipes/check.rs +++ b/src/libsyntax/ext/pipes/check.rs @@ -51,7 +51,7 @@ impl proto::visitor<(), (), ()> for @ExtCtxt { } } - fn visit_message(&self, name: ~str, _span: span, _tys: &[@ast::Ty], + fn visit_message(&self, name: @str, _span: span, _tys: &[@ast::Ty], this: state, next: Option<next_state>) { match next { Some(ref next_state) => { diff --git a/src/libsyntax/ext/pipes/parse_proto.rs b/src/libsyntax/ext/pipes/parse_proto.rs index a89fd26df4c..11db1a5da29 100644 --- a/src/libsyntax/ext/pipes/parse_proto.rs +++ b/src/libsyntax/ext/pipes/parse_proto.rs @@ -20,13 +20,13 @@ use parse::token; use parse::token::{interner_get}; pub trait proto_parser { - fn parse_proto(&self, id: ~str) -> protocol; + fn parse_proto(&self, id: @str) -> protocol; fn parse_state(&self, proto: protocol); fn parse_message(&self, state: state); } impl proto_parser for parser::Parser { - fn parse_proto(&self, id: ~str) -> protocol { + fn parse_proto(&self, id: @str) -> protocol { let proto = protocol(id, *self.span); self.parse_seq_to_before_end( @@ -43,7 +43,7 @@ impl proto_parser for parser::Parser { fn parse_state(&self, proto: protocol) { let id = self.parse_ident(); - let name = copy *interner_get(id.name); + let name = interner_get(id.name); self.expect(&token::COLON); let dir = match copy *self.token { @@ -51,9 +51,9 @@ impl proto_parser for parser::Parser { _ => fail!() }; self.bump(); - let dir = match dir { - @~"send" => send, - @~"recv" => recv, + let dir = match dir.as_slice() { + "send" => send, + "recv" => recv, _ => fail!() }; @@ -78,7 +78,7 @@ impl proto_parser for parser::Parser { } fn parse_message(&self, state: state) { - let mname = copy *interner_get(self.parse_ident().name); + let mname = interner_get(self.parse_ident().name); let args = if *self.token == token::LPAREN { self.parse_unspanned_seq( @@ -97,7 +97,7 @@ impl proto_parser for parser::Parser { let next = match *self.token { token::IDENT(_, _) => { - let name = copy *interner_get(self.parse_ident().name); + let name = interner_get(self.parse_ident().name); let ntys = if *self.token == token::LT { self.parse_unspanned_seq( &token::LT, diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 304c496bbf4..b00f5057dac 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -101,7 +101,7 @@ impl gen_send for message { name, vec::append_one( arg_names.map(|x| cx.str_of(*x)), - ~"s").connect(", ")); + @"s").connect(", ")); if !try { body += fmt!("::std::pipes::send(pipe, message);\n"); @@ -114,7 +114,7 @@ impl gen_send for message { } else { ::std::pipes::rt::make_none() } }"); } - let body = cx.parse_expr(body); + let body = cx.parse_expr(body.to_managed()); let mut rty = cx.ty_path(path(~[next.data_name()], span) @@ -123,7 +123,7 @@ impl gen_send for message { rty = cx.ty_option(rty); } - let name = cx.ident_of(if try { ~"try_" + name } else { name } ); + let name = if try {cx.ident_of(~"try_" + name)} else {cx.ident_of(name)}; cx.item_fn_poly(dummy_sp(), name, @@ -173,12 +173,12 @@ impl gen_send for message { } }"); } - let body = cx.parse_expr(body); + let body = cx.parse_expr(body.to_managed()); - let name = if try { ~"try_" + name } else { name }; + let name = if try {cx.ident_of(~"try_" + name)} else {cx.ident_of(name)}; cx.item_fn_poly(dummy_sp(), - cx.ident_of(name), + name, args_ast, if try { cx.ty_option(cx.ty_nil()) @@ -326,7 +326,7 @@ impl gen_init for protocol { start_state.generics.to_source(), start_state.to_ty(cx).to_source(), start_state.to_ty(cx).to_source(), - body.to_source())) + body.to_source()).to_managed()) } fn gen_buffer_init(&self, ext_cx: @ExtCtxt) -> @ast::expr { @@ -358,10 +358,10 @@ impl gen_init for protocol { self.states.map_to_vec( |s| ext_cx.parse_stmt( fmt!("data.%s.set_buffer(buffer)", - s.name))), + s.name).to_managed())), Some(ext_cx.parse_expr(fmt!( "::std::ptr::to_mut_unsafe_ptr(&mut (data.%s))", - self.states[0].name))))); + self.states[0].name).to_managed())))); quote_expr!({ let buffer = $buffer; @@ -459,9 +459,9 @@ impl gen_init for protocol { let allows = cx.attribute( copy self.span, cx.meta_list(copy self.span, - ~"allow", - ~[cx.meta_word(copy self.span, ~"non_camel_case_types"), - cx.meta_word(copy self.span, ~"unused_mut")])); + @"allow", + ~[cx.meta_word(copy self.span, @"non_camel_case_types"), + cx.meta_word(copy self.span, @"unused_mut")])); cx.item_mod(copy self.span, cx.ident_of(copy self.name), ~[allows], ~[], items) } diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 0eb0f5c6159..32714f37272 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -38,17 +38,17 @@ impl direction { } pub struct next_state { - state: ~str, + state: @str, tys: ~[@ast::Ty], } // name, span, data, current state, next state -pub struct message(~str, span, ~[@ast::Ty], state, Option<next_state>); +pub struct message(@str, span, ~[@ast::Ty], state, Option<next_state>); impl message { - pub fn name(&mut self) -> ~str { + pub fn name(&mut self) -> @str { match *self { - message(ref id, _, _, _, _) => copy *id + message(id, _, _, _, _) => id } } @@ -70,7 +70,7 @@ pub type state = @state_; pub struct state_ { id: uint, - name: ~str, + name: @str, ident: ast::ident, span: span, dir: direction, @@ -81,7 +81,7 @@ pub struct state_ { impl state_ { pub fn add_message(@self, - name: ~str, + name: @str, span: span, data: ~[@ast::Ty], next: Option<next_state>) { @@ -122,11 +122,11 @@ impl state_ { pub type protocol = @mut protocol_; -pub fn protocol(name: ~str, span: span) -> protocol { +pub fn protocol(name: @str, span: span) -> protocol { @mut protocol_(name, span) } -pub fn protocol_(name: ~str, span: span) -> protocol_ { +pub fn protocol_(name: @str, span: span) -> protocol_ { protocol_ { name: name, span: span, @@ -136,7 +136,7 @@ pub fn protocol_(name: ~str, span: span) -> protocol_ { } pub struct protocol_ { - name: ~str, + name: @str, span: span, states: @mut ~[state], @@ -181,7 +181,7 @@ impl protocol_ { impl protocol_ { pub fn add_state_poly(@mut self, - name: ~str, + name: @str, ident: ast::ident, dir: direction, generics: ast::Generics) @@ -208,7 +208,7 @@ impl protocol_ { pub trait visitor<Tproto, Tstate, Tmessage> { fn visit_proto(&self, proto: protocol, st: &[Tstate]) -> Tproto; fn visit_state(&self, state: state, m: &[Tmessage]) -> Tstate; - fn visit_message(&self, name: ~str, spane: span, tys: &[@ast::Ty], + fn visit_message(&self, name: @str, spane: span, tys: &[@ast::Ty], this: state, next: Option<next_state>) -> Tmessage; } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 92727c73977..5e47862a1f0 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -43,8 +43,6 @@ pub mod rt { pub use parse::new_parser_from_tts; pub use codemap::{BytePos, span, dummy_spanned}; - use print::pprust::{item_to_str, ty_to_str}; - pub trait ToTokens { pub fn to_tokens(&self, _cx: @ExtCtxt) -> ~[token_tree]; } @@ -71,132 +69,132 @@ pub mod rt { pub trait ToSource { // Takes a thing and generates a string containing rust code for it. - pub fn to_source(&self) -> ~str; + pub fn to_source(&self) -> @str; } impl ToSource for ast::ident { - fn to_source(&self) -> ~str { - copy *ident_to_str(self) + fn to_source(&self) -> @str { + ident_to_str(self) } } impl ToSource for @ast::item { - fn to_source(&self) -> ~str { - item_to_str(*self, get_ident_interner()) + fn to_source(&self) -> @str { + pprust::item_to_str(*self, get_ident_interner()).to_managed() } } impl<'self> ToSource for &'self [@ast::item] { - fn to_source(&self) -> ~str { - self.map(|i| i.to_source()).connect("\n\n") + fn to_source(&self) -> @str { + self.map(|i| i.to_source()).connect("\n\n").to_managed() } } impl ToSource for @ast::Ty { - fn to_source(&self) -> ~str { - ty_to_str(*self, get_ident_interner()) + fn to_source(&self) -> @str { + pprust::ty_to_str(*self, get_ident_interner()).to_managed() } } impl<'self> ToSource for &'self [@ast::Ty] { - fn to_source(&self) -> ~str { - self.map(|i| i.to_source()).connect(", ") + fn to_source(&self) -> @str { + self.map(|i| i.to_source()).connect(", ").to_managed() } } impl ToSource for Generics { - fn to_source(&self) -> ~str { - pprust::generics_to_str(self, get_ident_interner()) + fn to_source(&self) -> @str { + pprust::generics_to_str(self, get_ident_interner()).to_managed() } } impl ToSource for @ast::expr { - fn to_source(&self) -> ~str { - pprust::expr_to_str(*self, get_ident_interner()) + fn to_source(&self) -> @str { + pprust::expr_to_str(*self, get_ident_interner()).to_managed() } } impl ToSource for ast::blk { - fn to_source(&self) -> ~str { - pprust::block_to_str(self, get_ident_interner()) + fn to_source(&self) -> @str { + pprust::block_to_str(self, get_ident_interner()).to_managed() } } impl<'self> ToSource for &'self str { - fn to_source(&self) -> ~str { - let lit = dummy_spanned(ast::lit_str(@self.to_owned())); - pprust::lit_to_str(@lit) + fn to_source(&self) -> @str { + let lit = dummy_spanned(ast::lit_str(self.to_managed())); + pprust::lit_to_str(@lit).to_managed() } } impl ToSource for int { - fn to_source(&self) -> ~str { + fn to_source(&self) -> @str { let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i)); - pprust::lit_to_str(@lit) + pprust::lit_to_str(@lit).to_managed() } } impl ToSource for i8 { - fn to_source(&self) -> ~str { + fn to_source(&self) -> @str { let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i8)); - pprust::lit_to_str(@lit) + pprust::lit_to_str(@lit).to_managed() } } impl ToSource for i16 { - fn to_source(&self) -> ~str { + fn to_source(&self) -> @str { let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i16)); - pprust::lit_to_str(@lit) + pprust::lit_to_str(@lit).to_managed() } } impl ToSource for i32 { - fn to_source(&self) -> ~str { + fn to_source(&self) -> @str { let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i32)); - pprust::lit_to_str(@lit) + pprust::lit_to_str(@lit).to_managed() } } impl ToSource for i64 { - fn to_source(&self) -> ~str { + fn to_source(&self) -> @str { let lit = dummy_spanned(ast::lit_int(*self as i64, ast::ty_i64)); - pprust::lit_to_str(@lit) + pprust::lit_to_str(@lit).to_managed() } } impl ToSource for uint { - fn to_source(&self) -> ~str { + fn to_source(&self) -> @str { let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u)); - pprust::lit_to_str(@lit) + pprust::lit_to_str(@lit).to_managed() } } impl ToSource for u8 { - fn to_source(&self) -> ~str { + fn to_source(&self) -> @str { let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u8)); - pprust::lit_to_str(@lit) + pprust::lit_to_str(@lit).to_managed() } } impl ToSource for u16 { - fn to_source(&self) -> ~str { + fn to_source(&self) -> @str { let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u16)); - pprust::lit_to_str(@lit) + pprust::lit_to_str(@lit).to_managed() } } impl ToSource for u32 { - fn to_source(&self) -> ~str { + fn to_source(&self) -> @str { let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u32)); - pprust::lit_to_str(@lit) + pprust::lit_to_str(@lit).to_managed() } } impl ToSource for u64 { - fn to_source(&self) -> ~str { + fn to_source(&self) -> @str { let lit = dummy_spanned(ast::lit_uint(*self as u64, ast::ty_u64)); - pprust::lit_to_str(@lit) + pprust::lit_to_str(@lit).to_managed() } } @@ -317,18 +315,18 @@ pub mod rt { } pub trait ExtParseUtils { - fn parse_item(&self, s: ~str) -> @ast::item; - fn parse_expr(&self, s: ~str) -> @ast::expr; - fn parse_stmt(&self, s: ~str) -> @ast::stmt; - fn parse_tts(&self, s: ~str) -> ~[ast::token_tree]; + fn parse_item(&self, s: @str) -> @ast::item; + fn parse_expr(&self, s: @str) -> @ast::expr; + fn parse_stmt(&self, s: @str) -> @ast::stmt; + fn parse_tts(&self, s: @str) -> ~[ast::token_tree]; } impl ExtParseUtils for ExtCtxt { - fn parse_item(&self, s: ~str) -> @ast::item { + fn parse_item(&self, s: @str) -> @ast::item { let res = parse::parse_item_from_source_str( - ~"<quote expansion>", - @(copy s), + @"<quote expansion>", + s, self.cfg(), ~[], self.parse_sess()); @@ -341,27 +339,27 @@ pub mod rt { } } - fn parse_stmt(&self, s: ~str) -> @ast::stmt { + fn parse_stmt(&self, s: @str) -> @ast::stmt { parse::parse_stmt_from_source_str( - ~"<quote expansion>", - @(copy s), + @"<quote expansion>", + s, self.cfg(), ~[], self.parse_sess()) } - fn parse_expr(&self, s: ~str) -> @ast::expr { + fn parse_expr(&self, s: @str) -> @ast::expr { parse::parse_expr_from_source_str( - ~"<quote expansion>", - @(copy s), + @"<quote expansion>", + s, self.cfg(), self.parse_sess()) } - fn parse_tts(&self, s: ~str) -> ~[ast::token_tree] { + fn parse_tts(&self, s: @str) -> ~[ast::token_tree] { parse::parse_tts_from_source_str( - ~"<quote expansion>", - @(copy s), + @"<quote expansion>", + s, self.cfg(), self.parse_sess()) } diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 79018ebd1ea..d92f4e8458b 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -59,21 +59,21 @@ pub fn expand_file(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let topmost = topmost_expn_info(cx.backtrace().get()); let loc = cx.codemap().lookup_char_pos(topmost.call_site.lo); - let filename = copy loc.file.name; + let filename = loc.file.name; base::MRExpr(cx.expr_str(topmost.call_site, filename)) } pub fn expand_stringify(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let s = pprust::tts_to_str(tts, get_ident_interner()); - base::MRExpr(cx.expr_str(sp, s)) + base::MRExpr(cx.expr_str(sp, s.to_managed())) } pub fn expand_mod(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "module_path!"); base::MRExpr(cx.expr_str(sp, - cx.mod_path().map(|x| cx.str_of(*x)).connect("::"))) + cx.mod_path().map(|x| cx.str_of(*x)).connect("::").to_managed())) } // include! : parse the given file as an expr @@ -94,13 +94,13 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path(file))); match res { - result::Ok(_) => { /* Continue. */ } - result::Err(ref e) => { - cx.parse_sess().span_diagnostic.handler().fatal((*e)); + result::Ok(res) => { + base::MRExpr(cx.expr_str(sp, res.to_managed())) + } + result::Err(e) => { + cx.span_fatal(sp, e); } } - - base::MRExpr(cx.expr_str(sp, result::unwrap(res))) } pub fn expand_include_bin(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) @@ -131,7 +131,7 @@ fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo { _ }) => { // Don't recurse into file using "include!" - if *name == ~"include" { + if "include" == *name { expn_info } else { topmost_expn_info(next_expn_info) diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index e5a77cc21fb..dd155869526 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -205,7 +205,7 @@ pub fn nameize(p_s: @mut ParseSess, ms: &[matcher], res: &[@named_match]) } => { if ret_val.contains_key(bind_name) { p_s.span_diagnostic.span_fatal(sp, ~"Duplicated bind name: "+ - *ident_to_str(bind_name)) + ident_to_str(bind_name)) } ret_val.insert(*bind_name, res[idx]); } @@ -373,8 +373,8 @@ pub fn parse( let nts = bb_eis.map(|ei| { match ei.elts[ei.idx].node { match_nonterminal(ref bind,ref name,_) => { - fmt!("%s ('%s')", *ident_to_str(name), - *ident_to_str(bind)) + fmt!("%s ('%s')", ident_to_str(name), + ident_to_str(bind)) } _ => fail!() } }).connect(" or "); @@ -398,7 +398,7 @@ pub fn parse( match ei.elts[ei.idx].node { match_nonterminal(_, ref name, idx) => { ei.matches[idx].push(@matched_nonterminal( - parse_nt(&rust_parser, *ident_to_str(name)))); + parse_nt(&rust_parser, ident_to_str(name)))); ei.idx += 1u; } _ => fail!() diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 7805e736467..491989c77c4 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -148,7 +148,7 @@ pub fn add_new_extension(cx: @ExtCtxt, |cx, sp, arg| generic_extension(cx, sp, name, arg, *lhses, *rhses); return MRDef(MacroDef{ - name: copy *ident_to_str(&name), + name: ident_to_str(&name), ext: NormalTT(base::SyntaxExpanderTT{expander: exp, span: Some(sp)}) }); } diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index f3bd2d4b8d1..e44c3e67212 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -121,7 +121,7 @@ fn lookup_cur_matched(r: &mut TtReader, name: ident) -> @named_match { Some(s) => lookup_cur_matched_by_matched(r, s), None => { r.sp_diag.span_fatal(r.cur_span, fmt!("unknown macro variable `%s`", - *ident_to_str(&name))); + ident_to_str(&name))); } } } @@ -139,8 +139,8 @@ fn lockstep_iter_size(t: &token_tree, r: &mut TtReader) -> lis { lis_contradiction(_) => copy rhs, lis_constraint(r_len, _) if l_len == r_len => copy lhs, lis_constraint(r_len, ref r_id) => { - let l_n = copy *ident_to_str(l_id); - let r_n = copy *ident_to_str(r_id); + let l_n = ident_to_str(l_id); + let r_n = ident_to_str(r_id); lis_contradiction(fmt!("Inconsistent lockstep iteration: \ '%s' has %u items, but '%s' has %u", l_n, l_len, r_n, r_len)) @@ -290,7 +290,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { r.sp_diag.span_fatal( copy r.cur_span, /* blame the macro writer */ fmt!("variable '%s' is still repeating at this depth", - *ident_to_str(&ident))); + ident_to_str(&ident))); } } } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 9796fcd8bac..035675e523e 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -990,7 +990,7 @@ mod test { // make sure idents get transformed everywhere #[test] fn ident_transformation () { let zz_fold = fun_to_ident_folder(to_zz()); - let ast = string_to_crate(@~"#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}"); + let ast = string_to_crate(@"#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}"); assert_pred!(matches_codepattern, "matches_codepattern", pprust::to_str(zz_fold.fold_crate(ast),fake_print_crate, @@ -1001,7 +1001,7 @@ mod test { // even inside macro defs.... #[test] fn ident_transformation_in_defs () { let zz_fold = fun_to_ident_folder(to_zz()); - let ast = string_to_crate(@~"macro_rules! a {(b $c:expr $(d $e:token)f+ + let ast = string_to_crate(@"macro_rules! a {(b $c:expr $(d $e:token)f+ => (g $(d $d $e)+))} "); assert_pred!(matches_codepattern, "matches_codepattern", diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index ed9a83d6b1e..ddcad5c3e8f 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -46,7 +46,7 @@ impl parser_attr for Parser { } token::DOC_COMMENT(s) => { let attr = ::attr::mk_sugared_doc_attr( - copy *self.id_to_str(s), + self.id_to_str(s), self.span.lo, self.span.hi ); @@ -119,7 +119,7 @@ impl parser_attr for Parser { } token::DOC_COMMENT(s) => { let attr = ::attr::mk_sugared_doc_attr( - copy *self.id_to_str(s), + self.id_to_str(s), self.span.lo, self.span.hi ); diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index a6933c16483..5c56ea6c446 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -320,10 +320,10 @@ pub struct lit { // probably not a good thing. pub fn gather_comments_and_literals(span_diagnostic: @diagnostic::span_handler, - path: ~str, + path: @str, srdr: @io::Reader) -> (~[cmnt], ~[lit]) { - let src = @str::from_bytes(srdr.read_whole_stream()); + let src = str::from_bytes(srdr.read_whole_stream()).to_managed(); let cm = CodeMap::new(); let filemap = cm.new_filemap(path, src); let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap); diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index 6027d3b07f2..0956fa7225f 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -158,7 +158,7 @@ impl Parser { self.fatal( fmt!( "expected `%s`, found `%s`", - *self.id_to_str(kw.to_ident()), + self.id_to_str(kw.to_ident()), self.this_token_to_str() ) ); diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 474e93ed11a..d71e2763b5c 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -40,7 +40,7 @@ pub struct TokenAndSpan {tok: token::Token, sp: span} pub struct StringReader { span_diagnostic: @span_handler, - src: @~str, + src: @str, // The absolute offset within the codemap of the next character to read pos: BytePos, // The absolute offset within the codemap of the last character read(curr) @@ -176,7 +176,7 @@ pub fn with_str_from<T>(rdr: @mut StringReader, start: BytePos, f: &fn(s: &str) pub fn bump(rdr: &mut StringReader) { rdr.last_pos = rdr.pos; let current_byte_offset = byte_offset(rdr, rdr.pos).to_uint(); - if current_byte_offset < (*rdr.src).len() { + if current_byte_offset < (rdr.src).len() { assert!(rdr.curr != -1 as char); let last_char = rdr.curr; let next = rdr.src.char_range_at(current_byte_offset); @@ -202,7 +202,7 @@ pub fn is_eof(rdr: @mut StringReader) -> bool { } pub fn nextch(rdr: @mut StringReader) -> char { let offset = byte_offset(rdr, rdr.pos).to_uint(); - if offset < (*rdr.src).len() { + if offset < (rdr.src).len() { return rdr.src.char_at(offset); } else { return -1 as char; } } @@ -801,9 +801,9 @@ mod test { } // open a string reader for the given string - fn setup(teststr: ~str) -> Env { + fn setup(teststr: @str) -> Env { let cm = CodeMap::new(); - let fm = cm.new_filemap(~"zebra.rs", @teststr); + let fm = cm.new_filemap(@"zebra.rs", teststr); let span_handler = diagnostic::mk_span_handler(diagnostic::mk_handler(None),@cm); Env { @@ -813,7 +813,7 @@ mod test { #[test] fn t1 () { let Env {string_reader} = - setup(~"/* my source file */ \ + setup(@"/* my source file */ \ fn main() { io::println(~\"zebra\"); }\n"); let id = str_to_ident("fn"); let tok1 = string_reader.next_token(); @@ -849,14 +849,14 @@ mod test { } #[test] fn doublecolonparsing () { - let env = setup (~"a b"); + let env = setup (@"a b"); check_tokenization (env, ~[mk_ident("a",false), mk_ident("b",false)]); } #[test] fn dcparsing_2 () { - let env = setup (~"a::b"); + let env = setup (@"a::b"); check_tokenization (env, ~[mk_ident("a",true), token::MOD_SEP, @@ -864,7 +864,7 @@ mod test { } #[test] fn dcparsing_3 () { - let env = setup (~"a ::b"); + let env = setup (@"a ::b"); check_tokenization (env, ~[mk_ident("a",false), token::MOD_SEP, @@ -872,7 +872,7 @@ mod test { } #[test] fn dcparsing_4 () { - let env = setup (~"a:: b"); + let env = setup (@"a:: b"); check_tokenization (env, ~[mk_ident("a",true), token::MOD_SEP, @@ -880,28 +880,28 @@ mod test { } #[test] fn character_a() { - let env = setup(~"'a'"); + let env = setup(@"'a'"); let TokenAndSpan {tok, sp: _} = env.string_reader.next_token(); assert_eq!(tok,token::LIT_INT('a' as i64, ast::ty_char)); } #[test] fn character_space() { - let env = setup(~"' '"); + let env = setup(@"' '"); let TokenAndSpan {tok, sp: _} = env.string_reader.next_token(); assert_eq!(tok, token::LIT_INT(' ' as i64, ast::ty_char)); } #[test] fn character_escaped() { - let env = setup(~"'\n'"); + let env = setup(@"'\n'"); let TokenAndSpan {tok, sp: _} = env.string_reader.next_token(); assert_eq!(tok, token::LIT_INT('\n' as i64, ast::ty_char)); } #[test] fn lifetime_name() { - let env = setup(~"'abc"); + let env = setup(@"'abc"); let TokenAndSpan {tok, sp: _} = env.string_reader.next_token(); let id = token::str_to_ident("abc"); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 559bca34f21..5edd2ec4d47 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -82,38 +82,38 @@ pub fn parse_crate_from_file( } pub fn parse_crate_from_source_str( - name: ~str, - source: @~str, + name: @str, + source: @str, cfg: ast::crate_cfg, sess: @mut ParseSess ) -> @ast::crate { let p = new_parser_from_source_str( sess, /*bad*/ copy cfg, - /*bad*/ copy name, + name, source ); maybe_aborted(p.parse_crate_mod(),p) } pub fn parse_expr_from_source_str( - name: ~str, - source: @~str, + name: @str, + source: @str, cfg: ast::crate_cfg, sess: @mut ParseSess ) -> @ast::expr { let p = new_parser_from_source_str( sess, cfg, - /*bad*/ copy name, + name, source ); maybe_aborted(p.parse_expr(), p) } pub fn parse_item_from_source_str( - name: ~str, - source: @~str, + name: @str, + source: @str, cfg: ast::crate_cfg, attrs: ~[ast::attribute], sess: @mut ParseSess @@ -121,30 +121,30 @@ pub fn parse_item_from_source_str( let p = new_parser_from_source_str( sess, cfg, - /*bad*/ copy name, + name, source ); maybe_aborted(p.parse_item(attrs),p) } pub fn parse_meta_from_source_str( - name: ~str, - source: @~str, + name: @str, + source: @str, cfg: ast::crate_cfg, sess: @mut ParseSess ) -> @ast::meta_item { let p = new_parser_from_source_str( sess, cfg, - /*bad*/ copy name, + name, source ); maybe_aborted(p.parse_meta_item(),p) } pub fn parse_stmt_from_source_str( - name: ~str, - source: @~str, + name: @str, + source: @str, cfg: ast::crate_cfg, attrs: ~[ast::attribute], sess: @mut ParseSess @@ -152,22 +152,22 @@ pub fn parse_stmt_from_source_str( let p = new_parser_from_source_str( sess, cfg, - /*bad*/ copy name, + name, source ); maybe_aborted(p.parse_stmt(attrs),p) } pub fn parse_tts_from_source_str( - name: ~str, - source: @~str, + name: @str, + source: @str, cfg: ast::crate_cfg, sess: @mut ParseSess ) -> ~[ast::token_tree] { let p = new_parser_from_source_str( sess, cfg, - /*bad*/ copy name, + name, source ); *p.quote_depth += 1u; @@ -182,8 +182,8 @@ pub fn parse_tts_from_source_str( // result. pub fn parse_from_source_str<T>( f: &fn(&Parser) -> T, - name: ~str, ss: codemap::FileSubstr, - source: @~str, + name: @str, ss: codemap::FileSubstr, + source: @str, cfg: ast::crate_cfg, sess: @mut ParseSess ) -> T { @@ -213,8 +213,8 @@ pub fn next_node_id(sess: @mut ParseSess) -> node_id { // Create a new parser from a source string pub fn new_parser_from_source_str(sess: @mut ParseSess, cfg: ast::crate_cfg, - name: ~str, - source: @~str) + name: @str, + source: @str) -> Parser { filemap_to_parser(sess,string_to_filemap(sess,source,name),cfg) } @@ -223,9 +223,9 @@ pub fn new_parser_from_source_str(sess: @mut ParseSess, // is specified as a substring of another file. pub fn new_parser_from_source_substr(sess: @mut ParseSess, cfg: ast::crate_cfg, - name: ~str, + name: @str, ss: codemap::FileSubstr, - source: @~str) + source: @str) -> Parser { filemap_to_parser(sess,substring_to_filemap(sess,source,name,ss),cfg) } @@ -275,7 +275,7 @@ pub fn new_parser_from_tts(sess: @mut ParseSess, pub fn file_to_filemap(sess: @mut ParseSess, path: &Path, spanopt: Option<span>) -> @FileMap { match io::read_whole_file_str(path) { - Ok(src) => string_to_filemap(sess, @src, path.to_str()), + Ok(src) => string_to_filemap(sess, src.to_managed(), path.to_str().to_managed()), Err(e) => { match spanopt { Some(span) => sess.span_diagnostic.span_fatal(span, e), @@ -287,14 +287,14 @@ pub fn file_to_filemap(sess: @mut ParseSess, path: &Path, spanopt: Option<span>) // given a session and a string, add the string to // the session's codemap and return the new filemap -pub fn string_to_filemap(sess: @mut ParseSess, source: @~str, path: ~str) +pub fn string_to_filemap(sess: @mut ParseSess, source: @str, path: @str) -> @FileMap { sess.cm.new_filemap(path, source) } // given a session and a string and a path and a FileSubStr, add // the string to the CodeMap and return the new FileMap -pub fn substring_to_filemap(sess: @mut ParseSess, source: @~str, path: ~str, +pub fn substring_to_filemap(sess: @mut ParseSess, source: @str, path: @str, filesubstr: FileSubstr) -> @FileMap { sess.cm.new_filemap_w_substr(path,filesubstr,source) } @@ -349,7 +349,7 @@ mod test { use util::parser_testing::{string_to_stmt, strs_to_idents}; // map a string to tts, return the tt without its parsesess - fn string_to_tts_only(source_str : @~str) -> ~[ast::token_tree] { + fn string_to_tts_only(source_str : @str) -> ~[ast::token_tree] { let (tts,_ps) = string_to_tts_and_sess(source_str); tts } @@ -368,7 +368,7 @@ mod test { } #[test] fn path_exprs_1 () { - assert_eq!(string_to_expr(@~"a"), + assert_eq!(string_to_expr(@"a"), @ast::expr{id:1, node:ast::expr_path(@ast::Path {span:sp(0,1), global:false, @@ -379,7 +379,7 @@ mod test { } #[test] fn path_exprs_2 () { - assert_eq!(string_to_expr(@~"::a::b"), + assert_eq!(string_to_expr(@"::a::b"), @ast::expr{id:1, node:ast::expr_path( @ast::Path {span:sp(0,6), @@ -394,11 +394,11 @@ mod test { // marked as `#[should_fail]`. /*#[should_fail] #[test] fn bad_path_expr_1() { - string_to_expr(@~"::abc::def::return"); + string_to_expr(@"::abc::def::return"); }*/ #[test] fn string_to_tts_1 () { - let (tts,_ps) = string_to_tts_and_sess(@~"fn a (b : int) { b; }"); + let (tts,_ps) = string_to_tts_and_sess(@"fn a (b : int) { b; }"); assert_eq!(to_json_str(@tts), ~"[\ [\"tt_tok\",null,[\"IDENT\",\"fn\",false]],\ @@ -427,7 +427,7 @@ mod test { } #[test] fn ret_expr() { - assert_eq!(string_to_expr(@~"return d"), + assert_eq!(string_to_expr(@"return d"), @ast::expr{id:2, node:ast::expr_ret( Some(@ast::expr{id:1, @@ -443,7 +443,7 @@ mod test { } #[test] fn parse_stmt_1 () { - assert_eq!(string_to_stmt(@~"b;"), + assert_eq!(string_to_stmt(@"b;"), @spanned{ node: ast::stmt_expr(@ast::expr{ id: 1, @@ -465,7 +465,7 @@ mod test { } #[test] fn parse_ident_pat () { - let parser = string_to_parser(@~"b"); + let parser = string_to_parser(@"b"); assert_eq!(parser.parse_pat(), @ast::pat{id:1, // fixme node: ast::pat_ident(ast::bind_infer, @@ -482,7 +482,7 @@ mod test { } #[test] fn parse_arg () { - let parser = string_to_parser(@~"b : int"); + let parser = string_to_parser(@"b : int"); assert_eq!(parser.parse_arg_general(true), ast::arg{ is_mutbl: false, @@ -515,7 +515,7 @@ mod test { #[test] fn parse_fundecl () { // this test depends on the intern order of "fn" and "int", and on the // assignment order of the node_ids. - assert_eq!(string_to_item(@~"fn a (b : int) { b; }"), + assert_eq!(string_to_item(@"fn a (b : int) { b; }"), Some( @ast::item{ident:str_to_ident("a"), attrs:~[], @@ -585,12 +585,12 @@ mod test { #[test] fn parse_exprs () { // just make sure that they parse.... - string_to_expr(@~"3 + 4"); - string_to_expr(@~"a::z.froob(b,@(987+3))"); + string_to_expr(@"3 + 4"); + string_to_expr(@"a::z.froob(b,@(987+3))"); } #[test] fn attrs_fix_bug () { - string_to_item(@~"pub fn mk_file_writer(path: &Path, flags: &[FileFlag]) + string_to_item(@"pub fn mk_file_writer(path: &Path, flags: &[FileFlag]) -> Result<@Writer, ~str> { #[cfg(windows)] fn wb() -> c_int { diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 61b7f1403e6..cc7b7fab07e 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -259,7 +259,7 @@ impl Parser { -> bool { match *token { token::IDENT(sid, _) => { - str::eq_slice(*self.id_to_str(sid), ident) + str::eq_slice(self.id_to_str(sid), ident) } _ => false } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8dd80be4f9c..47c0827eb23 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -96,7 +96,6 @@ use core::iterator::IteratorUtil; use core::either::Either; use core::either; use core::hashmap::HashSet; -use core::str; use core::vec; #[deriving(Eq)] @@ -263,7 +262,7 @@ pub struct Parser { /// extra detail when the same error is seen twice obsolete_set: @mut HashSet<ObsoleteSyntax>, /// Used to determine the path to externally loaded source files - mod_path_stack: @mut ~[~str], + mod_path_stack: @mut ~[@str], } @@ -333,7 +332,7 @@ impl Parser { } pub fn get_id(&self) -> node_id { next_node_id(self.sess) } - pub fn id_to_str(&self, id: ident) -> @~str { + pub fn id_to_str(&self, id: ident) -> @str { get_ident_interner().get(id.name) } @@ -2886,7 +2885,7 @@ impl Parser { loop { match *self.token { token::LIFETIME(lifetime) => { - if str::eq_slice(*self.id_to_str(lifetime), "static") { + if "static" == self.id_to_str(lifetime) { result.push(RegionTyParamBound); } else { self.span_err(*self.span, @@ -2898,11 +2897,11 @@ impl Parser { let obsolete_bound = match *self.token { token::MOD_SEP => false, token::IDENT(sid, _) => { - match *self.id_to_str(sid) { - ~"send" | - ~"copy" | - ~"const" | - ~"owned" => { + match self.id_to_str(sid).as_slice() { + "send" | + "copy" | + "const" | + "owned" => { self.obsolete( *self.span, ObsoleteLowerCaseKindBounds); @@ -3364,7 +3363,7 @@ impl Parser { } if fields.len() == 0 { self.fatal(fmt!("Unit-like struct should be written as `struct %s;`", - *get_ident_interner().get(class_name.name))); + get_ident_interner().get(class_name.name))); } self.bump(); } else if *self.token == token::LPAREN { @@ -3580,8 +3579,8 @@ impl Parser { let file_path = match ::attr::first_attr_value_str_by_name( attrs, "path") { - Some(d) => copy *d, - None => copy *default_path + Some(d) => d, + None => default_path }; self.mod_path_stack.push(file_path) } @@ -3599,13 +3598,13 @@ impl Parser { let prefix = prefix.dir_path(); let mod_path_stack = &*self.mod_path_stack; let mod_path = Path(".").push_many(*mod_path_stack); - let default_path = *token::interner_get(id.name) + ".rs"; + let default_path = token::interner_get(id.name).to_owned() + ".rs"; let file_path = match ::attr::first_attr_value_str_by_name( outer_attrs, "path") { Some(d) => { - let path = Path(copy *d); + let path = Path(d); if !path.is_absolute { - mod_path.push(copy *d) + mod_path.push(d) } else { path } @@ -3637,9 +3636,9 @@ impl Parser { let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs); return (ast::item_mod(m0), mod_attrs); - fn cdir_path_opt(default: ~str, attrs: ~[ast::attribute]) -> ~str { + fn cdir_path_opt(default: @str, attrs: ~[ast::attribute]) -> @str { match ::attr::first_attr_value_str_by_name(attrs, "path") { - Some(d) => copy *d, + Some(d) => d, None => default } } @@ -4263,7 +4262,7 @@ impl Parser { let first_ident = self.parse_ident(); let mut path = ~[first_ident]; - debug!("parsed view_path: %s", *self.id_to_str(first_ident)); + debug!("parsed view_path: %s", self.id_to_str(first_ident)); match *self.token { token::EQ => { // x = foo::bar @@ -4528,7 +4527,7 @@ impl Parser { config: copy self.cfg }) } - pub fn parse_str(&self) -> @~str { + pub fn parse_str(&self) -> @str { match *self.token { token::LIT_STR(s) => { self.bump(); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 91605db77b5..e7bc67340f0 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -21,10 +21,8 @@ use core::cast; use core::char; use core::cmp::Equiv; use core::local_data; -use core::str; use core::rand; use core::rand::RngUtil; -use core::to_bytes; #[deriving(Encodable, Decodable, Eq)] pub enum binop { @@ -180,28 +178,28 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str { } LIT_INT_UNSUFFIXED(i) => { i.to_str() } LIT_FLOAT(ref s, t) => { - let mut body = copy *ident_to_str(s); + let mut body = ident_to_str(s).to_owned(); if body.ends_with(".") { body += "0"; // `10.f` is not a float literal } body + ast_util::float_ty_to_str(t) } LIT_FLOAT_UNSUFFIXED(ref s) => { - let mut body = copy *ident_to_str(s); + let mut body = ident_to_str(s).to_owned(); if body.ends_with(".") { body += "0"; // `10.f` is not a float literal } body } - LIT_STR(ref s) => { ~"\"" + ident_to_str(s).escape_default() + "\"" } + LIT_STR(ref s) => { fmt!("\"%s\"", ident_to_str(s).escape_default()) } /* Name components */ - IDENT(s, _) => copy *in.get(s.name), - LIFETIME(s) => fmt!("'%s", *in.get(s.name)), + IDENT(s, _) => in.get(s.name).to_owned(), + LIFETIME(s) => fmt!("'%s", in.get(s.name)), UNDERSCORE => ~"_", /* Other */ - DOC_COMMENT(ref s) => copy *ident_to_str(s), + DOC_COMMENT(ref s) => ident_to_str(s).to_owned(), EOF => ~"<eof>", INTERPOLATED(ref nt) => { match nt { @@ -350,20 +348,6 @@ pub mod special_idents { pub static type_self: ident = ident { name: 34, ctxt: 0}; // `Self` } -pub struct StringRef<'self>(&'self str); - -impl<'self> Equiv<@~str> for StringRef<'self> { - #[inline(always)] - fn equiv(&self, other: &@~str) -> bool { str::eq_slice(**self, **other) } -} - -impl<'self> to_bytes::IterBytes for StringRef<'self> { - #[inline(always)] - fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { - (**self).iter_bytes(lsb0, f) - } -} - /** * Maps a token to a record specifying the corresponding binary * operator @@ -403,14 +387,14 @@ impl ident_interner { pub fn gensym(&self, val: &str) -> Name { self.interner.gensym(val) } - pub fn get(&self, idx: Name) -> @~str { + pub fn get(&self, idx: Name) -> @str { self.interner.get(idx) } // is this really something that should be exposed? pub fn len(&self) -> uint { self.interner.len() } - pub fn find_equiv<Q:Hash + IterBytes + Equiv<@~str>>(&self, val: &Q) + pub fn find_equiv<Q:Hash + IterBytes + Equiv<@str>>(&self, val: &Q) -> Option<Name> { self.interner.find_equiv(val) } @@ -542,12 +526,12 @@ pub fn gensym(str : &str) -> Name { } // map an interned representation back to a string -pub fn interner_get(name : Name) -> @~str { +pub fn interner_get(name : Name) -> @str { get_ident_interner().get(name) } // maps an identifier to the string that it corresponds to -pub fn ident_to_str(id : &ast::ident) -> @~str { +pub fn ident_to_str(id : &ast::ident) -> @str { interner_get(id.name) } @@ -715,6 +699,6 @@ mod test { #[test] fn t1() { let a = fresh_name("ghi"); io::println(fmt!("interned name: %u,\ntextual name: %s\n", - a,*interner_get(a))); + a,interner_get(a))); } } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index f6059980697..7853e7e312d 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -80,7 +80,7 @@ pub struct begin_t { } pub enum token { - STRING(@~str, int), + STRING(@str, int), BREAK(break_t), BEGIN(begin_t), END, @@ -107,7 +107,7 @@ impl token { pub fn tok_str(t: token) -> ~str { match t { - STRING(s, len) => return fmt!("STR(%s,%d)", *s, len), + STRING(s, len) => return fmt!("STR(%s,%d)", s, len), BREAK(_) => return ~"BREAK", BEGIN(_) => return ~"BEGIN", END => return ~"END", @@ -335,11 +335,11 @@ impl Printer { STRING(s, len) => { if self.scan_stack_empty { debug!("pp STRING('%s')/print ~[%u,%u]", - *s, self.left, self.right); + s, self.left, self.right); self.print(t, len); } else { debug!("pp STRING('%s')/buffer ~[%u,%u]", - *s, self.left, self.right); + s, self.left, self.right); self.advance_right(); self.token[self.right] = t; self.size[self.right] = len; @@ -534,11 +534,11 @@ impl Printer { } } STRING(s, len) => { - debug!("print STRING(%s)", *s); + debug!("print STRING(%s)", s); assert_eq!(L, len); // assert!(L <= space); self.space -= len; - self.print_str(*s); + self.print_str(s); } EOF => { // EOF should never get here. @@ -572,15 +572,15 @@ pub fn end(p: @mut Printer) { p.pretty_print(END); } pub fn eof(p: @mut Printer) { p.pretty_print(EOF); } pub fn word(p: @mut Printer, wrd: &str) { - p.pretty_print(STRING(@/*bad*/ wrd.to_owned(), wrd.len() as int)); + p.pretty_print(STRING(/* bad */ wrd.to_managed(), wrd.len() as int)); } pub fn huge_word(p: @mut Printer, wrd: &str) { - p.pretty_print(STRING(@/*bad*/ wrd.to_owned(), size_infinity)); + p.pretty_print(STRING(/* bad */ wrd.to_managed(), size_infinity)); } pub fn zero_word(p: @mut Printer, wrd: &str) { - p.pretty_print(STRING(@/*bad*/ wrd.to_owned(), 0)); + p.pretty_print(STRING(/* bad */ wrd.to_managed(), 0)); } pub fn spaces(p: @mut Printer, n: uint) { break_offset(p, n, 0); } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index ea33c04dbb5..c2a537dd10d 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -111,14 +111,14 @@ pub fn print_crate(cm: @CodeMap, intr: @ident_interner, span_diagnostic: @diagnostic::span_handler, crate: @ast::crate, - filename: ~str, + filename: @str, in: @io::Reader, out: @io::Writer, ann: pp_ann, is_expanded: bool) { let (cmnts, lits) = comments::gather_comments_and_literals( span_diagnostic, - copy filename, + filename, in ); let s = @ps { @@ -860,7 +860,7 @@ pub fn print_attribute(s: @ps, attr: ast::attribute) { if attr.node.is_sugared_doc { let meta = attr::attr_meta(attr); let comment = attr::get_meta_item_value_str(meta).get(); - word(s.s, *comment); + word(s.s, comment); } else { word(s.s, "#["); print_meta_item(s, attr.node.value); @@ -1400,10 +1400,10 @@ pub fn print_expr(s: @ps, expr: @ast::expr) { word(s.s, "asm!"); } popen(s); - print_string(s, *a.asm); + print_string(s, a.asm); word_space(s, ":"); for a.outputs.each |&(co, o)| { - print_string(s, *co); + print_string(s, co); popen(s); print_expr(s, o); pclose(s); @@ -1411,14 +1411,14 @@ pub fn print_expr(s: @ps, expr: @ast::expr) { } word_space(s, ":"); for a.inputs.each |&(co, o)| { - print_string(s, *co); + print_string(s, co); popen(s); print_expr(s, o); pclose(s); word_space(s, ","); } word_space(s, ":"); - print_string(s, *a.clobbers); + print_string(s, a.clobbers); pclose(s); } ast::expr_mac(ref m) => print_mac(s, m), @@ -1474,7 +1474,7 @@ pub fn print_decl(s: @ps, decl: @ast::decl) { } pub fn print_ident(s: @ps, ident: ast::ident) { - word(s.s, *ident_to_str(&ident)); + word(s.s, ident_to_str(&ident)); } pub fn print_for_decl(s: @ps, loc: @ast::local, coll: @ast::expr) { @@ -1776,14 +1776,14 @@ pub fn print_generics(s: @ps, generics: &ast::Generics) { pub fn print_meta_item(s: @ps, item: @ast::meta_item) { ibox(s, indent_unit); match item.node { - ast::meta_word(name) => word(s.s, *name), + ast::meta_word(name) => word(s.s, name), ast::meta_name_value(name, value) => { - word_space(s, *name); + word_space(s, name); word_space(s, "="); print_literal(s, @value); } ast::meta_list(name, ref items) => { - word(s.s, *name); + word(s.s, name); popen(s); commasep( s, @@ -1995,7 +1995,7 @@ pub fn print_literal(s: @ps, lit: @ast::lit) { _ => () } match lit.node { - ast::lit_str(st) => print_string(s, *st), + ast::lit_str(st) => print_string(s, st), ast::lit_int(ch, ast::ty_char) => { word(s.s, ~"'" + char::escape_default(ch as char) + "'"); } @@ -2023,9 +2023,9 @@ pub fn print_literal(s: @ps, lit: @ast::lit) { } } ast::lit_float(f, t) => { - word(s.s, *f + ast_util::float_ty_to_str(t)); + word(s.s, f.to_owned() + ast_util::float_ty_to_str(t)); } - ast::lit_float_unsuffixed(f) => word(s.s, *f), + ast::lit_float_unsuffixed(f) => word(s.s, f), ast::lit_nil => word(s.s, "()"), ast::lit_bool(val) => { if val { word(s.s, "true"); } else { word(s.s, "false"); } @@ -2101,7 +2101,7 @@ pub fn print_comment(s: @ps, cmnt: &comments::cmnt) { // We need to do at least one, possibly two hardbreaks. let is_semi = match s.s.last_token() { - pp::STRING(s, _) => *s == ~";", + pp::STRING(s, _) => ";" == s, _ => false }; if is_semi || is_begin(s) || is_end(s) { hardbreak(s.s); } diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index b55050184fe..d4f183ada7b 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -19,7 +19,6 @@ use core::prelude::*; use core::cmp::Equiv; use core::hashmap::HashMap; -use syntax::parse::token::StringRef; pub struct Interner<T> { priv map: @mut HashMap<T, uint>, @@ -80,8 +79,8 @@ impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> { // A StrInterner differs from Interner<String> in that it accepts // borrowed pointers rather than @ ones, resulting in less allocation. pub struct StrInterner { - priv map: @mut HashMap<@~str, uint>, - priv vect: @mut ~[@~str], + priv map: @mut HashMap<@str, uint>, + priv vect: @mut ~[@str], } // when traits can extend traits, we should extend index<uint,T> to get [] @@ -95,37 +94,38 @@ impl StrInterner { pub fn prefill(init: &[&str]) -> StrInterner { let rv = StrInterner::new(); - for init.each() |v| { rv.intern(*v); } + for init.each |&v| { rv.intern(v); } rv } pub fn intern(&self, val: &str) -> uint { - match self.map.find_equiv(&StringRef(val)) { + match self.map.find_equiv(&val) { Some(&idx) => return idx, None => (), } let new_idx = self.len(); - self.map.insert(@val.to_owned(), new_idx); - self.vect.push(@val.to_owned()); + let val = val.to_managed(); + self.map.insert(val, new_idx); + self.vect.push(val); new_idx } pub fn gensym(&self, val: &str) -> uint { let new_idx = self.len(); // leave out of .map to avoid colliding - self.vect.push(@val.to_owned()); + self.vect.push(val.to_managed()); new_idx } // this isn't "pure" in the traditional sense, because it can go from // failing to returning a value as items are interned. But for typestate, // where we first check a pred and then rely on it, ceasing to fail is ok. - pub fn get(&self, idx: uint) -> @~str { self.vect[idx] } + pub fn get(&self, idx: uint) -> @str { self.vect[idx] } pub fn len(&self) -> uint { let vect = &*self.vect; vect.len() } - pub fn find_equiv<Q:Hash + IterBytes + Equiv<@~str>>(&self, val: &Q) + pub fn find_equiv<Q:Hash + IterBytes + Equiv<@str>>(&self, val: &Q) -> Option<uint> { match self.map.find_equiv(val) { Some(v) => Some(*v), @@ -140,41 +140,41 @@ mod tests { #[test] #[should_fail] fn i1 () { - let i : Interner<@~str> = Interner::new(); + let i : Interner<@str> = Interner::new(); i.get(13); } #[test] fn i2 () { - let i : Interner<@~str> = Interner::new(); + let i : Interner<@str> = Interner::new(); // first one is zero: - assert_eq!(i.intern (@~"dog"), 0); + assert_eq!(i.intern (@"dog"), 0); // re-use gets the same entry: - assert_eq!(i.intern (@~"dog"), 0); + assert_eq!(i.intern (@"dog"), 0); // different string gets a different #: - assert_eq!(i.intern (@~"cat"), 1); - assert_eq!(i.intern (@~"cat"), 1); + assert_eq!(i.intern (@"cat"), 1); + assert_eq!(i.intern (@"cat"), 1); // dog is still at zero - assert_eq!(i.intern (@~"dog"), 0); + assert_eq!(i.intern (@"dog"), 0); // gensym gets 3 - assert_eq!(i.gensym (@~"zebra" ), 2); + assert_eq!(i.gensym (@"zebra" ), 2); // gensym of same string gets new number : - assert_eq!(i.gensym (@~"zebra" ), 3); + assert_eq!(i.gensym (@"zebra" ), 3); // gensym of *existing* string gets new number: - assert_eq!(i.gensym (@~"dog"), 4); - assert_eq!(i.get(0), @~"dog"); - assert_eq!(i.get(1), @~"cat"); - assert_eq!(i.get(2), @~"zebra"); - assert_eq!(i.get(3), @~"zebra"); - assert_eq!(i.get(4), @~"dog"); + assert_eq!(i.gensym (@"dog"), 4); + assert_eq!(i.get(0), @"dog"); + assert_eq!(i.get(1), @"cat"); + assert_eq!(i.get(2), @"zebra"); + assert_eq!(i.get(3), @"zebra"); + assert_eq!(i.get(4), @"dog"); } #[test] fn i3 () { - let i : Interner<@~str> = Interner::prefill([@~"Alan",@~"Bob",@~"Carol"]); - assert_eq!(i.get(0), @~"Alan"); - assert_eq!(i.get(1), @~"Bob"); - assert_eq!(i.get(2), @~"Carol"); - assert_eq!(i.intern(@~"Bob"), 1); + let i : Interner<@str> = Interner::prefill([@"Alan",@"Bob",@"Carol"]); + assert_eq!(i.get(0), @"Alan"); + assert_eq!(i.get(1), @"Bob"); + assert_eq!(i.get(2), @"Carol"); + assert_eq!(i.intern(@"Bob"), 1); } } diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index 76055ca7914..d0961ddbc70 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -18,50 +18,50 @@ use parse::token; // map a string to tts, using a made-up filename: return both the token_trees // and the ParseSess -pub fn string_to_tts_and_sess (source_str : @~str) -> (~[ast::token_tree],@mut ParseSess) { +pub fn string_to_tts_and_sess (source_str : @str) -> (~[ast::token_tree],@mut ParseSess) { let ps = new_parse_sess(None); - (filemap_to_tts(ps,string_to_filemap(ps,source_str,~"bogofile")),ps) + (filemap_to_tts(ps,string_to_filemap(ps,source_str,@"bogofile")),ps) } -pub fn string_to_parser_and_sess(source_str: @~str) -> (Parser,@mut ParseSess) { +pub fn string_to_parser_and_sess(source_str: @str) -> (Parser,@mut ParseSess) { let ps = new_parse_sess(None); - (new_parser_from_source_str(ps,~[],~"bogofile",source_str),ps) + (new_parser_from_source_str(ps,~[],@"bogofile",source_str),ps) } // map string to parser (via tts) -pub fn string_to_parser(source_str: @~str) -> Parser { +pub fn string_to_parser(source_str: @str) -> Parser { let (p,_) = string_to_parser_and_sess(source_str); p } -pub fn string_to_crate (source_str : @~str) -> @ast::crate { +pub fn string_to_crate (source_str : @str) -> @ast::crate { string_to_parser(source_str).parse_crate_mod() } // parse a string, return an expr -pub fn string_to_expr (source_str : @~str) -> @ast::expr { +pub fn string_to_expr (source_str : @str) -> @ast::expr { string_to_parser(source_str).parse_expr() } // parse a string, return an item -pub fn string_to_item (source_str : @~str) -> Option<@ast::item> { +pub fn string_to_item (source_str : @str) -> Option<@ast::item> { string_to_parser(source_str).parse_item(~[]) } // parse a string, return an item and the ParseSess -pub fn string_to_item_and_sess (source_str : @~str) -> (Option<@ast::item>,@mut ParseSess) { +pub fn string_to_item_and_sess (source_str : @str) -> (Option<@ast::item>,@mut ParseSess) { let (p,ps) = string_to_parser_and_sess(source_str); (p.parse_item(~[]),ps) } // parse a string, return a stmt -pub fn string_to_stmt(source_str : @~str) -> @ast::stmt { +pub fn string_to_stmt(source_str : @str) -> @ast::stmt { string_to_parser(source_str).parse_stmt(~[]) } // parse a string, return a pat. Uses "irrefutable"... which doesn't // (currently) affect parsing. -pub fn string_to_pat(source_str : @~str) -> @ast::pat { +pub fn string_to_pat(source_str : @str) -> @ast::pat { string_to_parser(source_str).parse_pat() } |
