diff options
Diffstat (limited to 'src/libsyntax')
26 files changed, 124 insertions, 83 deletions
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 46bbc8768c9..ee61ce24c30 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -121,7 +121,7 @@ pub fn is_shift_binop(b: BinOp) -> bool { pub fn unop_to_str(op: UnOp) -> &'static str { match op { UnBox => "@", - UnUniq => "~", + UnUniq => "box() ", UnDeref => "*", UnNot => "!", UnNeg => "-", diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index f09072e0bc6..ee03046b6d6 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -111,7 +111,7 @@ impl SpanHandler { // others log errors for later reporting. pub struct Handler { err_count: Cell<uint>, - emit: RefCell<~Emitter:Send>, + emit: RefCell<Box<Emitter:Send>>, } impl Handler { @@ -180,7 +180,7 @@ pub fn default_handler() -> Handler { mk_handler(box EmitterWriter::stderr()) } -pub fn mk_handler(e: ~Emitter:Send) -> Handler { +pub fn mk_handler(e: Box<Emitter:Send>) -> Handler { Handler { err_count: Cell::new(0), emit: RefCell::new(e), @@ -253,7 +253,7 @@ pub struct EmitterWriter { enum Destination { Terminal(term::Terminal<io::stdio::StdWriter>), - Raw(~Writer:Send), + Raw(Box<Writer:Send>), } impl EmitterWriter { @@ -270,7 +270,7 @@ impl EmitterWriter { } } - pub fn new(dst: ~Writer:Send) -> EmitterWriter { + pub fn new(dst: Box<Writer:Send>) -> EmitterWriter { EmitterWriter { dst: Raw(dst) } } } diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 9b362f8d942..b9c8be290ca 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -20,6 +20,7 @@ use parse; use parse::token::InternedString; use parse::token; + enum State { Asm, Outputs, @@ -45,7 +46,7 @@ impl State { static OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"]; pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { let mut p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.iter() diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index cee6216b23f..01ec4c84b68 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -50,19 +50,19 @@ pub trait MacroExpander { ecx: &mut ExtCtxt, span: Span, token_tree: &[ast::TokenTree]) - -> ~MacResult; + -> Box<MacResult>; } pub type MacroExpanderFn = fn(ecx: &mut ExtCtxt, span: codemap::Span, token_tree: &[ast::TokenTree]) - -> ~MacResult; + -> Box<MacResult>; impl MacroExpander for BasicMacroExpander { fn expand(&self, ecx: &mut ExtCtxt, span: Span, token_tree: &[ast::TokenTree]) - -> ~MacResult { + -> Box<MacResult> { (self.expander)(ecx, span, token_tree) } } @@ -78,7 +78,7 @@ pub trait IdentMacroExpander { sp: Span, ident: ast::Ident, token_tree: Vec<ast::TokenTree> ) - -> ~MacResult; + -> Box<MacResult>; } impl IdentMacroExpander for BasicIdentMacroExpander { @@ -87,13 +87,13 @@ impl IdentMacroExpander for BasicIdentMacroExpander { sp: Span, ident: ast::Ident, token_tree: Vec<ast::TokenTree> ) - -> ~MacResult { + -> Box<MacResult> { (self.expander)(cx, sp, ident, token_tree) } } pub type IdentMacroExpanderFn = - fn(&mut ExtCtxt, Span, ast::Ident, Vec<ast::TokenTree> ) -> ~MacResult; + fn(&mut ExtCtxt, Span, ast::Ident, Vec<ast::TokenTree>) -> Box<MacResult>; pub type MacroCrateRegistrationFun = fn(|ast::Name, SyntaxExtension|); @@ -130,8 +130,8 @@ pub struct MacExpr { e: @ast::Expr } impl MacExpr { - pub fn new(e: @ast::Expr) -> ~MacResult { - box MacExpr { e: e } as ~MacResult + pub fn new(e: @ast::Expr) -> Box<MacResult> { + box MacExpr { e: e } as Box<MacResult> } } impl MacResult for MacExpr { @@ -144,8 +144,8 @@ pub struct MacItem { i: @ast::Item } impl MacItem { - pub fn new(i: @ast::Item) -> ~MacResult { - box MacItem { i: i } as ~MacResult + pub fn new(i: @ast::Item) -> Box<MacResult> { + box MacItem { i: i } as Box<MacResult> } } impl MacResult for MacItem { @@ -173,8 +173,8 @@ impl DummyResult { /// /// Use this as a return value after hitting any errors and /// calling `span_err`. - pub fn any(sp: Span) -> ~MacResult { - box DummyResult { expr_only: false, span: sp } as ~MacResult + pub fn any(sp: Span) -> Box<MacResult> { + box DummyResult { expr_only: false, span: sp } as Box<MacResult> } /// Create a default MacResult that can only be an expression. @@ -182,8 +182,8 @@ impl DummyResult { /// Use this for macros that must expand to an expression, so even /// if an error is encountered internally, the user will recieve /// an error that they also used it in the wrong place. - pub fn expr(sp: Span) -> ~MacResult { - box DummyResult { expr_only: true, span: sp } as ~MacResult + pub fn expr(sp: Span) -> Box<MacResult> { + box DummyResult { expr_only: true, span: sp } as Box<MacResult> } /// A plain dummy expression. @@ -229,13 +229,13 @@ pub enum SyntaxExtension { /// A normal, function-like syntax extension. /// /// `bytes!` is a `NormalTT`. - NormalTT(~MacroExpander:'static, Option<Span>), + NormalTT(Box<MacroExpander:'static>, Option<Span>), /// A function-like syntax extension that has an extra ident before /// the block. /// /// `macro_rules!` is an `IdentTT`. - IdentTT(~IdentMacroExpander:'static, Option<Span>), + IdentTT(Box<IdentMacroExpander:'static>, Option<Span>), } pub struct BlockInfo { diff --git a/src/libsyntax/ext/bytes.rs b/src/libsyntax/ext/bytes.rs index c6349d616ec..06b50e37cbd 100644 --- a/src/libsyntax/ext/bytes.rs +++ b/src/libsyntax/ext/bytes.rs @@ -16,7 +16,9 @@ use ext::base::*; use ext::base; use ext::build::AstBuilder; -pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> ~base::MacResult { + +pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) + -> Box<base::MacResult> { // Gather all argument expressions let exprs = match get_exprs_from_tts(cx, sp, tts) { None => return DummyResult::expr(sp), diff --git a/src/libsyntax/ext/cfg.rs b/src/libsyntax/ext/cfg.rs index 8cd899738bf..3e74b2680e0 100644 --- a/src/libsyntax/ext/cfg.rs +++ b/src/libsyntax/ext/cfg.rs @@ -26,7 +26,9 @@ use parse::token::InternedString; use parse::token; use parse; -pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> ~base::MacResult { + +pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) + -> Box<base::MacResult> { let mut p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts.iter() diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index fe7fa636e7d..7c6c9892002 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -18,7 +18,8 @@ use std::strbuf::StrBuf; pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, sp: codemap::Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box<base::MacResult> { let es = match base::get_exprs_from_tts(cx, sp, tts) { Some(e) => e, None => return base::DummyResult::expr(sp) diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 9513c15c3d0..0e168e7b33b 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -19,7 +19,7 @@ use parse::token::{str_to_ident}; use std::strbuf::StrBuf; pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { let mut res_str = StrBuf::new(); for (i, e) in tts.iter().enumerate() { if i & 1 == 1 { diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index bf886e51885..a3f9eaee892 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -571,7 +571,7 @@ impl<'a> MethodDef<'a> { Self if nonstatic => { self_args.push(arg_expr); } - Ptr(~Self, _) if nonstatic => { + Ptr(box Self, _) if nonstatic => { self_args.push(cx.expr_deref(trait_.span, arg_expr)) } _ => { diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 769bbe2fc4e..602245b4c47 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -20,6 +20,7 @@ use ext::build::AstBuilder; use codemap::{Span,respan}; use owned_slice::OwnedSlice; + /// The types of pointers pub enum PtrTy<'a> { Send, // ~ @@ -31,7 +32,7 @@ pub enum PtrTy<'a> { pub struct Path<'a> { pub path: Vec<&'a str> , pub lifetime: Option<&'a str>, - pub params: Vec<~Ty<'a>> , + pub params: Vec<Box<Ty<'a>>>, pub global: bool, } @@ -44,7 +45,7 @@ impl<'a> Path<'a> { } pub fn new_<'r>(path: Vec<&'r str> , lifetime: Option<&'r str>, - params: Vec<~Ty<'r>> , + params: Vec<Box<Ty<'r>>>, global: bool) -> Path<'r> { Path { @@ -80,8 +81,8 @@ impl<'a> Path<'a> { /// A type. Supports pointers (except for *), Self, and literals pub enum Ty<'a> { Self, - // &/~/@ Ty - Ptr(~Ty<'a>, PtrTy<'a>), + // &/Box/@ Ty + Ptr(Box<Ty<'a>>, PtrTy<'a>), // mod::mod::Type<[lifetime], [Params...]>, including a plain type // parameter, and things like `int` Literal(Path<'a>), @@ -92,7 +93,7 @@ pub enum Ty<'a> { pub fn borrowed_ptrty<'r>() -> PtrTy<'r> { Borrowed(None, ast::MutImmutable) } -pub fn borrowed<'r>(ty: ~Ty<'r>) -> Ty<'r> { +pub fn borrowed<'r>(ty: Box<Ty<'r>>) -> Ty<'r> { Ptr(ty, borrowed_ptrty()) } diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 7229f5c1df9..ea3fef352be 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -24,7 +24,7 @@ use parse::token; use std::os; pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { let var = match get_single_str_from_tts(cx, sp, tts, "option_env!") { None => return DummyResult::expr(sp), Some(v) => v @@ -60,7 +60,7 @@ pub fn expand_option_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } pub fn expand_env(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { let exprs = match get_exprs_from_tts(cx, sp, tts) { Some(ref exprs) if exprs.len() == 0 => { cx.span_err(sp, "env! takes 1 or 2 arguments"); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 734d07ccb8f..0dc62728e5c 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1100,12 +1100,6 @@ mod test { } } - //fn fake_print_crate(krate: &ast::Crate) { - // let mut out = ~std::io::stderr() as ~std::io::Writer; - // let mut s = pprust::rust_printer(out, get_ident_interner()); - // pprust::print_crate_(&mut s, krate); - //} - fn expand_crate_str(crate_str: ~str) -> ast::Crate { let ps = parse::new_parse_sess(); let crate_ast = string_to_parser(&ps, crate_str).parse_crate_mod(); diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 41c74ce9ae5..0907541eee0 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -15,8 +15,11 @@ use codemap::Span; use ext::base; use ext::build::AstBuilder; -pub fn expand_syntax_ext(ecx: &mut base::ExtCtxt, sp: Span, - _tts: &[ast::TokenTree]) -> ~base::MacResult { + +pub fn expand_syntax_ext(ecx: &mut base::ExtCtxt, + sp: Span, + _tts: &[ast::TokenTree]) + -> Box<base::MacResult> { ecx.span_err(sp, "`fmt!` is deprecated, use `format!` instead"); ecx.parse_sess.span_diagnostic.span_note(sp, "see http://static.rust-lang.org/doc/master/std/fmt/index.html \ diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 0d856fb689d..fc3136996ae 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -805,7 +805,7 @@ impl<'a, 'b> Context<'a, 'b> { } pub fn expand_args(ecx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) -> Box<base::MacResult> { match parse_args(ecx, sp, tts) { (extra, Some((efmt, args, order, names))) => { diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index 666bc486fbf..486d060da77 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -18,7 +18,7 @@ use std::rc::Rc; pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, sp: codemap::Span, tt: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { cx.print_backtrace(); println!("{}", print::pprust::tt_to_str(&ast::TTDelim( diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index fc7f7722354..4d8be9bab76 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -17,6 +17,7 @@ use parse::token::*; use parse::token; use parse; + /** * * Quasiquoting works via token trees. @@ -312,7 +313,8 @@ pub mod rt { pub fn expand_quote_tokens(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box<base::MacResult> { let (cx_expr, expr) = expand_tts(cx, sp, tts); let expanded = expand_wrapper(cx, sp, cx_expr, expr); base::MacExpr::new(expanded) @@ -320,14 +322,15 @@ pub fn expand_quote_tokens(cx: &mut ExtCtxt, pub fn expand_quote_expr(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) -> Box<base::MacResult> { let expanded = expand_parse_call(cx, sp, "parse_expr", Vec::new(), tts); base::MacExpr::new(expanded) } pub fn expand_quote_item(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box<base::MacResult> { let e_attrs = cx.expr_vec_ng(sp); let expanded = expand_parse_call(cx, sp, "parse_item", vec!(e_attrs), tts); @@ -336,7 +339,8 @@ pub fn expand_quote_item(cx: &mut ExtCtxt, pub fn expand_quote_pat(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box<base::MacResult> { let e_refutable = cx.expr_lit(sp, ast::LitBool(true)); let expanded = expand_parse_call(cx, sp, "parse_pat", vec!(e_refutable), tts); @@ -345,7 +349,8 @@ pub fn expand_quote_pat(cx: &mut ExtCtxt, pub fn expand_quote_ty(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box<base::MacResult> { let e_param_colons = cx.expr_lit(sp, ast::LitBool(false)); let expanded = expand_parse_call(cx, sp, "parse_ty", vec!(e_param_colons), tts); @@ -354,7 +359,8 @@ pub fn expand_quote_ty(cx: &mut ExtCtxt, pub fn expand_quote_stmt(cx: &mut ExtCtxt, sp: Span, - tts: &[ast::TokenTree]) -> ~base::MacResult { + tts: &[ast::TokenTree]) + -> Box<base::MacResult> { let e_attrs = cx.expr_vec_ng(sp); let expanded = expand_parse_call(cx, sp, "parse_stmt", vec!(e_attrs), tts); diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 7f1d8172255..e221ab80d7b 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -29,7 +29,7 @@ use std::str; /* line!(): expands to the current line number */ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { base::check_zero_tts(cx, sp, tts, "line!"); let topmost = topmost_expn_info(cx.backtrace().unwrap()); @@ -40,7 +40,7 @@ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) /* col!(): expands to the current column number */ pub fn expand_col(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { base::check_zero_tts(cx, sp, tts, "col!"); let topmost = topmost_expn_info(cx.backtrace().unwrap()); @@ -52,7 +52,7 @@ pub fn expand_col(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) /* The filemap (`loc.file`) contains a bunch more information we could spit * out if we wanted. */ pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { base::check_zero_tts(cx, sp, tts, "file!"); let topmost = topmost_expn_info(cx.backtrace().unwrap()); @@ -62,13 +62,13 @@ pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { let s = pprust::tts_to_str(tts); base::MacExpr::new(cx.expr_str(sp, token::intern_and_get_ident(s))) } pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { base::check_zero_tts(cx, sp, tts, "module_path!"); let string = cx.mod_path() .iter() @@ -82,7 +82,7 @@ pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) // This is generally a bad idea because it's going to behave // unhygienically. pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { let file = match get_single_str_from_tts(cx, sp, tts, "include!") { Some(f) => f, None => return DummyResult::expr(sp), @@ -100,7 +100,7 @@ pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) // include_str! : read the given file, insert it as a literal string expr pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { let file = match get_single_str_from_tts(cx, sp, tts, "include_str!") { Some(f) => f, None => return DummyResult::expr(sp) @@ -131,8 +131,7 @@ 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 -{ + -> Box<base::MacResult> { let file = match get_single_str_from_tts(cx, sp, tts, "include_bin!") { Some(f) => f, None => return DummyResult::expr(sp) diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index d428251604c..77324632664 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -14,10 +14,11 @@ use ext::base::ExtCtxt; use ext::base; use parse::token::{keywords, is_keyword}; + pub fn expand_trace_macros(cx: &mut ExtCtxt, sp: Span, tt: &[ast::TokenTree]) - -> ~base::MacResult { + -> Box<base::MacResult> { match tt { [ast::TTTok(_, ref tok)] if is_keyword(keywords::True, tok) => { cx.set_trace_macros(true); diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 4c426bef12e..ee3ff0c389e 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -102,7 +102,7 @@ pub struct MatcherPos { elts: Vec<ast::Matcher> , // maybe should be <'>? Need to understand regions. sep: Option<Token>, idx: uint, - up: Option<~MatcherPos>, + up: Option<Box<MatcherPos>>, matches: Vec<Vec<Rc<NamedMatch>>>, match_lo: uint, match_hi: uint, sp_lo: BytePos, @@ -120,7 +120,7 @@ pub fn count_names(ms: &[Matcher]) -> uint { } pub fn initial_matcher_pos(ms: Vec<Matcher> , sep: Option<Token>, lo: BytePos) - -> ~MatcherPos { + -> Box<MatcherPos> { let mut match_idx_hi = 0u; for elt in ms.iter() { match elt.node { diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index ab0266cedaa..5a02acdae1c 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -95,7 +95,7 @@ impl MacroExpander for MacroRulesMacroExpander { cx: &mut ExtCtxt, sp: Span, arg: &[ast::TokenTree]) - -> ~MacResult { + -> Box<MacResult> { generic_extension(cx, sp, self.name, @@ -121,7 +121,7 @@ fn generic_extension(cx: &ExtCtxt, arg: &[ast::TokenTree], lhses: &[Rc<NamedMatch>], rhses: &[Rc<NamedMatch>]) - -> ~MacResult { + -> Box<MacResult> { if cx.trace_macros() { println!("{}! \\{ {} \\}", token::get_ident(name), @@ -171,7 +171,7 @@ fn generic_extension(cx: &ExtCtxt, // Weird, but useful for X-macros. return box ParserAnyMacro { parser: RefCell::new(p), - } as ~MacResult + } as Box<MacResult> } Failure(sp, ref msg) => if sp.lo >= best_fail_spot.lo { best_fail_spot = sp; @@ -193,7 +193,7 @@ pub fn add_new_extension(cx: &mut ExtCtxt, sp: Span, name: Ident, arg: Vec<ast::TokenTree> ) - -> ~base::MacResult { + -> Box<base::MacResult> { // these spans won't matter, anyways fn ms(m: Matcher_) -> Matcher { Spanned { @@ -250,5 +250,5 @@ pub fn add_new_extension(cx: &mut ExtCtxt, name: token::get_ident(name).to_str(), ext: NormalTT(exp, Some(sp)) })) - } as ~MacResult + } as Box<MacResult> } diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 8fa4857cab0..f6bee033553 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -254,7 +254,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { /* sidestep the interpolation tricks for ident because (a) idents can be in lots of places, so it'd be a pain (b) we actually can, since it's a token. */ - MatchedNonterminal(NtIdent(~sn,b)) => { + MatchedNonterminal(NtIdent(box sn, b)) => { r.cur_span = sp; r.cur_tok = IDENT(sn,b); return ret_val; diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index d09a002e117..b9157e0043d 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -40,6 +40,9 @@ pub enum ObsoleteSyntax { ObsoleteManagedPattern, ObsoleteManagedString, ObsoleteManagedVec, + ObsoleteOwnedType, + ObsoleteOwnedExpr, + ObsoleteOwnedPattern, } pub trait ParserObsoleteMethods { @@ -126,6 +129,18 @@ impl<'a> ParserObsoleteMethods for Parser<'a> { "managed vector", "use `Rc<~[T]>` instead of a managed vector" ), + ObsoleteOwnedType => ( + "`~` notation for owned pointers", + "use `Box<T>` in `std::owned` instead" + ), + ObsoleteOwnedExpr => ( + "`~` notation for owned pointer allocation", + "use the `box` operator instead of `~`" + ), + ObsoleteOwnedPattern => ( + "`~` notation for owned pointer patterns", + "use the `box` operator instead of `~`" + ), }; self.report(sp, kind, kind_str, desc); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 11a773a7f09..74c2ab9c494 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -273,7 +273,10 @@ struct ParsedItemsAndViewItems { /* ident is handled by common.rs */ -pub fn Parser<'a>(sess: &'a ParseSess, cfg: ast::CrateConfig, mut rdr: ~Reader:) +pub fn Parser<'a>( + sess: &'a ParseSess, + cfg: ast::CrateConfig, + mut rdr: Box<Reader:>) -> Parser<'a> { let tok0 = rdr.next_token(); let span = tok0.sp; @@ -318,14 +321,14 @@ pub struct Parser<'a> { pub last_span: Span, pub cfg: CrateConfig, // the previous token or None (only stashed sometimes). - pub last_token: Option<~token::Token>, + pub last_token: Option<Box<token::Token>>, pub buffer: [TokenAndSpan, ..4], pub buffer_start: int, pub buffer_end: int, pub tokens_consumed: uint, pub restriction: restriction, pub quote_depth: uint, // not (yet) related to the quasiquoter - pub reader: ~Reader:, + pub reader: Box<Reader:>, pub interner: Rc<token::IdentInterner>, /// The set of seen errors about obsolete syntax. Used to suppress /// extra detail when the same error is seen twice @@ -1221,6 +1224,14 @@ impl<'a> Parser<'a> { } else if self.token == token::TILDE { // OWNED POINTER self.bump(); + match self.token { + token::IDENT(ref ident, _) + if "str" == token::get_ident(*ident).get() => { + // This is OK (for now). + } + token::LBRACKET => {} // Also OK. + _ => self.obsolete(self.last_span, ObsoleteOwnedType), + }; TyUniq(self.parse_ty(false)) } else if self.token == token::BINOP(token::STAR) { // STAR POINTER (bare pointer?) @@ -1445,7 +1456,7 @@ impl<'a> Parser<'a> { _ => None, }; match found { - Some(INTERPOLATED(token::NtPath(~path))) => { + Some(INTERPOLATED(token::NtPath(box path))) => { return PathAndBounds { path: path, bounds: None, @@ -2258,9 +2269,13 @@ impl<'a> Parser<'a> { ex = match e.node { ExprVec(..) | ExprRepeat(..) => ExprVstore(e, ExprVstoreUniq), ExprLit(lit) if lit_is_str(lit) => { + self.obsolete(self.last_span, ObsoleteOwnedExpr); ExprVstore(e, ExprVstoreUniq) } - _ => self.mk_unary(UnUniq, e) + _ => { + self.obsolete(self.last_span, ObsoleteOwnedExpr); + self.mk_unary(UnUniq, e) + } }; } token::IDENT(_, _) if self.is_keyword(keywords::Box) => { @@ -2772,6 +2787,7 @@ impl<'a> Parser<'a> { let sub = self.parse_pat(); pat = PatUniq(sub); hi = self.last_span.hi; + self.obsolete(self.last_span, ObsoleteOwnedPattern); return @ast::Pat { id: ast::DUMMY_NODE_ID, node: pat, diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 519a7d141d3..e4e71baad44 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -113,9 +113,9 @@ pub enum Nonterminal { NtPat( @ast::Pat), NtExpr(@ast::Expr), NtTy( P<ast::Ty>), - NtIdent(~ast::Ident, bool), + NtIdent(Box<ast::Ident>, bool), NtMeta(@ast::MetaItem), // stuff inside brackets for attributes - NtPath(~ast::Path), + NtPath(Box<ast::Path>), NtTT( @ast::TokenTree), // needs @ed to break a circularity NtMatchers(Vec<ast::Matcher> ) } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 21215748fb4..a32cad70175 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -155,7 +155,7 @@ pub struct PrintStackElem { static SIZE_INFINITY: int = 0xffff; -pub fn mk_printer(out: ~io::Writer, linewidth: uint) -> Printer { +pub fn mk_printer(out: Box<io::Writer>, linewidth: uint) -> Printer { // Yes 3, it makes the ring buffers big enough to never // fall behind. let n: uint = 3 * linewidth; @@ -262,7 +262,7 @@ pub fn mk_printer(out: ~io::Writer, linewidth: uint) -> Printer { * called 'print'. */ pub struct Printer { - pub out: ~io::Writer, + pub out: Box<io::Writer>, buf_len: uint, margin: int, // width of lines we're constrained to space: int, // number of spaces left on line diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index fb823522612..310ca18e4fa 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -65,12 +65,12 @@ pub struct State<'a> { ann: &'a PpAnn } -pub fn rust_printer(writer: ~io::Writer) -> State<'static> { +pub fn rust_printer(writer: Box<io::Writer>) -> State<'static> { static NO_ANN: NoAnn = NoAnn; rust_printer_annotated(writer, &NO_ANN) } -pub fn rust_printer_annotated<'a>(writer: ~io::Writer, +pub fn rust_printer_annotated<'a>(writer: Box<io::Writer>, ann: &'a PpAnn) -> State<'a> { State { s: pp::mk_printer(writer, default_columns), @@ -99,7 +99,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap, krate: &ast::Crate, filename: ~str, input: &mut io::Reader, - out: ~io::Writer, + out: Box<io::Writer>, ann: &'a PpAnn, is_expanded: bool) -> IoResult<()> { let (cmnts, lits) = comments::gather_comments_and_literals( @@ -140,7 +140,7 @@ pub fn to_str(f: |&mut State| -> IoResult<()>) -> ~str { // FIXME(pcwalton): A nasty function to extract the string from an `io::Writer` // that we "know" to be a `MemWriter` that works around the lack of checked // downcasts. - let (_, wr): (uint, ~MemWriter) = cast::transmute_copy(&s.s.out); + let (_, wr): (uint, Box<MemWriter>) = cast::transmute_copy(&s.s.out); let result = str::from_utf8_owned(wr.get_ref().to_owned()).unwrap(); cast::forget(wr); result @@ -1113,7 +1113,7 @@ impl<'a> State<'a> { pub fn print_expr_vstore(&mut self, t: ast::ExprVstore) -> IoResult<()> { match t { - ast::ExprVstoreUniq => word(&mut self.s, "~"), + ast::ExprVstoreUniq => word(&mut self.s, "box "), ast::ExprVstoreSlice => word(&mut self.s, "&"), ast::ExprVstoreMutSlice => { try!(word(&mut self.s, "&")); @@ -1686,7 +1686,7 @@ impl<'a> State<'a> { try!(self.pclose()); } ast::PatUniq(inner) => { - try!(word(&mut self.s, "~")); + try!(word(&mut self.s, "box ")); try!(self.print_pat(inner)); } ast::PatRegion(inner) => { |
