From 082bfde412176249dc7328e771a2a15d202824cf Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 10 Dec 2014 19:46:38 -0800 Subject: Fallout of std::str stabilization --- src/libsyntax/ext/asm.rs | 3 +- src/libsyntax/ext/base.rs | 10 +++--- src/libsyntax/ext/build.rs | 3 +- src/libsyntax/ext/concat.rs | 8 ++--- src/libsyntax/ext/concat_idents.rs | 2 +- src/libsyntax/ext/deriving/bounds.rs | 3 +- src/libsyntax/ext/deriving/clone.rs | 9 ++--- src/libsyntax/ext/deriving/decodable.rs | 2 +- src/libsyntax/ext/deriving/encodable.rs | 3 +- src/libsyntax/ext/deriving/generic/mod.rs | 46 ++++++++++++------------- src/libsyntax/ext/deriving/mod.rs | 2 +- src/libsyntax/ext/deriving/show.rs | 2 +- src/libsyntax/ext/env.rs | 8 ++--- src/libsyntax/ext/expand.rs | 57 +++++++++++++++---------------- src/libsyntax/ext/format.rs | 27 +++++++-------- src/libsyntax/ext/quote.rs | 6 ++-- src/libsyntax/ext/source_util.rs | 16 ++++----- src/libsyntax/ext/tt/macro_parser.rs | 21 ++++++------ src/libsyntax/ext/tt/macro_rules.rs | 12 +++---- src/libsyntax/ext/tt/transcribe.rs | 4 +-- 20 files changed, 116 insertions(+), 128 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index b138811187b..b77b822a6b2 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -100,8 +100,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) Some(('=', _)) => None, Some(('+', operand)) => { Some(token::intern_and_get_ident(format!( - "={}", - operand).as_slice())) + "={}", operand)[])) } _ => { cx.span_err(span, "output operand constraint lacks '=' or '+'"); diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index aefbb2a1fea..62fe718b522 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -549,7 +549,7 @@ impl<'a> ExtCtxt<'a> { pub fn mod_pop(&mut self) { self.mod_path.pop().unwrap(); } pub fn mod_path(&self) -> Vec { let mut v = Vec::new(); - v.push(token::str_to_ident(self.ecfg.crate_name.as_slice())); + v.push(token::str_to_ident(self.ecfg.crate_name[])); v.extend(self.mod_path.iter().map(|a| *a)); return v; } @@ -558,7 +558,7 @@ impl<'a> ExtCtxt<'a> { if self.recursion_count > self.ecfg.recursion_limit { self.span_fatal(ei.call_site, format!("recursion limit reached while expanding the macro `{}`", - ei.callee.name).as_slice()); + ei.callee.name)[]); } let mut call_site = ei.call_site; @@ -669,7 +669,7 @@ pub fn check_zero_tts(cx: &ExtCtxt, tts: &[ast::TokenTree], name: &str) { if tts.len() != 0 { - cx.span_err(sp, format!("{} takes no arguments", name).as_slice()); + cx.span_err(sp, format!("{} takes no arguments", name)[]); } } @@ -682,12 +682,12 @@ pub fn get_single_str_from_tts(cx: &mut ExtCtxt, -> Option { let mut p = cx.new_parser_from_tts(tts); if p.token == token::Eof { - cx.span_err(sp, format!("{} takes 1 argument", name).as_slice()); + cx.span_err(sp, format!("{} takes 1 argument", name)[]); return None } let ret = cx.expander().fold_expr(p.parse_expr()); if p.token != token::Eof { - cx.span_err(sp, format!("{} takes 1 argument", name).as_slice()); + cx.span_err(sp, format!("{} takes 1 argument", name)[]); } expr_to_string(cx, ret, "argument must be a string literal").map(|(s, _)| { s.get().to_string() diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 9d4992f7453..77165168746 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -712,8 +712,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { let loc = self.codemap().lookup_char_pos(span.lo); let expr_file = self.expr_str(span, token::intern_and_get_ident(loc.file - .name - .as_slice())); + .name[])); let expr_line = self.expr_uint(span, loc.line); let expr_file_line_tuple = self.expr_tuple(span, vec!(expr_file, expr_line)); let expr_file_line_ptr = self.expr_addr_of(span, expr_file_line_tuple); diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index e2867c2fbab..03dd08fdf7f 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -40,14 +40,14 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, ast::LitInt(i, ast::UnsignedIntLit(_)) | ast::LitInt(i, ast::SignedIntLit(_, ast::Plus)) | ast::LitInt(i, ast::UnsuffixedIntLit(ast::Plus)) => { - accumulator.push_str(format!("{}", i).as_slice()); + accumulator.push_str(format!("{}", i)[]); } ast::LitInt(i, ast::SignedIntLit(_, ast::Minus)) | ast::LitInt(i, ast::UnsuffixedIntLit(ast::Minus)) => { - accumulator.push_str(format!("-{}", i).as_slice()); + accumulator.push_str(format!("-{}", i)[]); } ast::LitBool(b) => { - accumulator.push_str(format!("{}", b).as_slice()); + accumulator.push_str(format!("{}", b)[]); } ast::LitByte(..) | ast::LitBinary(..) => { @@ -62,5 +62,5 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, } base::MacExpr::new(cx.expr_str( sp, - token::intern_and_get_ident(accumulator.as_slice()))) + token::intern_and_get_ident(accumulator[]))) } diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index aa18b1be31a..2cf60d30a1b 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -40,7 +40,7 @@ pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree] } } } - let res = str_to_ident(res_str.as_slice()); + let res = str_to_ident(res_str[]); let e = P(ast::Expr { id: ast::DUMMY_NODE_ID, diff --git a/src/libsyntax/ext/deriving/bounds.rs b/src/libsyntax/ext/deriving/bounds.rs index 3145b3bb1a4..c27a27fce6a 100644 --- a/src/libsyntax/ext/deriving/bounds.rs +++ b/src/libsyntax/ext/deriving/bounds.rs @@ -31,8 +31,7 @@ pub fn expand_deriving_bound(cx: &mut ExtCtxt, ref tname => { cx.span_bug(span, format!("expected built-in trait name but \ - found {}", - *tname).as_slice()) + found {}", *tname)[]) } } }, diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index a34764221b3..eedec6f37c8 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -80,13 +80,11 @@ fn cs_clone( EnumNonMatchingCollapsed (..) => { cx.span_bug(trait_span, format!("non-matching enum variants in \ - `deriving({})`", - name).as_slice()) + `deriving({})`", name)[]) } StaticEnum(..) | StaticStruct(..) => { cx.span_bug(trait_span, - format!("static method in `deriving({})`", - name).as_slice()) + format!("static method in `deriving({})`", name)[]) } } @@ -103,8 +101,7 @@ fn cs_clone( None => { cx.span_bug(trait_span, format!("unnamed field in normal struct in \ - `deriving({})`", - name).as_slice()) + `deriving({})`", name)[]) } }; cx.field_imm(field.span, ident, subcall(field)) diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 0a8d59da896..a4c70ebbc8e 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -174,7 +174,7 @@ fn decode_static_fields(cx: &mut ExtCtxt, let fields = fields.iter().enumerate().map(|(i, &span)| { getarg(cx, span, token::intern_and_get_ident(format!("_field{}", - i).as_slice()), + i)[]), i) }).collect(); diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 30851ebeaae..aac515ed81a 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -162,8 +162,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span, let name = match name { Some(id) => token::get_ident(id), None => { - token::intern_and_get_ident(format!("_field{}", - i).as_slice()) + token::intern_and_get_ident(format!("_field{}", i)[]) } }; let enc = cx.expr_method_call(span, self_.clone(), diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index d8de3d2db97..a2b5c0b9e96 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -514,15 +514,15 @@ impl<'a> TraitDef<'a> { self, struct_def, type_ident, - self_args.as_slice(), - nonself_args.as_slice()) + self_args[], + nonself_args[]) } else { method_def.expand_struct_method_body(cx, self, struct_def, type_ident, - self_args.as_slice(), - nonself_args.as_slice()) + self_args[], + nonself_args[]) }; method_def.create_method(cx, @@ -554,15 +554,15 @@ impl<'a> TraitDef<'a> { self, enum_def, type_ident, - self_args.as_slice(), - nonself_args.as_slice()) + self_args[], + nonself_args[]) } else { method_def.expand_enum_method_body(cx, self, enum_def, type_ident, self_args, - nonself_args.as_slice()) + nonself_args[]) }; method_def.create_method(cx, @@ -649,7 +649,7 @@ impl<'a> MethodDef<'a> { for (i, ty) in self.args.iter().enumerate() { let ast_ty = ty.to_ty(cx, trait_.span, type_ident, generics); - let ident = cx.ident_of(format!("__arg_{}", i).as_slice()); + let ident = cx.ident_of(format!("__arg_{}", i)[]); arg_tys.push((ident, ast_ty)); let arg_expr = cx.expr_ident(trait_.span, ident); @@ -756,7 +756,7 @@ impl<'a> MethodDef<'a> { struct_path, struct_def, format!("__self_{}", - i).as_slice(), + i)[], ast::MutImmutable); patterns.push(pat); raw_fields.push(ident_expr); @@ -912,22 +912,22 @@ impl<'a> MethodDef<'a> { .collect::>(); let self_arg_idents = self_arg_names.iter() - .map(|name|cx.ident_of(name.as_slice())) + .map(|name|cx.ident_of(name[])) .collect::>(); // The `vi_idents` will be bound, solely in the catch-all, to // a series of let statements mapping each self_arg to a uint // corresponding to its variant index. let vi_idents: Vec = self_arg_names.iter() - .map(|name| { let vi_suffix = format!("{}_vi", name.as_slice()); - cx.ident_of(vi_suffix.as_slice()) }) + .map(|name| { let vi_suffix = format!("{}_vi", name[]); + cx.ident_of(vi_suffix[]) }) .collect::>(); // Builds, via callback to call_substructure_method, the // delegated expression that handles the catch-all case, // using `__variants_tuple` to drive logic if necessary. let catch_all_substructure = EnumNonMatchingCollapsed( - self_arg_idents, variants.as_slice(), vi_idents.as_slice()); + self_arg_idents, variants[], vi_idents[]); // These arms are of the form: // (Variant1, Variant1, ...) => Body1 @@ -949,12 +949,12 @@ impl<'a> MethodDef<'a> { let mut subpats = Vec::with_capacity(self_arg_names.len()); let mut self_pats_idents = Vec::with_capacity(self_arg_names.len() - 1); let first_self_pat_idents = { - let (p, idents) = mk_self_pat(cx, self_arg_names[0].as_slice()); + let (p, idents) = mk_self_pat(cx, self_arg_names[0][]); subpats.push(p); idents }; for self_arg_name in self_arg_names.tail().iter() { - let (p, idents) = mk_self_pat(cx, self_arg_name.as_slice()); + let (p, idents) = mk_self_pat(cx, self_arg_name[]); subpats.push(p); self_pats_idents.push(idents); } @@ -1010,7 +1010,7 @@ impl<'a> MethodDef<'a> { &**variant, field_tuples); let arm_expr = self.call_substructure_method( - cx, trait_, type_ident, self_args.as_slice(), nonself_args, + cx, trait_, type_ident, self_args[], nonself_args, &substructure); cx.arm(sp, vec![single_pat], arm_expr) @@ -1063,7 +1063,7 @@ impl<'a> MethodDef<'a> { } let arm_expr = self.call_substructure_method( - cx, trait_, type_ident, self_args.as_slice(), nonself_args, + cx, trait_, type_ident, self_args[], nonself_args, &catch_all_substructure); // Builds the expression: @@ -1267,7 +1267,7 @@ impl<'a> TraitDef<'a> { cx.span_bug(sp, "a struct with named and unnamed fields in `deriving`"); } }; - let ident = cx.ident_of(format!("{}_{}", prefix, i).as_slice()); + let ident = cx.ident_of(format!("{}_{}", prefix, i)[]); paths.push(codemap::Spanned{span: sp, node: ident}); let val = cx.expr( sp, ast::ExprParen(cx.expr_deref(sp, cx.expr_path(cx.path_ident(sp,ident))))); @@ -1313,7 +1313,7 @@ impl<'a> TraitDef<'a> { let mut ident_expr = Vec::new(); for (i, va) in variant_args.iter().enumerate() { let sp = self.set_expn_info(cx, va.ty.span); - let ident = cx.ident_of(format!("{}_{}", prefix, i).as_slice()); + let ident = cx.ident_of(format!("{}_{}", prefix, i)[]); let path1 = codemap::Spanned{span: sp, node: ident}; paths.push(path1); let expr_path = cx.expr_path(cx.path_ident(sp, ident)); @@ -1356,7 +1356,7 @@ pub fn cs_fold(use_foldl: bool, field.span, old, field.self_.clone(), - field.other.as_slice()) + field.other[]) }) } else { all_fields.iter().rev().fold(base, |old, field| { @@ -1364,12 +1364,12 @@ pub fn cs_fold(use_foldl: bool, field.span, old, field.self_.clone(), - field.other.as_slice()) + field.other[]) }) } }, EnumNonMatchingCollapsed(ref all_args, _, tuple) => - enum_nonmatch_f(cx, trait_span, (all_args.as_slice(), tuple), + enum_nonmatch_f(cx, trait_span, (all_args[], tuple), substructure.nonself_args), StaticEnum(..) | StaticStruct(..) => { cx.span_bug(trait_span, "static function in `deriving`") @@ -1409,7 +1409,7 @@ pub fn cs_same_method(f: F, f(cx, trait_span, called) }, EnumNonMatchingCollapsed(ref all_self_args, _, tuple) => - enum_nonmatch_f(cx, trait_span, (all_self_args.as_slice(), tuple), + enum_nonmatch_f(cx, trait_span, (all_self_args[], tuple), substructure.nonself_args), StaticEnum(..) | StaticStruct(..) => { cx.span_bug(trait_span, "static function in `deriving`") diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 839e99c81d1..4a9076b07b5 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -115,7 +115,7 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt, cx.span_err(titem.span, format!("unknown `deriving` \ trait: `{}`", - *tname).as_slice()); + *tname)[]); } }; } diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs index a68b521bbc9..19b45a1e610 100644 --- a/src/libsyntax/ext/deriving/show.rs +++ b/src/libsyntax/ext/deriving/show.rs @@ -127,7 +127,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, let formatter = substr.nonself_args[0].clone(); let meth = cx.ident_of("write_fmt"); - let s = token::intern_and_get_ident(format_string.as_slice()); + let s = token::intern_and_get_ident(format_string[]); let format_string = cx.expr_str(span, s); // phew, not our responsibility any more! diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 8c17b31f458..9fedc4a158e 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -30,7 +30,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenT Some(v) => v }; - let e = match os::getenv(var.as_slice()) { + let e = match os::getenv(var[]) { None => { cx.expr_path(cx.path_all(sp, true, @@ -56,7 +56,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenT cx.ident_of("Some")), vec!(cx.expr_str(sp, token::intern_and_get_ident( - s.as_slice())))) + s[])))) } }; MacExpr::new(e) @@ -83,7 +83,7 @@ pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) None => { token::intern_and_get_ident(format!("environment variable `{}` \ not defined", - var).as_slice()) + var)[]) } Some(second) => { match expr_to_string(cx, second, "expected string literal") { @@ -106,7 +106,7 @@ pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) cx.span_err(sp, msg.get()); cx.expr_uint(sp, 0) } - Some(s) => cx.expr_str(sp, token::intern_and_get_ident(s.as_slice())) + Some(s) => cx.expr_str(sp, token::intern_and_get_ident(s[])) }; MacExpr::new(e) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index b10ae7a09db..f2b6f6bfe16 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -293,7 +293,7 @@ fn expand_mac_invoc(mac: ast::Mac, span: codemap::Span, fld.cx.span_err( pth.span, format!("macro undefined: '{}!'", - extnamestr.get()).as_slice()); + extnamestr.get())[]); // let compilation continue None @@ -309,7 +309,7 @@ fn expand_mac_invoc(mac: ast::Mac, span: codemap::Span, }, }); let fm = fresh_mark(); - let marked_before = mark_tts(tts.as_slice(), fm); + let marked_before = mark_tts(tts[], fm); // The span that we pass to the expanders we want to // be the root of the call stack. That's the most @@ -320,7 +320,7 @@ fn expand_mac_invoc(mac: ast::Mac, span: codemap::Span, let opt_parsed = { let expanded = expandfun.expand(fld.cx, mac_span, - marked_before.as_slice()); + marked_before[]); parse_thunk(expanded) }; let parsed = match opt_parsed { @@ -329,8 +329,8 @@ fn expand_mac_invoc(mac: ast::Mac, span: codemap::Span, fld.cx.span_err( pth.span, format!("non-expression macro in expression position: {}", - extnamestr.get().as_slice() - ).as_slice()); + extnamestr.get()[] + )[]); return None; } }; @@ -340,7 +340,7 @@ fn expand_mac_invoc(mac: ast::Mac, span: codemap::Span, fld.cx.span_err( pth.span, format!("'{}' is not a tt-style macro", - extnamestr.get()).as_slice()); + extnamestr.get())[]); None } } @@ -445,7 +445,7 @@ pub fn expand_item(it: P, fld: &mut MacroExpander) if valid_ident { fld.cx.mod_push(it.ident); } - let macro_escape = contains_macro_escape(new_attrs.as_slice()); + let macro_escape = contains_macro_escape(new_attrs[]); let result = with_exts_frame!(fld.cx.syntax_env, macro_escape, noop_fold_item(it, fld)); @@ -553,7 +553,7 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) None => { fld.cx.span_err(path_span, format!("macro undefined: '{}!'", - extnamestr).as_slice()); + extnamestr)[]); // let compilation continue return SmallVector::zero(); } @@ -566,7 +566,7 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) format!("macro {}! expects no ident argument, \ given '{}'", extnamestr, - token::get_ident(it.ident)).as_slice()); + token::get_ident(it.ident))[]); return SmallVector::zero(); } fld.cx.bt_push(ExpnInfo { @@ -578,14 +578,14 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) } }); // mark before expansion: - let marked_before = mark_tts(tts.as_slice(), fm); - expander.expand(fld.cx, it.span, marked_before.as_slice()) + let marked_before = mark_tts(tts[], fm); + expander.expand(fld.cx, it.span, marked_before[]) } IdentTT(ref expander, span) => { if it.ident.name == parse::token::special_idents::invalid.name { fld.cx.span_err(path_span, format!("macro {}! expects an ident argument", - extnamestr.get()).as_slice()); + extnamestr.get())[]); return SmallVector::zero(); } fld.cx.bt_push(ExpnInfo { @@ -597,14 +597,14 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) } }); // mark before expansion: - let marked_tts = mark_tts(tts.as_slice(), fm); + let marked_tts = mark_tts(tts[], fm); expander.expand(fld.cx, it.span, it.ident, marked_tts) } LetSyntaxTT(ref expander, span) => { if it.ident.name == parse::token::special_idents::invalid.name { fld.cx.span_err(path_span, format!("macro {}! expects an ident argument", - extnamestr.get()).as_slice()); + extnamestr.get())[]); return SmallVector::zero(); } fld.cx.bt_push(ExpnInfo { @@ -621,7 +621,7 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) _ => { fld.cx.span_err(it.span, format!("{}! is not legal in item position", - extnamestr.get()).as_slice()); + extnamestr.get())[]); return SmallVector::zero(); } } @@ -639,8 +639,8 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) // result of expanding a LetSyntaxTT, and thus doesn't // need to be marked. Not that it could be marked anyway. // create issue to recommend refactoring here? - fld.cx.syntax_env.insert(intern(name.as_slice()), ext); - if attr::contains_name(it.attrs.as_slice(), "macro_export") { + fld.cx.syntax_env.insert(intern(name[]), ext); + if attr::contains_name(it.attrs[], "macro_export") { fld.cx.exported_macros.push(it); } SmallVector::zero() @@ -654,7 +654,7 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) Right(None) => { fld.cx.span_err(path_span, format!("non-item macro in item position: {}", - extnamestr.get()).as_slice()); + extnamestr.get())[]); return SmallVector::zero(); } }; @@ -903,7 +903,7 @@ fn expand_pat(p: P, fld: &mut MacroExpander) -> P { None => { fld.cx.span_err(pth.span, format!("macro undefined: '{}!'", - extnamestr).as_slice()); + extnamestr)[]); // let compilation continue return DummyResult::raw_pat(span); } @@ -920,11 +920,11 @@ fn expand_pat(p: P, fld: &mut MacroExpander) -> P { }); let fm = fresh_mark(); - let marked_before = mark_tts(tts.as_slice(), fm); + let marked_before = mark_tts(tts[], fm); let mac_span = fld.cx.original_span(); let expanded = match expander.expand(fld.cx, mac_span, - marked_before.as_slice()).make_pat() { + marked_before[]).make_pat() { Some(e) => e, None => { fld.cx.span_err( @@ -932,7 +932,7 @@ fn expand_pat(p: P, fld: &mut MacroExpander) -> P { format!( "non-pattern macro in pattern position: {}", extnamestr.get() - ).as_slice() + )[] ); return DummyResult::raw_pat(span); } @@ -944,7 +944,7 @@ fn expand_pat(p: P, fld: &mut MacroExpander) -> P { _ => { fld.cx.span_err(span, format!("{}! is not legal in pattern position", - extnamestr.get()).as_slice()); + extnamestr.get())[]); return DummyResult::raw_pat(span); } } @@ -1192,8 +1192,7 @@ pub fn expand_crate(parse_sess: &parse::ParseSess, let mut expander = MacroExpander::new(&mut cx); for ExportedMacros { crate_name, macros } in imported_macros.into_iter() { - let name = format!("<{} macros>", token::get_ident(crate_name)) - .into_string(); + let name = format!("<{} macros>", token::get_ident(crate_name)); for source in macros.into_iter() { let item = parse::parse_item_from_source_str(name.clone(), @@ -1238,7 +1237,7 @@ impl Folder for Marker { node: match node { MacInvocTT(path, tts, ctxt) => { MacInvocTT(self.fold_path(path), - self.fold_tts(tts.as_slice()), + self.fold_tts(tts[]), mtwt::apply_mark(self.mark, ctxt)) } }, @@ -1415,9 +1414,9 @@ mod test { let attr2 = make_dummy_attr ("bar"); let escape_attr = make_dummy_attr ("macro_escape"); let attrs1 = vec!(attr1.clone(), escape_attr, attr2.clone()); - assert_eq!(contains_macro_escape(attrs1.as_slice()),true); + assert_eq!(contains_macro_escape(attrs1[]),true); let attrs2 = vec!(attr1,attr2); - assert_eq!(contains_macro_escape(attrs2.as_slice()),false); + assert_eq!(contains_macro_escape(attrs2[]),false); } // make a MetaWord outer attribute with the given name @@ -1729,7 +1728,7 @@ foo_module!(); let string = ident.get(); "xx" == string }).collect(); - let cxbinds: &[&ast::Ident] = cxbinds.as_slice(); + let cxbinds: &[&ast::Ident] = cxbinds[]; let cxbind = match cxbinds { [b] => b, _ => panic!("expected just one binding for ext_cx") diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 95c7fcc564a..aad4045f00a 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -136,7 +136,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, allow_method: bool, _ => { ecx.span_err(p.span, format!("expected ident for named argument, found `{}`", - p.this_token_to_string()).as_slice()); + p.this_token_to_string())[]); return (invocation, None); } }; @@ -149,7 +149,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, allow_method: bool, Some(prev) => { ecx.span_err(e.span, format!("duplicate argument named `{}`", - name).as_slice()); + name)[]); ecx.parse_sess.span_diagnostic.span_note(prev.span, "previously here"); continue } @@ -240,7 +240,7 @@ impl<'a, 'b> Context<'a, 'b> { let msg = format!("invalid reference to argument `{}` ({})", arg, self.describe_num_args()); - self.ecx.span_err(self.fmtsp, msg.as_slice()); + self.ecx.span_err(self.fmtsp, msg[]); return; } { @@ -260,7 +260,7 @@ impl<'a, 'b> Context<'a, 'b> { Some(e) => e.span, None => { let msg = format!("there is no argument named `{}`", name); - self.ecx.span_err(self.fmtsp, msg.as_slice()); + self.ecx.span_err(self.fmtsp, msg[]); return; } }; @@ -303,19 +303,19 @@ impl<'a, 'b> Context<'a, 'b> { format!("argument redeclared with type `{}` when \ it was previously `{}`", *ty, - *cur).as_slice()); + *cur)[]); } (&Known(ref cur), _) => { self.ecx.span_err(sp, format!("argument used to format with `{}` was \ attempted to not be used for formatting", - *cur).as_slice()); + *cur)[]); } (_, &Known(ref ty)) => { self.ecx.span_err(sp, format!("argument previously used as a format \ argument attempted to be used as `{}`", - *ty).as_slice()); + *ty)[]); } (_, _) => { self.ecx.span_err(sp, "argument declared with multiple formats"); @@ -380,7 +380,7 @@ impl<'a, 'b> Context<'a, 'b> { /// Translate the accumulated string literals to a literal expression fn trans_literal_string(&mut self) -> P { let sp = self.fmtsp; - let s = token::intern_and_get_ident(self.literal.as_slice()); + let s = token::intern_and_get_ident(self.literal[]); self.literal.clear(); self.ecx.expr_str(sp, s) } @@ -552,7 +552,7 @@ impl<'a, 'b> Context<'a, 'b> { None => continue // error already generated }; - let name = self.ecx.ident_of(format!("__arg{}", i).as_slice()); + let name = self.ecx.ident_of(format!("__arg{}", i)[]); pats.push(self.ecx.pat_ident(e.span, name)); locals.push(Context::format_arg(self.ecx, e.span, arg_ty, self.ecx.expr_ident(e.span, name))); @@ -569,7 +569,7 @@ impl<'a, 'b> Context<'a, 'b> { }; let lname = self.ecx.ident_of(format!("__arg{}", - *name).as_slice()); + *name)[]); pats.push(self.ecx.pat_ident(e.span, lname)); names[self.name_positions[*name]] = Some(Context::format_arg(self.ecx, e.span, arg_ty, @@ -652,7 +652,7 @@ impl<'a, 'b> Context<'a, 'b> { -> P { let trait_ = match *ty { Known(ref tyname) => { - match tyname.as_slice() { + match tyname[] { "" => "Show", "?" => "Show", "e" => "LowerExp", @@ -665,7 +665,7 @@ impl<'a, 'b> Context<'a, 'b> { _ => { ecx.span_err(sp, format!("unknown format trait `{}`", - *tyname).as_slice()); + *tyname)[]); "Dummy" } } @@ -760,8 +760,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, match parser.errors.remove(0) { Some(error) => { cx.ecx.span_err(cx.fmtsp, - format!("invalid format string: {}", - error).as_slice()); + format!("invalid format string: {}", error)[]); return DummyResult::raw_expr(sp); } None => {} diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index c7cb41e2ece..368d4fa8447 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -474,7 +474,7 @@ pub fn expand_quote_stmt(cx: &mut ExtCtxt, } fn ids_ext(strs: Vec ) -> Vec { - strs.iter().map(|str| str_to_ident((*str).as_slice())).collect() + strs.iter().map(|str| str_to_ident((*str)[])).collect() } fn id_ext(str: &str) -> ast::Ident { @@ -676,7 +676,7 @@ fn mk_tt(cx: &ExtCtxt, tt: &ast::TokenTree) -> Vec> { for i in range(0, tt.len()) { seq.push(tt.get_tt(i)); } - mk_tts(cx, seq.as_slice()) + mk_tts(cx, seq[]) } ast::TtToken(sp, ref tok) => { let e_sp = cx.expr_ident(sp, id_ext("_sp")); @@ -765,7 +765,7 @@ fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let stmt_let_tt = cx.stmt_let(sp, true, id_ext("tt"), cx.expr_vec_ng(sp)); let mut vector = vec!(stmt_let_sp, stmt_let_tt); - vector.extend(mk_tts(cx, tts.as_slice()).into_iter()); + vector.extend(mk_tts(cx, tts[]).into_iter()); let block = cx.expr_block( cx.block_all(sp, Vec::new(), diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 570231940aa..7c2c5c1530c 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -57,7 +57,7 @@ pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let topmost = cx.original_span_in_file(); let loc = cx.codemap().lookup_char_pos(topmost.lo); - let filename = token::intern_and_get_ident(loc.file.name.as_slice()); + let filename = token::intern_and_get_ident(loc.file.name[]); base::MacExpr::new(cx.expr_str(topmost, filename)) } @@ -65,7 +65,7 @@ pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> Box { let s = pprust::tts_to_string(tts); base::MacExpr::new(cx.expr_str(sp, - token::intern_and_get_ident(s.as_slice()))) + token::intern_and_get_ident(s[]))) } pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) @@ -78,7 +78,7 @@ pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) .connect("::"); base::MacExpr::new(cx.expr_str( sp, - token::intern_and_get_ident(string.as_slice()))) + token::intern_and_get_ident(string[]))) } /// include! : parse the given file as an expr @@ -137,7 +137,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) cx.span_err(sp, format!("couldn't read {}: {}", file.display(), - e).as_slice()); + e)[]); return DummyResult::expr(sp); } Ok(bytes) => bytes, @@ -147,7 +147,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) // Add this input file to the code map to make it available as // dependency information let filename = file.display().to_string(); - let interned = token::intern_and_get_ident(src.as_slice()); + let interned = token::intern_and_get_ident(src[]); cx.codemap().new_filemap(filename, src); base::MacExpr::new(cx.expr_str(sp, interned)) @@ -155,7 +155,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) Err(_) => { cx.span_err(sp, format!("{} wasn't a utf-8 file", - file.display()).as_slice()); + file.display())[]); return DummyResult::expr(sp); } } @@ -171,9 +171,7 @@ pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) match File::open(&file).read_to_end() { Err(e) => { cx.span_err(sp, - format!("couldn't read {}: {}", - file.display(), - e).as_slice()); + format!("couldn't read {}: {}", file.display(), e)[]); return DummyResult::expr(sp); } Ok(bytes) => { diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index bc639c32380..73ef18b8449 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -153,7 +153,7 @@ pub fn count_names(ms: &[TokenTree]) -> uint { seq.num_captures } &TtDelimited(_, ref delim) => { - count_names(delim.tts.as_slice()) + count_names(delim.tts[]) } &TtToken(_, MatchNt(..)) => { 1 @@ -165,7 +165,7 @@ pub fn count_names(ms: &[TokenTree]) -> uint { pub fn initial_matcher_pos(ms: Rc>, sep: Option, lo: BytePos) -> Box { - let match_idx_hi = count_names(ms.as_slice()); + let match_idx_hi = count_names(ms[]); let matches = Vec::from_fn(match_idx_hi, |_i| Vec::new()); box MatcherPos { stack: vec![], @@ -229,7 +229,7 @@ pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc]) p_s.span_diagnostic .span_fatal(sp, format!("duplicated bind name: {}", - string.get()).as_slice()) + string.get())[]) } } } @@ -254,13 +254,13 @@ pub fn parse_or_else(sess: &ParseSess, rdr: TtReader, ms: Vec ) -> HashMap> { - match parse(sess, cfg, rdr, ms.as_slice()) { + match parse(sess, cfg, rdr, ms[]) { Success(m) => m, Failure(sp, str) => { - sess.span_diagnostic.span_fatal(sp, str.as_slice()) + sess.span_diagnostic.span_fatal(sp, str[]) } Error(sp, str) => { - sess.span_diagnostic.span_fatal(sp, str.as_slice()) + sess.span_diagnostic.span_fatal(sp, str[]) } } } @@ -416,7 +416,7 @@ pub fn parse(sess: &ParseSess, } } TtToken(sp, SubstNt(..)) => { - return Error(sp, "Cannot transcribe in macro LHS".into_string()) + return Error(sp, "Cannot transcribe in macro LHS".to_string()) } seq @ TtDelimited(..) | seq @ TtToken(_, DocComment(..)) => { let lower_elts = mem::replace(&mut ei.top_elts, Tt(seq)); @@ -446,7 +446,7 @@ pub fn parse(sess: &ParseSess, for dv in eof_eis[0].matches.iter_mut() { v.push(dv.pop().unwrap()); } - return Success(nameize(sess, ms, v.as_slice())); + return Success(nameize(sess, ms, v[])); } else if eof_eis.len() > 1u { return Error(sp, "ambiguity: multiple successful parses".to_string()); } else { @@ -521,7 +521,7 @@ pub fn parse_nt(p: &mut Parser, name: &str) -> Nonterminal { _ => { let token_str = pprust::token_to_string(&p.token); p.fatal((format!("expected ident, found {}", - token_str.as_slice())).as_slice()) + token_str[]))[]) } }, "path" => { @@ -535,8 +535,7 @@ pub fn parse_nt(p: &mut Parser, name: &str) -> Nonterminal { res } _ => { - p.fatal(format!("unsupported builtin nonterminal parser: {}", - name).as_slice()) + p.fatal(format!("unsupported builtin nonterminal parser: {}", name)[]) } } } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 92c68b7a9c7..08014dc1338 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -52,7 +52,7 @@ impl<'a> ParserAnyMacro<'a> { following", token_str); let span = parser.span; - parser.span_err(span, msg.as_slice()); + parser.span_err(span, msg[]); } } } @@ -124,8 +124,8 @@ impl TTMacroExpander for MacroRulesMacroExpander { sp, self.name, arg, - self.lhses.as_slice(), - self.rhses.as_slice()) + self.lhses[], + self.rhses[]) } } @@ -160,7 +160,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, match **lhs { MatchedNonterminal(NtTT(ref lhs_tt)) => { let lhs_tt = match **lhs_tt { - TtDelimited(_, ref delim) => delim.tts.as_slice(), + TtDelimited(_, ref delim) => delim.tts[], _ => cx.span_fatal(sp, "malformed macro lhs") }; // `None` is because we're not interpolating @@ -198,13 +198,13 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, best_fail_spot = sp; best_fail_msg = (*msg).clone(); }, - Error(sp, ref msg) => cx.span_fatal(sp, msg.as_slice()) + Error(sp, ref msg) => cx.span_fatal(sp, msg[]) } } _ => cx.bug("non-matcher found in parsed lhses") } } - cx.span_fatal(best_fail_spot, best_fail_msg.as_slice()); + cx.span_fatal(best_fail_spot, best_fail_msg[]); } // Note that macro-by-example's input is also matched against a token tree: diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 378dbba07fa..deed0b78e87 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -223,7 +223,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { } LisContradiction(ref msg) => { // FIXME #2887 blame macro invoker instead - r.sp_diag.span_fatal(sp.clone(), msg.as_slice()); + r.sp_diag.span_fatal(sp.clone(), msg[]); } LisConstraint(len, _) => { if len == 0 { @@ -280,7 +280,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { r.sp_diag.span_fatal( r.cur_span, /* blame the macro writer */ format!("variable '{}' is still repeating at this depth", - token::get_ident(ident)).as_slice()); + token::get_ident(ident))[]); } } } -- cgit 1.4.1-3-g733a5 From a76a80276852f05f30adaa4d2a8a2729b5fc0bfa Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 18 Dec 2014 22:52:48 -0800 Subject: serialize: Fully deprecate the library This commit completes the deprecation story for the in-tree serialization library. The compiler will now emit a warning whenever it encounters `deriving(Encodable)` or `deriving(Decodable)`, and the library itself is now marked `#[unstable]` for when feature staging is enabled. All users of serialization can migrate to the `rustc-serialize` crate on crates.io which provides the exact same interface as the libserialize library in-tree. The new deriving modes are named `RustcEncodable` and `RustcDecodable` and require `extern crate "rustc-serialize" as rustc_serialize` at the crate root in order to expand correctly. To migrate all crates, add the following to your `Cargo.toml`: [dependencies] rustc-serialize = "0.1.1" And then add the following to your crate root: extern crate "rustc-serialize" as rustc_serialize; Finally, rename `Encodable` and `Decodable` deriving modes to `RustcEncodable` and `RustcDecodable`. [breaking-change] --- src/librustc/lib.rs | 2 + src/librustc/middle/def.rs | 6 +- src/librustc/middle/region.rs | 3 +- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc/middle/subst.rs | 6 +- src/librustc/middle/ty.rs | 35 +++--- src/librustdoc/clean/mod.rs | 96 +++++++-------- src/librustdoc/doctree.rs | 2 +- src/librustdoc/lib.rs | 2 + src/librustdoc/stability_summary.rs | 4 +- src/libserialize/json.rs | 26 ++-- src/libserialize/lib.rs | 6 +- src/libsyntax/abi.rs | 2 +- src/libsyntax/ast.rs | 209 ++++++++++++++++---------------- src/libsyntax/ast_util.rs | 2 +- src/libsyntax/attr.rs | 8 +- src/libsyntax/codemap.rs | 4 +- src/libsyntax/ext/deriving/decodable.rs | 32 ++++- src/libsyntax/ext/deriving/encodable.rs | 25 +++- src/libsyntax/ext/deriving/mod.rs | 18 ++- src/libsyntax/ext/mtwt.rs | 2 +- src/libsyntax/lib.rs | 2 + src/libsyntax/parse/token.rs | 12 +- src/libtest/lib.rs | 3 +- src/libtime/lib.rs | 5 +- 25 files changed, 288 insertions(+), 226 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 463dcddaf94..203e63858d4 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -40,6 +40,8 @@ extern crate collections; #[phase(plugin, link)] extern crate log; #[phase(plugin, link)] extern crate syntax; +extern crate "serialize" as rustc_serialize; // used by deriving + #[cfg(test)] extern crate test; diff --git a/src/librustc/middle/def.rs b/src/librustc/middle/def.rs index a582907612f..a54bc4a945a 100644 --- a/src/librustc/middle/def.rs +++ b/src/librustc/middle/def.rs @@ -20,7 +20,7 @@ use syntax::ast_util::local_def; use std::cell::RefCell; -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum Def { DefFn(ast::DefId, bool /* is_ctor */), DefStaticMethod(/* method */ ast::DefId, MethodProvenance), @@ -73,13 +73,13 @@ pub struct Export { pub def_id: ast::DefId, // The definition of the target. } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum MethodProvenance { FromTrait(ast::DefId), FromImpl(ast::DefId), } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum TyParamProvenance { FromSelf(ast::DefId), FromParam(ast::DefId), diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index e0d5a3a50e6..8df78281cc2 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -36,7 +36,8 @@ use syntax::visit::{Visitor, FnKind}; /// placate the same deriving in `ty::FreeRegion`, but we may want to /// actually attach a more meaningful ordering to scopes than the one /// generated via deriving here. -#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable, + RustcDecodable, Show, Copy)] pub enum CodeExtent { Misc(ast::NodeId) } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index be191801626..b64170c2e12 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -33,7 +33,7 @@ use syntax::visit; use syntax::visit::Visitor; use util::nodemap::NodeMap; -#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Show)] pub enum DefRegion { DefStaticRegion, DefEarlyBoundRegion(/* space */ subst::ParamSpace, diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index 30a47ff9132..69249b9ed50 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -187,8 +187,8 @@ impl RegionSubsts { /////////////////////////////////////////////////////////////////////////// // ParamSpace -#[deriving(Copy, PartialOrd, Ord, PartialEq, Eq, - Clone, Hash, Encodable, Decodable, Show)] +#[deriving(PartialOrd, Ord, PartialEq, Eq, Copy, + Clone, Hash, RustcEncodable, RustcDecodable, Show)] pub enum ParamSpace { TypeSpace, // Type parameters attached to a type definition, trait, or impl SelfSpace, // Self parameter on a trait @@ -224,7 +224,7 @@ impl ParamSpace { /// Vector of things sorted by param space. Used to keep /// the set of things declared on the type, self, or method /// distinct. -#[deriving(PartialEq, Eq, Clone, Hash, Encodable, Decodable)] +#[deriving(PartialEq, Eq, Clone, Hash, RustcEncodable, RustcDecodable)] pub struct VecPerParamSpace { // This was originally represented as a tuple with one Vec for // each variant of ParamSpace, and that remains the abstraction diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 50a6fb9d0ca..6b298cfd0d1 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -246,7 +246,7 @@ pub struct mt<'tcx> { pub mutbl: ast::Mutability, } -#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Show)] pub enum TraitStore { /// Box UniqTraitStore, @@ -277,13 +277,13 @@ pub enum ast_ty_to_ty_cache_entry<'tcx> { atttce_resolved(Ty<'tcx>) /* resolved to a type, irrespective of region */ } -#[deriving(Clone, PartialEq, Decodable, Encodable)] +#[deriving(Clone, PartialEq, RustcDecodable, RustcEncodable)] pub struct ItemVariances { pub types: VecPerParamSpace, pub regions: VecPerParamSpace, } -#[deriving(Clone, Copy, PartialEq, Decodable, Encodable, Show)] +#[deriving(Clone, PartialEq, RustcDecodable, RustcEncodable, Show, Copy)] pub enum Variance { Covariant, // T <: T iff A <: B -- e.g., function return type Invariant, // T <: T iff B == A -- e.g., type of mutable cell @@ -430,7 +430,7 @@ pub fn type_of_adjust<'tcx>(cx: &ctxt<'tcx>, adj: &AutoAdjustment<'tcx>) -> Opti } } -#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, PartialOrd, Show)] +#[deriving(Clone, Copy, RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Show)] pub struct param_index { pub space: subst::ParamSpace, pub index: uint @@ -510,7 +510,7 @@ pub struct MethodCall { pub adjustment: ExprAdjustment } -#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show, Encodable, Decodable)] +#[deriving(Clone, PartialEq, Eq, Hash, Show, RustcEncodable, RustcDecodable, Copy)] pub enum ExprAdjustment { NoAdjustment, AutoDeref(uint), @@ -973,7 +973,7 @@ pub struct ParamTy { /// is the outer fn. /// /// [dbi]: http://en.wikipedia.org/wiki/De_Bruijn_index -#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Show, Copy)] pub struct DebruijnIndex { // We maintain the invariant that this is never 0. So 1 indicates // the innermost binder. To ensure this, create with `DebruijnIndex::new`. @@ -981,7 +981,7 @@ pub struct DebruijnIndex { } /// Representation of regions: -#[deriving(Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Show, Copy)] pub enum Region { // Region bound in a type or fn declaration which will be // substituted 'early' -- that is, at the same time when type @@ -1028,7 +1028,7 @@ pub struct UpvarId { pub closure_expr_id: ast::NodeId, } -#[deriving(Clone, Copy, PartialEq, Eq, Hash, Show, Encodable, Decodable)] +#[deriving(Clone, PartialEq, Eq, Hash, Show, RustcEncodable, RustcDecodable, Copy)] pub enum BorrowKind { /// Data must be immutable and is aliasable. ImmBorrow, @@ -1121,7 +1121,7 @@ pub enum BorrowKind { /// - Through mutation, the borrowed upvars can actually escape /// the closure, so sometimes it is necessary for them to be larger /// than the closure lifetime itself. -#[deriving(Copy, PartialEq, Clone, Encodable, Decodable, Show)] +#[deriving(PartialEq, Clone, RustcEncodable, RustcDecodable, Show, Copy)] pub struct UpvarBorrow { pub kind: BorrowKind, pub region: ty::Region, @@ -1146,7 +1146,8 @@ impl Region { } } -#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, + RustcEncodable, RustcDecodable, Show, Copy)] /// A "free" region `fr` can be interpreted as "some region /// at least as big as the scope `fr.scope`". pub struct FreeRegion { @@ -1154,7 +1155,8 @@ pub struct FreeRegion { pub bound_region: BoundRegion } -#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash, Encodable, Decodable, Show)] +#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, + RustcEncodable, RustcDecodable, Show, Copy)] pub enum BoundRegion { /// An anonymous region parameter for a given fn (&T) BrAnon(uint), @@ -1412,7 +1414,8 @@ pub struct ExistentialBounds { pub type BuiltinBounds = EnumSet; -#[deriving(Copy, Clone, Encodable, PartialEq, Eq, Decodable, Hash, Show)] +#[deriving(Clone, RustcEncodable, PartialEq, Eq, RustcDecodable, Hash, + Show, Copy)] #[repr(uint)] pub enum BuiltinBound { BoundSend, @@ -1463,7 +1466,7 @@ pub struct FloatVid { pub index: uint } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub struct RegionVid { pub index: uint } @@ -1485,7 +1488,7 @@ pub enum InferTy { FreshIntTy(uint), } -#[deriving(Clone, Copy, Encodable, Decodable, Eq, Hash, Show)] +#[deriving(Clone, RustcEncodable, RustcDecodable, Eq, Hash, Show, Copy)] pub enum InferRegion { ReVar(RegionVid), ReSkolemized(uint, BoundRegion) @@ -1571,7 +1574,7 @@ pub struct TypeParameterDef<'tcx> { pub default: Option>, } -#[deriving(Encodable, Decodable, Clone, Show)] +#[deriving(RustcEncodable, RustcDecodable, Clone, Show)] pub struct RegionParameterDef { pub name: ast::Name, pub def_id: ast::DefId, @@ -6223,7 +6226,7 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec, } /// A free variable referred to in a function. -#[deriving(Copy, Encodable, Decodable)] +#[deriving(Copy, RustcEncodable, RustcDecodable)] pub struct Freevar { /// The variable being accessed free. pub def: def::Def, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index ac688784f92..ed2b85a34a9 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -113,7 +113,7 @@ impl, U> Clean> for syntax::owned_slice::OwnedSlice { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Crate { pub name: String, pub src: FsPath, @@ -195,7 +195,7 @@ impl<'a, 'tcx> Clean for visit_ast::RustdocVisitor<'a, 'tcx> { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct ExternalCrate { pub name: String, pub attrs: Vec, @@ -228,7 +228,7 @@ impl Clean for cstore::crate_metadata { /// Anything with a source location and set of attributes and, optionally, a /// name. That is, anything that can be documented. This doesn't correspond /// directly to the AST's concept of an item; it's a strict superset. -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Item { /// Stringified span pub source: Span, @@ -304,7 +304,7 @@ impl Item { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub enum ItemEnum { StructItem(Struct), EnumItem(Enum), @@ -333,7 +333,7 @@ pub enum ItemEnum { AssociatedTypeItem(TyParam), } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Module { pub items: Vec, pub is_crate: bool, @@ -400,7 +400,7 @@ impl Clean for doctree::Module { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub enum Attribute { Word(String), List(String, Vec ), @@ -453,7 +453,7 @@ impl<'a> attr::AttrMetaMethods for &'a Attribute { fn meta_item_list(&self) -> Option<&[P]> { None } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub struct TyParam { pub name: String, pub did: ast::DefId, @@ -490,7 +490,7 @@ impl<'tcx> Clean for ty::TypeParameterDef<'tcx> { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub enum TyParamBound { RegionBound(Lifetime), TraitBound(Type) @@ -632,7 +632,7 @@ impl<'tcx> Clean>> for subst::Substs<'tcx> { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub struct Lifetime(String); impl Lifetime { @@ -682,7 +682,7 @@ impl Clean> for ty::Region { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub struct WherePredicate { pub ty: Type, pub bounds: Vec @@ -706,7 +706,7 @@ impl Clean for ast::WherePredicate { } // maybe use a Generic enum and use ~[Generic]? -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub struct Generics { pub lifetimes: Vec, pub type_params: Vec, @@ -734,7 +734,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics<'tcx>, subst::ParamSpace) { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Method { pub generics: Generics, pub self_: SelfTy, @@ -773,7 +773,7 @@ impl Clean for ast::Method { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct TyMethod { pub unsafety: ast::Unsafety, pub decl: FnDecl, @@ -811,7 +811,7 @@ impl Clean for ast::TypeMethod { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub enum SelfTy { SelfStatic, SelfValue, @@ -832,7 +832,7 @@ impl Clean for ast::ExplicitSelf_ { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Function { pub decl: FnDecl, pub generics: Generics, @@ -857,7 +857,7 @@ impl Clean for doctree::Function { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub struct ClosureDecl { pub lifetimes: Vec, pub decl: FnDecl, @@ -878,14 +878,14 @@ impl Clean for ast::ClosureTy { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub struct FnDecl { pub inputs: Arguments, pub output: FunctionRetTy, pub attrs: Vec, } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub struct Arguments { pub values: Vec, } @@ -938,7 +938,7 @@ impl<'a, 'tcx> Clean for (ast::DefId, &'a ty::PolyFnSig<'tcx>) { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub struct Argument { pub type_: Type, pub name: String, @@ -955,7 +955,7 @@ impl Clean for ast::Arg { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub enum FunctionRetTy { Return(Type), NoReturn @@ -970,7 +970,7 @@ impl Clean for ast::FunctionRetTy { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Trait { pub unsafety: ast::Unsafety, pub items: Vec, @@ -1014,7 +1014,7 @@ impl Clean for ast::PolyTraitRef { /// An item belonging to a trait, whether a method or associated. Could be named /// TraitItem except that's already taken by an exported enum variant. -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub enum TraitMethod { RequiredMethod(Item), ProvidedMethod(Item), @@ -1059,7 +1059,7 @@ impl Clean for ast::TraitItem { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub enum ImplMethod { MethodImplItem(Item), TypeImplItem(Item), @@ -1132,7 +1132,7 @@ impl<'tcx> Clean for ty::ImplOrTraitItem<'tcx> { /// A representation of a Type suitable for hyperlinking purposes. Ideally one can get the original /// type out of the AST/ty::ctxt given one of these, if more information is needed. Most importantly /// it does not preserve mutability or boxes. -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub enum Type { /// structs/enums/traits (anything that'd be an ast::TyPath) ResolvedPath { @@ -1180,7 +1180,7 @@ pub enum Type { PolyTraitRef(Vec), } -#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Eq, Hash)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Copy)] pub enum PrimitiveType { Int, I8, I16, I32, I64, Uint, U8, U16, U32, U64, @@ -1192,7 +1192,7 @@ pub enum PrimitiveType { PrimitiveTuple, } -#[deriving(Clone, Copy, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable, Copy)] pub enum TypeKind { TypeEnum, TypeFunction, @@ -1436,7 +1436,7 @@ impl Clean for ast::QPath { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub enum StructField { HiddenStructField, // inserted later by strip passes TypedStructField(Type), @@ -1495,7 +1495,7 @@ impl Clean> for ast::Visibility { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Struct { pub struct_type: doctree::StructType, pub generics: Generics, @@ -1525,7 +1525,7 @@ impl Clean for doctree::Struct { /// This is a more limited form of the standard Struct, different in that /// it lacks the things most items have (name, id, parameterization). Found /// only as a variant in an enum. -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct VariantStruct { pub struct_type: doctree::StructType, pub fields: Vec, @@ -1542,7 +1542,7 @@ impl Clean for syntax::ast::StructDef { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Enum { pub variants: Vec, pub generics: Generics, @@ -1567,7 +1567,7 @@ impl Clean for doctree::Enum { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Variant { pub kind: VariantKind, } @@ -1635,7 +1635,7 @@ impl<'tcx> Clean for ty::VariantInfo<'tcx> { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub enum VariantKind { CLikeVariant, TupleVariant(Vec), @@ -1657,7 +1657,7 @@ impl Clean for ast::VariantKind { } } -#[deriving(Clone, Encodable, Decodable, Show)] +#[deriving(Clone, RustcEncodable, RustcDecodable, Show)] pub struct Span { pub filename: String, pub loline: uint, @@ -1692,7 +1692,7 @@ impl Clean for syntax::codemap::Span { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub struct Path { pub global: bool, pub segments: Vec, @@ -1707,7 +1707,7 @@ impl Clean for ast::Path { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub struct PathSegment { pub name: String, pub lifetimes: Vec, @@ -1763,7 +1763,7 @@ impl Clean for ast::Name { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Typedef { pub type_: Type, pub generics: Generics, @@ -1786,7 +1786,7 @@ impl Clean for doctree::Typedef { } } -#[deriving(Clone, Encodable, Decodable, PartialEq)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub struct BareFunctionDecl { pub unsafety: ast::Unsafety, pub generics: Generics, @@ -1809,7 +1809,7 @@ impl Clean for ast::BareFnTy { } } -#[deriving(Clone, Encodable, Decodable, Show)] +#[deriving(Clone, RustcEncodable, RustcDecodable, Show)] pub struct Static { pub type_: Type, pub mutability: Mutability, @@ -1838,7 +1838,7 @@ impl Clean for doctree::Static { } } -#[deriving(Clone, Encodable, Decodable, Show)] +#[deriving(Clone, RustcEncodable, RustcDecodable, Show)] pub struct Constant { pub type_: Type, pub expr: String, @@ -1861,7 +1861,7 @@ impl Clean for doctree::Constant { } } -#[deriving(Copy, Show, Clone, Encodable, Decodable, PartialEq)] +#[deriving(Show, Clone, RustcEncodable, RustcDecodable, PartialEq, Copy)] pub enum Mutability { Mutable, Immutable, @@ -1876,7 +1876,7 @@ impl Clean for ast::Mutability { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Impl { pub generics: Generics, pub trait_: Option, @@ -1914,7 +1914,7 @@ impl Clean for doctree::Impl { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct ViewItem { pub inner: ViewItemInner, } @@ -1980,7 +1980,7 @@ impl Clean> for ast::ViewItem { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub enum ViewItemInner { ExternCrate(String, Option, ast::NodeId), Import(ViewPath) @@ -2003,7 +2003,7 @@ impl Clean for ast::ViewItem_ { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub enum ViewPath { // use source as str; SimpleImport(String, ImportSource), @@ -2013,7 +2013,7 @@ pub enum ViewPath { ImportList(ImportSource, Vec), } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct ImportSource { pub path: Path, pub did: Option, @@ -2034,7 +2034,7 @@ impl Clean for ast::ViewPath { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct ViewListIdent { pub name: String, pub source: Option, @@ -2247,7 +2247,7 @@ fn resolve_def(cx: &DocContext, id: ast::NodeId) -> Option { }) } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Macro { pub source: String, } @@ -2268,7 +2268,7 @@ impl Clean for doctree::Macro { } } -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct Stability { pub level: attr::StabilityLevel, pub text: String diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 83552884d7f..7f7c055062a 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -70,7 +70,7 @@ impl Module { } } -#[deriving(Copy, Show, Clone, Encodable, Decodable)] +#[deriving(Show, Clone, RustcEncodable, RustcDecodable, Copy)] pub enum StructType { /// A normal struct Plain, diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 182c83d805c..8dfb352d028 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -32,6 +32,8 @@ extern crate syntax; extern crate "test" as testing; #[phase(plugin, link)] extern crate log; +extern crate "serialize" as rustc_serialize; // used by deriving + use std::cell::RefCell; use std::collections::HashMap; use std::collections::hash_map::Entry::{Occupied, Vacant}; diff --git a/src/librustdoc/stability_summary.rs b/src/librustdoc/stability_summary.rs index 2f3079f75b9..2e3adf8e767 100644 --- a/src/librustdoc/stability_summary.rs +++ b/src/librustdoc/stability_summary.rs @@ -25,7 +25,7 @@ use clean::{TypeTraitItem, ViewItemItem, PrimitiveItem, Stability}; use html::render::cache; -#[deriving(Zero, Encodable, Decodable, PartialEq, Eq)] +#[deriving(Zero, RustcEncodable, RustcDecodable, PartialEq, Eq)] /// The counts for each stability level. #[deriving(Copy)] pub struct Counts { @@ -73,7 +73,7 @@ impl Counts { } } -#[deriving(Encodable, Decodable, PartialEq, Eq)] +#[deriving(RustcEncodable, RustcDecodable, PartialEq, Eq)] /// A summarized module, which includes total counts and summarized children /// modules. pub struct ModuleSummary { diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 3181e28a121..15e7de08016 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -57,17 +57,17 @@ //! //! Rust provides a mechanism for low boilerplate encoding & decoding of values to and from JSON via //! the serialization API. -//! To be able to encode a piece of data, it must implement the `serialize::Encodable` trait. -//! To be able to decode a piece of data, it must implement the `serialize::Decodable` trait. +//! To be able to encode a piece of data, it must implement the `serialize::RustcEncodable` trait. +//! To be able to decode a piece of data, it must implement the `serialize::RustcDecodable` trait. //! The Rust compiler provides an annotation to automatically generate the code for these traits: -//! `#[deriving(Decodable, Encodable)]` +//! `#[deriving(RustcDecodable, RustcEncodable)]` //! //! The JSON API provides an enum `json::Json` and a trait `ToJson` to encode objects. //! The `ToJson` trait provides a `to_json` method to convert an object into a `json::Json` value. //! A `json::Json` value can be encoded as a string or buffer using the functions described above. //! You can also use the `json::Encoder` object, which implements the `Encoder` trait. //! -//! When using `ToJson` the `Encodable` trait implementation is not mandatory. +//! When using `ToJson` the `RustcEncodable` trait implementation is not mandatory. //! //! # Examples of use //! @@ -127,7 +127,7 @@ //! } //! } //! -//! // Only generate `Encodable` trait implementation +//! // Only generate `RustcEncodable` trait implementation //! #[deriving(Encodable)] //! pub struct ComplexNumRecord { //! uid: u8, @@ -404,7 +404,7 @@ impl<'a> Encoder<'a> { } /// Encode the specified struct into a json [u8] - pub fn buffer_encode, io::IoError>>(object: &T) -> Vec { + pub fn buffer_encode, io::IoError>>(object: &T) -> Vec { //Serialize the object in a string using a writer let mut m = Vec::new(); // FIXME(14302) remove the transmute and unsafe block. @@ -2428,7 +2428,7 @@ mod tests { use std::num::Float; use std::string; - #[deriving(Decodable, Eq, PartialEq, Show)] + #[deriving(RustcDecodable, Eq, PartialEq, Show)] struct OptionData { opt: Option, } @@ -2455,20 +2455,20 @@ mod tests { ExpectedError("Number".into_string(), "false".into_string())); } - #[deriving(PartialEq, Encodable, Decodable, Show)] + #[deriving(PartialEq, RustcEncodable, RustcDecodable, Show)] enum Animal { Dog, Frog(string::String, int) } - #[deriving(PartialEq, Encodable, Decodable, Show)] + #[deriving(PartialEq, RustcEncodable, RustcDecodable, Show)] struct Inner { a: (), b: uint, c: Vec, } - #[deriving(PartialEq, Encodable, Decodable, Show)] + #[deriving(PartialEq, RustcEncodable, RustcDecodable, Show)] struct Outer { inner: Vec, } @@ -3009,7 +3009,7 @@ mod tests { ); } - #[deriving(Decodable)] + #[deriving(RustcDecodable)] struct FloatStruct { f: f64, a: Vec @@ -3058,7 +3058,7 @@ mod tests { Err(SyntaxError(EOFWhileParsingObject, 3u, 8u))); } - #[deriving(Decodable)] + #[deriving(RustcDecodable)] #[allow(dead_code)] struct DecodeStruct { x: f64, @@ -3066,7 +3066,7 @@ mod tests { z: string::String, w: Vec } - #[deriving(Decodable)] + #[deriving(RustcDecodable)] enum DecodeEnum { A(f64), B(string::String) diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index e700d102fef..7ed806fb3b6 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -15,7 +15,7 @@ Core encoding and decoding interfaces. */ #![crate_name = "serialize"] -#![experimental] +#![unstable = "deprecated in favor of rustc-serialize on crates.io"] #![crate_type = "rlib"] #![crate_type = "dylib"] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", @@ -44,3 +44,7 @@ mod collection_impls; pub mod base64; pub mod hex; pub mod json; + +mod rustc_serialize { + pub use serialize::*; +} diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 70bad90aea1..b1599cb807d 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -26,7 +26,7 @@ pub enum Os { OsDragonfly, } -#[deriving(Copy, PartialEq, Eq, Hash, Encodable, Decodable, Clone)] +#[deriving(PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Clone, Copy)] pub enum Abi { // NB: This ordering MUST match the AbiDatas array below. // (This is ensured by the test indices_are_correct().) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a294706ef2c..b37914ed429 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -157,7 +157,8 @@ pub const ILLEGAL_CTXT : SyntaxContext = 1; /// A name is a part of an identifier, representing a string or gensym. It's /// the result of interning. -#[deriving(Copy, Eq, Ord, PartialEq, PartialOrd, Hash, Encodable, Decodable, Clone)] +#[deriving(Eq, Ord, PartialEq, PartialOrd, Hash, + RustcEncodable, RustcDecodable, Clone, Copy)] pub struct Name(pub u32); impl Name { @@ -187,7 +188,7 @@ impl, E> Encodable for Ident { } } -impl, E> Decodable for Ident { +impl, E> Decodable for Ident { fn decode(d: &mut D) -> Result { Ok(str_to_ident(try!(d.read_str()).as_slice())) } @@ -196,14 +197,15 @@ impl, E> Decodable for Ident { /// Function name (not all functions have names) pub type FnIdent = Option; -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, + Show, Copy)] pub struct Lifetime { pub id: NodeId, pub span: Span, pub name: Name } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct LifetimeDef { pub lifetime: Lifetime, pub bounds: Vec @@ -212,7 +214,7 @@ pub struct LifetimeDef { /// A "Path" is essentially Rust's notion of a name; for instance: /// std::cmp::PartialEq . It's represented as a sequence of identifiers, /// along with a bunch of supporting information. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Path { pub span: Span, /// A `::foo` path, is relative to the crate root rather than current @@ -224,7 +226,7 @@ pub struct Path { /// A segment of a path: an identifier, an optional lifetime, and a set of /// types. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct PathSegment { /// The identifier portion of this path segment. pub identifier: Ident, @@ -237,7 +239,7 @@ pub struct PathSegment { pub parameters: PathParameters, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum PathParameters { AngleBracketedParameters(AngleBracketedParameterData), ParenthesizedParameters(ParenthesizedParameterData), @@ -315,7 +317,7 @@ impl PathParameters { } /// A path like `Foo<'a, T>` -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct AngleBracketedParameterData { /// The lifetime parameters for this path segment. pub lifetimes: Vec, @@ -333,7 +335,7 @@ impl AngleBracketedParameterData { } /// A path like `Foo(A,B) -> C` -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct ParenthesizedParameterData { /// `(A,B)` pub inputs: Vec>, @@ -346,7 +348,8 @@ pub type CrateNum = u32; pub type NodeId = u32; -#[deriving(Clone, Copy, Eq, Ord, PartialOrd, PartialEq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Eq, Ord, PartialOrd, PartialEq, RustcEncodable, + RustcDecodable, Hash, Show, Copy)] pub struct DefId { pub krate: CrateNum, pub node: NodeId, @@ -366,7 +369,7 @@ pub const DUMMY_NODE_ID: NodeId = -1; /// typeck::collect::compute_bounds matches these against /// the "special" built-in traits (see middle::lang_items) and /// detects Copy, Send and Sync. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum TyParamBound { TraitTyParamBound(PolyTraitRef), RegionTyParamBound(Lifetime) @@ -374,7 +377,7 @@ pub enum TyParamBound { pub type TyParamBounds = OwnedSlice; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct TyParam { pub ident: Ident, pub id: NodeId, @@ -386,7 +389,7 @@ pub struct TyParam { /// Represents lifetimes and type parameters attached to a declaration /// of a function, enum, trait, etc. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Generics { pub lifetimes: Vec, pub ty_params: OwnedSlice, @@ -405,34 +408,34 @@ impl Generics { } } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct WhereClause { pub id: NodeId, pub predicates: Vec, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum WherePredicate { BoundPredicate(WhereBoundPredicate), RegionPredicate(WhereRegionPredicate), EqPredicate(WhereEqPredicate) } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct WhereBoundPredicate { pub span: Span, pub bounded_ty: P, pub bounds: OwnedSlice, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct WhereRegionPredicate { pub span: Span, pub lifetime: Lifetime, pub bounds: Vec, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct WhereEqPredicate { pub id: NodeId, pub span: Span, @@ -444,7 +447,7 @@ pub struct WhereEqPredicate { /// used to drive conditional compilation pub type CrateConfig = Vec> ; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Crate { pub module: Mod, pub attrs: Vec, @@ -455,7 +458,7 @@ pub struct Crate { pub type MetaItem = Spanned; -#[deriving(Clone, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum MetaItem_ { MetaWord(InternedString), MetaList(InternedString, Vec>), @@ -487,7 +490,7 @@ impl PartialEq for MetaItem_ { } } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Block { pub view_items: Vec, pub stmts: Vec>, @@ -497,27 +500,27 @@ pub struct Block { pub span: Span, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Pat { pub id: NodeId, pub node: Pat_, pub span: Span, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct FieldPat { pub ident: Ident, pub pat: P, pub is_shorthand: bool, } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum BindingMode { BindByRef(Mutability), BindByValue(Mutability), } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum PatWildKind { /// Represents the wildcard pattern `_` PatWildSingle, @@ -526,7 +529,7 @@ pub enum PatWildKind { PatWildMulti, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum Pat_ { /// Represents a wildcard pattern (either `_` or `..`) PatWild(PatWildKind), @@ -555,13 +558,13 @@ pub enum Pat_ { PatMac(Mac), } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum Mutability { MutMutable, MutImmutable, } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum BinOp { BiAdd, BiSub, @@ -583,7 +586,7 @@ pub enum BinOp { BiGt, } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum UnOp { UnUniq, UnDeref, @@ -593,7 +596,7 @@ pub enum UnOp { pub type Stmt = Spanned; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum Stmt_ { /// Could be an item or a local (let) binding: StmtDecl(P, NodeId), @@ -607,7 +610,7 @@ pub enum Stmt_ { StmtMac(Mac, MacStmtStyle), } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum MacStmtStyle { /// The macro statement had a trailing semicolon, e.g. `foo! { ... };` /// `foo!(...);`, `foo![...];` @@ -622,7 +625,7 @@ pub enum MacStmtStyle { /// Where a local declaration came from: either a true `let ... = /// ...;`, or one desugared from the pattern of a for loop. -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum LocalSource { LocalLet, LocalFor, @@ -631,7 +634,7 @@ pub enum LocalSource { // FIXME (pending discussion of #1697, #2178...): local should really be // a refinement on pat. /// Local represents a `let` statement, e.g., `let : = ;` -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Local { pub ty: P, pub pat: P, @@ -643,7 +646,7 @@ pub struct Local { pub type Decl = Spanned; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum Decl_ { /// A local (let) binding: DeclLocal(P), @@ -652,7 +655,7 @@ pub enum Decl_ { } /// represents one arm of a 'match' -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Arm { pub attrs: Vec, pub pats: Vec>, @@ -660,7 +663,7 @@ pub struct Arm { pub body: P, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Field { pub ident: SpannedIdent, pub expr: P, @@ -669,26 +672,26 @@ pub struct Field { pub type SpannedIdent = Spanned; -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum BlockCheckMode { DefaultBlock, UnsafeBlock(UnsafeSource), } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum UnsafeSource { CompilerGenerated, UserProvided, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Expr { pub id: NodeId, pub node: Expr_, pub span: Span, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum Expr_ { /// First expr is the place; second expr is the value. ExprBox(Option>, P), @@ -750,28 +753,28 @@ pub enum Expr_ { /// as SomeTrait>::SomeAssociatedItem /// ^~~~~ ^~~~~~~~~ ^~~~~~~~~~~~~~~~~~ /// self_type trait_name item_name -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct QPath { pub self_type: P, pub trait_ref: P, pub item_name: Ident, } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum MatchSource { Normal, IfLetDesugar { contains_else_clause: bool }, WhileLetDesugar, } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum CaptureClause { CaptureByValue, CaptureByRef, } /// A delimited sequence of token trees -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Delimited { /// The type of delimiter pub delim: token::DelimToken, @@ -806,7 +809,7 @@ impl Delimited { } /// A sequence of token treesee -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct SequenceRepetition { /// The sequence of token trees pub tts: Vec, @@ -820,7 +823,7 @@ pub struct SequenceRepetition { /// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star) /// for token sequences. -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum KleeneOp { ZeroOrMore, OneOrMore, @@ -838,7 +841,7 @@ pub enum KleeneOp { /// /// The RHS of an MBE macro is the only place `SubstNt`s are substituted. /// Nothing special happens to misnamed or misplaced `SubstNt`s. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] #[doc="For macro invocations; parsing is delegated to the macro"] pub enum TokenTree { /// A single token @@ -928,14 +931,14 @@ pub type Mac = Spanned; /// is being invoked, and the vector of token-trees contains the source /// of the macro invocation. /// There's only one flavor, now, so this could presumably be simplified. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum Mac_ { // NB: the additional ident for a macro_rules-style macro is actually // stored in the enclosing item. Oog. MacInvocTT(Path, Vec , SyntaxContext), // new macro-invocation } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum StrStyle { CookedStr, RawStr(uint) @@ -943,7 +946,7 @@ pub enum StrStyle { pub type Lit = Spanned; -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum Sign { Minus, Plus @@ -959,7 +962,7 @@ impl Sign where T: Int { } } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum LitIntType { SignedIntLit(IntTy, Sign), UnsignedIntLit(UintTy), @@ -976,7 +979,7 @@ impl LitIntType { } } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum Lit_ { LitStr(InternedString, StrStyle), LitBinary(Rc >), @@ -990,13 +993,13 @@ pub enum Lit_ { // NB: If you change this, you'll probably want to change the corresponding // type structure in middle/ty.rs as well. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct MutTy { pub ty: P, pub mutbl: Mutability, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct TypeField { pub ident: Ident, pub mt: MutTy, @@ -1005,7 +1008,7 @@ pub struct TypeField { /// Represents a required method in a trait declaration, /// one without a default implementation -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct TypeMethod { pub ident: Ident, pub attrs: Vec, @@ -1023,26 +1026,26 @@ pub struct TypeMethod { /// a default implementation A trait method is either required (meaning it /// doesn't have an implementation, just a signature) or provided (meaning it /// has a default implementation). -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum TraitItem { RequiredMethod(TypeMethod), ProvidedMethod(P), TypeTraitItem(P), } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum ImplItem { MethodImplItem(P), TypeImplItem(P), } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct AssociatedType { pub attrs: Vec, pub ty_param: TyParam, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Typedef { pub id: NodeId, pub span: Span, @@ -1052,7 +1055,7 @@ pub struct Typedef { pub typ: P, } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum IntTy { TyI, TyI8, @@ -1077,7 +1080,7 @@ impl IntTy { } } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum UintTy { TyU, TyU8, @@ -1102,7 +1105,7 @@ impl fmt::Show for UintTy { } } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum FloatTy { TyF32, TyF64, @@ -1123,7 +1126,7 @@ impl FloatTy { } // Bind a type to an associated type: `A=Foo`. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct TypeBinding { pub id: NodeId, pub ident: Ident, @@ -1133,7 +1136,7 @@ pub struct TypeBinding { // NB PartialEq method appears below. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Ty { pub id: NodeId, pub node: Ty_, @@ -1141,7 +1144,7 @@ pub struct Ty { } /// Not represented directly in the AST, referred to by name through a ty_path. -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum PrimTy { TyInt(IntTy), TyUint(UintTy), @@ -1151,7 +1154,7 @@ pub enum PrimTy { TyChar } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum Onceness { Once, Many @@ -1167,7 +1170,7 @@ impl fmt::Show for Onceness { } /// Represents the type of a closure -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct ClosureTy { pub lifetimes: Vec, pub unsafety: Unsafety, @@ -1176,7 +1179,7 @@ pub struct ClosureTy { pub bounds: TyParamBounds, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct BareFnTy { pub unsafety: Unsafety, pub abi: Abi, @@ -1184,7 +1187,7 @@ pub struct BareFnTy { pub decl: P } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] /// The different kinds of types recognized by the compiler pub enum Ty_ { TyVec(P), @@ -1219,13 +1222,13 @@ pub enum Ty_ { TyInfer, } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum AsmDialect { AsmAtt, AsmIntel } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct InlineAsm { pub asm: InternedString, pub asm_str_style: StrStyle, @@ -1239,7 +1242,7 @@ pub struct InlineAsm { } /// represents an argument in a function header -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Arg { pub ty: P, pub pat: P, @@ -1267,14 +1270,14 @@ impl Arg { } /// represents the header (not the body) of a function declaration -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct FnDecl { pub inputs: Vec, pub output: FunctionRetTy, pub variadic: bool } -#[deriving(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash)] +#[deriving(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)] pub enum Unsafety { Unsafe, Normal, @@ -1289,7 +1292,7 @@ impl fmt::Show for Unsafety { } } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum FunctionRetTy { /// Functions with return type ! that always /// raise an error or exit (i.e. never return to the caller) @@ -1308,7 +1311,7 @@ impl FunctionRetTy { } /// Represents the kind of 'self' associated with a method -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum ExplicitSelf_ { /// No self SelfStatic, @@ -1322,7 +1325,7 @@ pub enum ExplicitSelf_ { pub type ExplicitSelf = Spanned; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Method { pub attrs: Vec, pub id: NodeId, @@ -1330,7 +1333,7 @@ pub struct Method { pub node: Method_, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum Method_ { /// Represents a method declaration MethDecl(Ident, @@ -1345,7 +1348,7 @@ pub enum Method_ { MethMac(Mac), } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Mod { /// A span from the first token past `{` to the last token until `}`. /// For `mod foo;`, the inner span ranges from the first token @@ -1355,31 +1358,31 @@ pub struct Mod { pub items: Vec>, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct ForeignMod { pub abi: Abi, pub view_items: Vec, pub items: Vec>, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct VariantArg { pub ty: P, pub id: NodeId, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum VariantKind { TupleVariantKind(Vec), StructVariantKind(P), } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct EnumDef { pub variants: Vec>, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Variant_ { pub name: Ident, pub attrs: Vec, @@ -1391,7 +1394,7 @@ pub struct Variant_ { pub type Variant = Spanned; -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum PathListItem_ { PathListIdent { name: Ident, id: NodeId }, PathListMod { id: NodeId } @@ -1409,7 +1412,7 @@ pub type PathListItem = Spanned; pub type ViewPath = Spanned; -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum ViewPath_ { /// `foo::bar::baz as quux` @@ -1426,7 +1429,7 @@ pub enum ViewPath_ { ViewPathList(Path, Vec , NodeId) } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct ViewItem { pub node: ViewItem_, pub attrs: Vec, @@ -1434,7 +1437,7 @@ pub struct ViewItem { pub span: Span, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum ViewItem_ { /// Ident: name used to refer to this crate in the code /// optional (InternedString,StrStyle): if present, this is a location @@ -1450,17 +1453,17 @@ pub type Attribute = Spanned; /// Distinguishes between Attributes that decorate items and Attributes that /// are contained as statements within items. These two cases need to be /// distinguished for pretty-printing. -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum AttrStyle { AttrOuter, AttrInner, } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub struct AttrId(pub uint); /// Doc-comments are promoted to attributes that have is_sugared_doc = true -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Attribute_ { pub id: AttrId, pub style: AttrStyle, @@ -1473,13 +1476,13 @@ pub struct Attribute_ { /// that the ref_id is for. The impl_id maps to the "self type" of this impl. /// If this impl is an ItemImpl, the impl_id is redundant (it could be the /// same as the impl's node id). -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct TraitRef { pub path: Path, pub ref_id: NodeId, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct PolyTraitRef { /// The `'a` in `<'a> Foo<&'a T>` pub bound_lifetimes: Vec, @@ -1488,7 +1491,7 @@ pub struct PolyTraitRef { pub trait_ref: TraitRef } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum Visibility { Public, Inherited, @@ -1503,7 +1506,7 @@ impl Visibility { } } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct StructField_ { pub kind: StructFieldKind, pub id: NodeId, @@ -1522,7 +1525,7 @@ impl StructField_ { pub type StructField = Spanned; -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum StructFieldKind { NamedField(Ident, Visibility), /// Element of a tuple-like struct @@ -1538,7 +1541,7 @@ impl StructFieldKind { } } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct StructDef { /// Fields, not including ctor pub fields: Vec, @@ -1551,7 +1554,7 @@ pub struct StructDef { FIXME (#3300): Should allow items to be anonymous. Right now we just use dummy names for anon items. */ -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct Item { pub ident: Ident, pub attrs: Vec, @@ -1561,7 +1564,7 @@ pub struct Item { pub span: Span, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum Item_ { ItemStatic(P, Mutability, P), ItemConst(P, P), @@ -1605,7 +1608,7 @@ impl Item_ { } } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub struct ForeignItem { pub ident: Ident, pub attrs: Vec, @@ -1615,7 +1618,7 @@ pub struct ForeignItem { pub vis: Visibility, } -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum ForeignItem_ { ForeignItemFn(P, Generics), ForeignItemStatic(P, /* is_mutbl */ bool), @@ -1630,7 +1633,7 @@ impl ForeignItem_ { } } -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum UnboxedClosureKind { FnUnboxedClosureKind, FnMutUnboxedClosureKind, @@ -1640,7 +1643,7 @@ pub enum UnboxedClosureKind { /// The data we save and restore about an inlined item or method. This is not /// part of the AST that we parse from a file, but it becomes part of the tree /// that we trans. -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum InlinedItem { IIItem(P), IITraitItem(DefId /* impl id */, TraitItem), diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 02771809ae6..48d39079c5b 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -343,7 +343,7 @@ pub fn empty_generics() -> Generics { // ______________________________________________________________________ // Enumerating the IDs which appear in an AST -#[deriving(Copy, Encodable, Decodable, Show)] +#[deriving(RustcEncodable, RustcDecodable, Show, Copy)] pub struct IdRange { pub min: NodeId, pub max: NodeId, diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 127cc5ed51d..cddf1a9923a 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -340,14 +340,14 @@ pub fn cfg_matches(diagnostic: &SpanHandler, cfgs: &[P], cfg: &ast::Me } /// Represents the #[deprecated="foo"] and friends attributes. -#[deriving(Encodable,Decodable,Clone,Show)] +#[deriving(RustcEncodable,RustcDecodable,Clone,Show)] pub struct Stability { pub level: StabilityLevel, pub text: Option } /// The available stability levels. -#[deriving(Copy,Encodable,Decodable,PartialEq,PartialOrd,Clone,Show)] +#[deriving(RustcEncodable,RustcDecodable,PartialEq,PartialOrd,Clone,Show,Copy)] pub enum StabilityLevel { Deprecated, Experimental, @@ -464,7 +464,7 @@ fn int_type_of_word(s: &str) -> Option { } } -#[deriving(Copy, PartialEq, Show, Encodable, Decodable)] +#[deriving(PartialEq, Show, RustcEncodable, RustcDecodable, Copy)] pub enum ReprAttr { ReprAny, ReprInt(Span, IntType), @@ -483,7 +483,7 @@ impl ReprAttr { } } -#[deriving(Copy, Eq, Hash, PartialEq, Show, Encodable, Decodable)] +#[deriving(Eq, Hash, PartialEq, Show, RustcEncodable, RustcDecodable, Copy)] pub enum IntType { SignedInt(ast::IntTy), UnsignedInt(ast::UintTy) diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index c726e17a8fa..221c4fca586 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -92,7 +92,7 @@ pub struct Span { pub const DUMMY_SP: Span = Span { lo: BytePos(0), hi: BytePos(0), expn_id: NO_EXPANSION }; -#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +#[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub struct Spanned { pub node: T, pub span: Span, @@ -218,7 +218,7 @@ pub struct ExpnInfo { pub callee: NameAndSpan } -#[deriving(Copy, PartialEq, Eq, Clone, Show, Hash, Encodable, Decodable)] +#[deriving(PartialEq, Eq, Clone, Show, Hash, RustcEncodable, RustcDecodable, Copy)] pub struct ExpnId(u32); pub const NO_EXPANSION: ExpnId = ExpnId(-1); diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 0a8d59da896..4878a690bb9 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -21,24 +21,45 @@ use parse::token::InternedString; use parse::token; use ptr::P; +pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ + expand_deriving_decodable_imp(cx, span, mitem, item, push, "rustc_serialize") +} + pub fn expand_deriving_decodable(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, item: &Item, push: F) where F: FnOnce(P), +{ + expand_deriving_decodable_imp(cx, span, mitem, item, push, "serialize") +} + +fn expand_deriving_decodable_imp(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F, + krate: &'static str) where + F: FnOnce(P), { let trait_def = TraitDef { span: span, attributes: Vec::new(), - path: Path::new_(vec!("serialize", "Decodable"), None, + path: Path::new_(vec!(krate, "Decodable"), None, vec!(box Literal(Path::new_local("__D")), box Literal(Path::new_local("__E"))), true), additional_bounds: Vec::new(), generics: LifetimeBounds { lifetimes: Vec::new(), bounds: vec!(("__D", None, vec!(Path::new_( - vec!("serialize", "Decoder"), None, + vec!(krate, "Decoder"), None, vec!(box Literal(Path::new_local("__E"))), true))), ("__E", None, vec!())) }, @@ -54,7 +75,7 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt, box Literal(Path::new_local("__E"))), true)), attributes: Vec::new(), combine_substructure: combine_substructure(|a, b, c| { - decodable_substructure(a, b, c) + decodable_substructure(a, b, c, krate) }), }) }; @@ -63,9 +84,10 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt, } fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span, - substr: &Substructure) -> P { + substr: &Substructure, + krate: &str) -> P { let decoder = substr.nonself_args[0].clone(); - let recurse = vec!(cx.ident_of("serialize"), + let recurse = vec!(cx.ident_of(krate), cx.ident_of("Decodable"), cx.ident_of("decode")); // throw an underscore in front to suppress unused variable warnings diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 30851ebeaae..1b8d01f1cd0 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -97,24 +97,45 @@ use ext::deriving::generic::ty::*; use parse::token; use ptr::P; +pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P), +{ + expand_deriving_encodable_imp(cx, span, mitem, item, push, "rustc_serialize") +} + pub fn expand_deriving_encodable(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, item: &Item, push: F) where F: FnOnce(P), +{ + expand_deriving_encodable_imp(cx, span, mitem, item, push, "serialize") +} + +fn expand_deriving_encodable_imp(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F, + krate: &'static str) where + F: FnOnce(P), { let trait_def = TraitDef { span: span, attributes: Vec::new(), - path: Path::new_(vec!("serialize", "Encodable"), None, + path: Path::new_(vec!(krate, "Encodable"), None, vec!(box Literal(Path::new_local("__S")), box Literal(Path::new_local("__E"))), true), additional_bounds: Vec::new(), generics: LifetimeBounds { lifetimes: Vec::new(), bounds: vec!(("__S", None, vec!(Path::new_( - vec!("serialize", "Encoder"), None, + vec!(krate, "Encoder"), None, vec!(box Literal(Path::new_local("__E"))), true))), ("__E", None, vec!())) }, diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 839e99c81d1..b5957fd1b8a 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -71,24 +71,22 @@ pub fn expand_meta_deriving(cx: &mut ExtCtxt, "Hash" => expand!(hash::expand_deriving_hash), "RustcEncodable" => { - expand!(encodable::expand_deriving_encodable) + expand!(encodable::expand_deriving_rustc_encodable) } "RustcDecodable" => { - expand!(decodable::expand_deriving_decodable) + expand!(decodable::expand_deriving_rustc_decodable) } "Encodable" => { - // NOTE: uncomment after a stage0 snap - // cx.span_warn(titem.span, - // "deriving(Encodable) is deprecated \ - // in favor of deriving(RustcEncodable)"); + cx.span_warn(titem.span, + "deriving(Encodable) is deprecated \ + in favor of deriving(RustcEncodable)"); expand!(encodable::expand_deriving_encodable) } "Decodable" => { - // NOTE: uncomment after a stage0 snap - // cx.span_warn(titem.span, - // "deriving(Decodable) is deprecated \ - // in favor of deriving(RustcDecodable)"); + cx.span_warn(titem.span, + "deriving(Decodable) is deprecated \ + in favor of deriving(RustcDecodable)"); expand!(decodable::expand_deriving_decodable) } diff --git a/src/libsyntax/ext/mtwt.rs b/src/libsyntax/ext/mtwt.rs index f0392912878..6a296333fdb 100644 --- a/src/libsyntax/ext/mtwt.rs +++ b/src/libsyntax/ext/mtwt.rs @@ -39,7 +39,7 @@ pub struct SCTable { rename_memo: RefCell>, } -#[deriving(Copy, PartialEq, Encodable, Decodable, Hash, Show)] +#[deriving(PartialEq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum SyntaxContext_ { EmptyCtxt, Mark (Mrk,SyntaxContext), diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 5f62c74ef07..d5093c5055c 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -34,6 +34,8 @@ extern crate serialize; extern crate term; extern crate libc; +extern crate "serialize" as rustc_serialize; // used by deriving + pub mod util { pub mod interner; #[cfg(test)] diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index dad369792d7..87d65e258de 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -28,7 +28,7 @@ use std::path::BytesContainer; use std::rc::Rc; #[allow(non_camel_case_types)] -#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Show, Copy)] pub enum BinOpToken { Plus, Minus, @@ -43,7 +43,7 @@ pub enum BinOpToken { } /// A delimeter token -#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Show, Copy)] pub enum DelimToken { /// A round parenthesis: `(` or `)` Paren, @@ -53,14 +53,14 @@ pub enum DelimToken { Brace, } -#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Show, Copy)] pub enum IdentStyle { /// `::` follows the identifier with no whitespace in-between. ModName, Plain, } -#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Show, Copy)] pub enum Lit { Byte(ast::Name), Char(ast::Name), @@ -86,7 +86,7 @@ impl Lit { } #[allow(non_camel_case_types)] -#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Show)] pub enum Token { /* Expression-operator symbols. */ Eq, @@ -334,7 +334,7 @@ impl Token { } } -#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash)] /// For interpolation during macro expansion. pub enum Nonterminal { NtItem(P), diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 5b04a1fed89..7ef6ec4fdcf 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -37,6 +37,7 @@ extern crate getopts; extern crate regex; extern crate serialize; +extern crate "serialize" as rustc_serialize; extern crate term; pub use self::TestFn::*; @@ -213,7 +214,7 @@ pub struct TestDescAndFn { pub testfn: TestFn, } -#[deriving(Clone, Copy, Encodable, Decodable, PartialEq, Show)] +#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq, Show, Copy)] pub struct Metric { value: f64, noise: f64 diff --git a/src/libtime/lib.rs b/src/libtime/lib.rs index dfa9b924274..e58a0229d69 100644 --- a/src/libtime/lib.rs +++ b/src/libtime/lib.rs @@ -24,7 +24,9 @@ #[cfg(test)] #[phase(plugin, link)] extern crate log; +#[cfg(stage0)] extern crate serialize; +extern crate "serialize" as rustc_serialize; extern crate libc; pub use self::ParseError::*; @@ -76,7 +78,8 @@ mod imp { } /// A record specifying a time value in seconds and nanoseconds. -#[deriving(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable, Show)] +#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, + RustcDecodable, Show, Copy)] pub struct Timespec { pub sec: i64, pub nsec: i32, -- cgit 1.4.1-3-g733a5 From f8cfd2480b69a1cc266fc91d0b60c825a9dc18a7 Mon Sep 17 00:00:00 2001 From: Florian Wilkens Date: Fri, 19 Dec 2014 21:52:10 +0100 Subject: Renaming of the Iter types as in RFC #344 libcore: slice::Items -> slice::Iter, slice::MutItems -> slice::IterMut libcollections: *::Items -> *::Iter, *::MoveItems -> *::IntoIter, *::MutItems -> *::IterMut This is of course a [breaking-change]. --- src/libcollections/binary_heap.rs | 29 ++++++------- src/libcollections/bit.rs | 2 +- src/libcollections/btree/node.rs | 12 +++--- src/libcollections/btree/set.rs | 40 ++++++++--------- src/libcollections/dlist.rs | 46 ++++++++++---------- src/libcollections/enum_set.rs | 14 +++--- src/libcollections/ring_buf.rs | 40 ++++++++--------- src/libcollections/slice.rs | 12 +++--- src/libcollections/vec.rs | 18 ++++---- src/libcollections/vec_map.rs | 16 +++---- src/libcore/fmt/mod.rs | 2 +- src/libcore/slice.rs | 50 +++++++++++----------- src/libcore/str.rs | 9 ++-- src/libgraphviz/maybe_owned_vec.rs | 2 +- src/liblog/lib.rs | 2 +- src/libregex/re.rs | 4 +- src/librustc/middle/lang_items.rs | 2 +- src/librustc/middle/subst.rs | 4 +- src/librustc/middle/traits/mod.rs | 8 ++-- src/libsyntax/ast_map/mod.rs | 4 +- src/libsyntax/ext/deriving/generic/mod.rs | 2 +- src/libsyntax/owned_slice.rs | 2 +- src/libsyntax/util/small_vector.rs | 18 ++++---- src/test/bench/shootout-k-nucleotide.rs | 2 +- .../resolve-conflict-type-vs-import.rs | 6 +-- src/test/run-pass/issue-13167.rs | 2 +- 26 files changed, 173 insertions(+), 175 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 0840e8ec881..c9d1d9d13fb 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -239,9 +239,8 @@ impl BinaryHeap { /// } /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter(&self) -> Items { - Items { iter: self.data.iter() } - } + pub fn iter(&self) -> Iter { + Iter { iter: self.data.iter() } } /// Creates a consuming iterator, that is, one that moves each value out of /// the binary heap in arbitrary order. The binary heap cannot be used @@ -260,8 +259,8 @@ impl BinaryHeap { /// } /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn into_iter(self) -> MoveItems { - MoveItems { iter: self.data.into_iter() } + pub fn into_iter(self) -> IntoIter { + IntoIter { iter: self.data.into_iter() } } /// Returns the greatest item in a queue, or `None` if it is empty. @@ -571,11 +570,11 @@ impl BinaryHeap { } /// `BinaryHeap` iterator. -pub struct Items<'a, T: 'a> { - iter: slice::Items<'a, T>, +pub struct Iter <'a, T: 'a> { + iter: slice::Iter<'a, T>, } -impl<'a, T> Iterator<&'a T> for Items<'a, T> { +impl<'a, T> Iterator<&'a T> for Iter<'a, T> { #[inline] fn next(&mut self) -> Option<&'a T> { self.iter.next() } @@ -583,19 +582,19 @@ impl<'a, T> Iterator<&'a T> for Items<'a, T> { fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } -impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> { +impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() } } -impl<'a, T> ExactSizeIterator<&'a T> for Items<'a, T> {} +impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} /// An iterator that moves out of a `BinaryHeap`. -pub struct MoveItems { - iter: vec::MoveItems, +pub struct IntoIter { + iter: vec::IntoIter, } -impl Iterator for MoveItems { +impl Iterator for IntoIter { #[inline] fn next(&mut self) -> Option { self.iter.next() } @@ -603,12 +602,12 @@ impl Iterator for MoveItems { fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } -impl DoubleEndedIterator for MoveItems { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.iter.next_back() } } -impl ExactSizeIterator for MoveItems {} +impl ExactSizeIterator for IntoIter {} /// An iterator that drains a `BinaryHeap`. pub struct Drain<'a, T: 'a> { diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 17dbf8a2cae..8ceeb99d585 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -145,7 +145,7 @@ impl Index for Bitv { } struct MaskWords<'a> { - iter: slice::Items<'a, u32>, + iter: slice::Iter<'a, u32>, next_word: Option<&'a u32>, last_word_mask: u32, offset: uint diff --git a/src/libcollections/btree/node.rs b/src/libcollections/btree/node.rs index 86c7def49b1..2c3c546fdb7 100644 --- a/src/libcollections/btree/node.rs +++ b/src/libcollections/btree/node.rs @@ -1382,14 +1382,14 @@ pub enum TraversalItem { } /// A traversal over a node's entries and edges -pub type Traversal<'a, K, V> = AbsTraversal, - slice::Items<'a, V>>, - slice::Items<'a, Node>>>; +pub type Traversal<'a, K, V> = AbsTraversal, + slice::Iter<'a, V>>, + slice::Iter<'a, Node>>>; /// A mutable traversal over a node's entries and edges -pub type MutTraversal<'a, K, V> = AbsTraversal, - slice::MutItems<'a, V>>, - slice::MutItems<'a, Node>>>; +pub type MutTraversal<'a, K, V> = AbsTraversal, + slice::IterMut<'a, V>>, + slice::IterMut<'a, Node>>>; /// An owning traversal over a node's entries and edges pub type MoveTraversal = AbsTraversal>; diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index e4328a3cb20..26e82994f56 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -33,37 +33,37 @@ pub struct BTreeSet{ } /// An iterator over a BTreeSet's items. -pub struct Items<'a, T: 'a> { +pub struct Iter<'a, T: 'a> { iter: Keys<'a, T, ()> } /// An owning iterator over a BTreeSet's items. -pub struct MoveItems { +pub struct IntoIter { iter: Map<(T, ()), T, MoveEntries, fn((T, ())) -> T> } /// A lazy iterator producing elements in the set difference (in-order). pub struct DifferenceItems<'a, T:'a> { - a: Peekable<&'a T, Items<'a, T>>, - b: Peekable<&'a T, Items<'a, T>>, + a: Peekable<&'a T, Iter<'a, T>>, + b: Peekable<&'a T, Iter<'a, T>>, } /// A lazy iterator producing elements in the set symmetric difference (in-order). pub struct SymDifferenceItems<'a, T:'a> { - a: Peekable<&'a T, Items<'a, T>>, - b: Peekable<&'a T, Items<'a, T>>, + a: Peekable<&'a T, Iter<'a, T>>, + b: Peekable<&'a T, Iter<'a, T>>, } /// A lazy iterator producing elements in the set intersection (in-order). pub struct IntersectionItems<'a, T:'a> { - a: Peekable<&'a T, Items<'a, T>>, - b: Peekable<&'a T, Items<'a, T>>, + a: Peekable<&'a T, Iter<'a, T>>, + b: Peekable<&'a T, Iter<'a, T>>, } /// A lazy iterator producing elements in the set union (in-order). pub struct UnionItems<'a, T:'a> { - a: Peekable<&'a T, Items<'a, T>>, - b: Peekable<&'a T, Items<'a, T>>, + a: Peekable<&'a T, Iter<'a, T>>, + b: Peekable<&'a T, Iter<'a, T>>, } impl BTreeSet { @@ -107,8 +107,8 @@ impl BTreeSet { /// assert_eq!(v, vec![1u,2,3,4]); /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter<'a>(&'a self) -> Items<'a, T> { - Items { iter: self.map.keys() } + pub fn iter<'a>(&'a self) -> Iter<'a, T> { + Iter { iter: self.map.keys() } } /// Gets an iterator for moving out the BtreeSet's contents. @@ -124,10 +124,10 @@ impl BTreeSet { /// assert_eq!(v, vec![1u,2,3,4]); /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn into_iter(self) -> MoveItems { + pub fn into_iter(self) -> IntoIter { fn first((a, _): (A, B)) -> A { a } - MoveItems { iter: self.map.into_iter().map(first) } + IntoIter { iter: self.map.into_iter().map(first) } } } @@ -544,24 +544,24 @@ impl Show for BTreeSet { } } -impl<'a, T> Iterator<&'a T> for Items<'a, T> { +impl<'a, T> Iterator<&'a T> for Iter<'a, T> { fn next(&mut self) -> Option<&'a T> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } -impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> { +impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() } } -impl<'a, T> ExactSizeIterator<&'a T> for Items<'a, T> {} +impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} -impl Iterator for MoveItems { +impl Iterator for IntoIter { fn next(&mut self) -> Option { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } -impl DoubleEndedIterator for MoveItems { +impl DoubleEndedIterator for IntoIter { fn next_back(&mut self) -> Option { self.iter.next_back() } } -impl ExactSizeIterator for MoveItems {} +impl ExactSizeIterator for IntoIter {} /// Compare `x` and `y`, but return `short` if x is None and `long` if y is None fn cmp_opt(x: Option<&T>, y: Option<&T>, diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index d3c1a0f81a3..eb057b48853 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -51,21 +51,21 @@ struct Node { } /// An iterator over references to the items of a `DList`. -pub struct Items<'a, T:'a> { +pub struct Iter<'a, T:'a> { head: &'a Link, tail: Rawlink>, nelem: uint, } // FIXME #11820: the &'a Option<> of the Link stops clone working. -impl<'a, T> Clone for Items<'a, T> { - fn clone(&self) -> Items<'a, T> { *self } +impl<'a, T> Clone for Iter<'a, T> { + fn clone(&self) -> Iter<'a, T> { *self } } -impl<'a,T> Copy for Items<'a,T> {} +impl<'a,T> Copy for Iter<'a,T> {} /// An iterator over mutable references to the items of a `DList`. -pub struct MutItems<'a, T:'a> { +pub struct IterMut<'a, T:'a> { list: &'a mut DList, head: Rawlink>, tail: Rawlink>, @@ -74,7 +74,7 @@ pub struct MutItems<'a, T:'a> { /// An iterator over mutable references to the items of a `DList`. #[deriving(Clone)] -pub struct MoveItems { +pub struct IntoIter { list: DList } @@ -394,19 +394,19 @@ impl DList { /// Provides a forward iterator. #[inline] #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter<'a>(&'a self) -> Items<'a, T> { - Items{nelem: self.len(), head: &self.list_head, tail: self.list_tail} + pub fn iter<'a>(&'a self) -> Iter<'a, T> { + Iter{nelem: self.len(), head: &self.list_head, tail: self.list_tail} } /// Provides a forward iterator with mutable references. #[inline] #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> { + pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> { let head_raw = match self.list_head { Some(ref mut h) => Rawlink::some(&mut **h), None => Rawlink::none(), }; - MutItems{ + IterMut{ nelem: self.len(), head: head_raw, tail: self.list_tail, @@ -417,8 +417,8 @@ impl DList { /// Consumes the list into an iterator yielding elements by value. #[inline] #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn into_iter(self) -> MoveItems { - MoveItems{list: self} + pub fn into_iter(self) -> IntoIter { + IntoIter{list: self} } /// Returns `true` if the `DList` is empty. @@ -579,7 +579,7 @@ impl Drop for DList { } -impl<'a, A> Iterator<&'a A> for Items<'a, A> { +impl<'a, A> Iterator<&'a A> for Iter<'a, A> { #[inline] fn next(&mut self) -> Option<&'a A> { if self.nelem == 0 { @@ -598,7 +598,7 @@ impl<'a, A> Iterator<&'a A> for Items<'a, A> { } } -impl<'a, A> DoubleEndedIterator<&'a A> for Items<'a, A> { +impl<'a, A> DoubleEndedIterator<&'a A> for Iter<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a A> { if self.nelem == 0 { @@ -612,9 +612,9 @@ impl<'a, A> DoubleEndedIterator<&'a A> for Items<'a, A> { } } -impl<'a, A> ExactSizeIterator<&'a A> for Items<'a, A> {} +impl<'a, A> ExactSizeIterator<&'a A> for Iter<'a, A> {} -impl<'a, A> Iterator<&'a mut A> for MutItems<'a, A> { +impl<'a, A> Iterator<&'a mut A> for IterMut<'a, A> { #[inline] fn next(&mut self) -> Option<&'a mut A> { if self.nelem == 0 { @@ -636,7 +636,7 @@ impl<'a, A> Iterator<&'a mut A> for MutItems<'a, A> { } } -impl<'a, A> DoubleEndedIterator<&'a mut A> for MutItems<'a, A> { +impl<'a, A> DoubleEndedIterator<&'a mut A> for IterMut<'a, A> { #[inline] fn next_back(&mut self) -> Option<&'a mut A> { if self.nelem == 0 { @@ -650,7 +650,7 @@ impl<'a, A> DoubleEndedIterator<&'a mut A> for MutItems<'a, A> { } } -impl<'a, A> ExactSizeIterator<&'a mut A> for MutItems<'a, A> {} +impl<'a, A> ExactSizeIterator<&'a mut A> for IterMut<'a, A> {} /// Allows mutating a `DList` while iterating. pub trait ListInsertion { @@ -664,8 +664,8 @@ pub trait ListInsertion { fn peek_next<'a>(&'a mut self) -> Option<&'a mut A>; } -// private methods for MutItems -impl<'a, A> MutItems<'a, A> { +// private methods for IterMut +impl<'a, A> IterMut<'a, A> { fn insert_next_node(&mut self, mut ins_node: Box>) { // Insert before `self.head` so that it is between the // previously yielded element and self.head. @@ -687,7 +687,7 @@ impl<'a, A> MutItems<'a, A> { } } -impl<'a, A> ListInsertion for MutItems<'a, A> { +impl<'a, A> ListInsertion for IterMut<'a, A> { #[inline] fn insert_next(&mut self, elt: A) { self.insert_next_node(box Node::new(elt)) @@ -702,7 +702,7 @@ impl<'a, A> ListInsertion for MutItems<'a, A> { } } -impl Iterator for MoveItems { +impl Iterator for IntoIter { #[inline] fn next(&mut self) -> Option { self.list.pop_front() } @@ -712,7 +712,7 @@ impl Iterator for MoveItems { } } -impl DoubleEndedIterator for MoveItems { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.list.pop_back() } } diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index bb762f4fb4e..fd04ce94247 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -178,8 +178,8 @@ impl EnumSet { /// Returns an iterator over an `EnumSet`. #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter(&self) -> Items { - Items::new(self.bits) + pub fn iter(&self) -> Iter { + Iter::new(self.bits) } } @@ -208,18 +208,18 @@ impl BitXor, EnumSet> for EnumSet { } /// An iterator over an EnumSet -pub struct Items { +pub struct Iter { index: uint, bits: uint, } -impl Items { - fn new(bits: uint) -> Items { - Items { index: 0, bits: bits } +impl Iter { + fn new(bits: uint) -> Iter { + Iter { index: 0, bits: bits } } } -impl Iterator for Items { +impl Iterator for Iter { fn next(&mut self) -> Option { if self.bits == 0 { return None; diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index aa0e33248fc..37c088f7453 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -376,8 +376,8 @@ impl RingBuf { /// assert_eq!(buf.iter().collect::>().as_slice(), b); /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter(&self) -> Items { - Items { + pub fn iter(&self) -> Iter { + Iter { tail: self.tail, head: self.head, ring: unsafe { self.buffer_as_slice() } @@ -402,8 +402,8 @@ impl RingBuf { /// assert_eq!(buf.iter_mut().collect::>()[], b); /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> { - MutItems { + pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> { + IterMut { tail: self.tail, head: self.head, cap: self.cap, @@ -414,8 +414,8 @@ impl RingBuf { /// Consumes the list into an iterator yielding elements by value. #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn into_iter(self) -> MoveItems { - MoveItems { + pub fn into_iter(self) -> IntoIter { + IntoIter { inner: self, } } @@ -1122,13 +1122,13 @@ fn count(tail: uint, head: uint, size: uint) -> uint { } /// `RingBuf` iterator. -pub struct Items<'a, T:'a> { +pub struct Iter<'a, T:'a> { ring: &'a [T], tail: uint, head: uint } -impl<'a, T> Iterator<&'a T> for Items<'a, T> { +impl<'a, T> Iterator<&'a T> for Iter<'a, T> { #[inline] fn next(&mut self) -> Option<&'a T> { if self.tail == self.head { @@ -1146,7 +1146,7 @@ impl<'a, T> Iterator<&'a T> for Items<'a, T> { } } -impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> { +impl<'a, T> DoubleEndedIterator<&'a T> for Iter<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a T> { if self.tail == self.head { @@ -1157,9 +1157,9 @@ impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> { } } -impl<'a, T> ExactSizeIterator<&'a T> for Items<'a, T> {} +impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} -impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> { +impl<'a, T> RandomAccessIterator<&'a T> for Iter<'a, T> { #[inline] fn indexable(&self) -> uint { let (len, _) = self.size_hint(); @@ -1177,11 +1177,11 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> { } } -// FIXME This was implemented differently from Items because of a problem +// FIXME This was implemented differently from Iter because of a problem // with returning the mutable reference. I couldn't find a way to // make the lifetime checker happy so, but there should be a way. /// `RingBuf` mutable iterator. -pub struct MutItems<'a, T:'a> { +pub struct IterMut<'a, T:'a> { ptr: *mut T, tail: uint, head: uint, @@ -1189,7 +1189,7 @@ pub struct MutItems<'a, T:'a> { marker: marker::ContravariantLifetime<'a>, } -impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> { +impl<'a, T> Iterator<&'a mut T> for IterMut<'a, T> { #[inline] fn next(&mut self) -> Option<&'a mut T> { if self.tail == self.head { @@ -1210,7 +1210,7 @@ impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> { } } -impl<'a, T> DoubleEndedIterator<&'a mut T> for MutItems<'a, T> { +impl<'a, T> DoubleEndedIterator<&'a mut T> for IterMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut T> { if self.tail == self.head { @@ -1224,14 +1224,14 @@ impl<'a, T> DoubleEndedIterator<&'a mut T> for MutItems<'a, T> { } } -impl<'a, T> ExactSizeIterator<&'a mut T> for MutItems<'a, T> {} +impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {} // A by-value RingBuf iterator -pub struct MoveItems { +pub struct IntoIter { inner: RingBuf, } -impl Iterator for MoveItems { +impl Iterator for IntoIter { #[inline] fn next(&mut self) -> Option { self.inner.pop_front() @@ -1244,14 +1244,14 @@ impl Iterator for MoveItems { } } -impl DoubleEndedIterator for MoveItems { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back(&mut self) -> Option { self.inner.pop_back() } } -impl ExactSizeIterator for MoveItems {} +impl ExactSizeIterator for IntoIter {} /// A draining RingBuf iterator pub struct Drain<'a, T: 'a> { diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 16adf6fa224..d6d94f57acf 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -37,7 +37,7 @@ //! //! ## Structs //! -//! There are several structs that are useful for slices, such as `Items`, which +//! There are several structs that are useful for slices, such as `Iter`, which //! represents iteration over a slice. //! //! ## Traits @@ -104,7 +104,7 @@ use self::Direction::*; use vec::Vec; pub use core::slice::{Chunks, AsSlice, SplitsN, Windows}; -pub use core::slice::{Items, MutItems, PartialEqSliceExt}; +pub use core::slice::{Iter, IterMut, PartialEqSliceExt}; pub use core::slice::{ImmutableIntSlice, MutableIntSlice}; pub use core::slice::{MutSplits, MutChunks, Splits}; pub use core::slice::{bytes, mut_ref_slice, ref_slice}; @@ -771,7 +771,7 @@ pub trait SliceExt for Sized? { /// Returns an iterator over the slice #[unstable = "iterator type may change"] - fn iter(&self) -> Items; + fn iter(&self) -> Iter; /// Returns an iterator over subslices separated by elements that match /// `pred`. The matched element is not contained in the subslices. @@ -970,7 +970,7 @@ pub trait SliceExt for Sized? { /// Returns an iterator that allows modifying each value #[unstable = "waiting on iterator type name conventions"] - fn iter_mut(&mut self) -> MutItems; + fn iter_mut(&mut self) -> IterMut; /// Returns a mutable pointer to the first element of a slice, or `None` if it is empty #[unstable = "name may change"] @@ -1137,7 +1137,7 @@ impl SliceExt for [T] { } #[inline] - fn iter<'a>(&'a self) -> Items<'a, T> { + fn iter<'a>(&'a self) -> Iter<'a, T> { core_slice::SliceExt::iter(self) } @@ -1246,7 +1246,7 @@ impl SliceExt for [T] { } #[inline] - fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> { + fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> { core_slice::SliceExt::iter_mut(self) } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index b82c7e4cba2..fa0e4a2340e 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -888,7 +888,7 @@ impl Vec { /// ``` #[inline] #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn into_iter(self) -> MoveItems { + pub fn into_iter(self) -> IntoIter { unsafe { let ptr = self.ptr; let cap = self.cap; @@ -899,7 +899,7 @@ impl Vec { ptr.offset(self.len() as int) as *const T }; mem::forget(self); - MoveItems { allocation: ptr, cap: cap, ptr: begin, end: end } + IntoIter { allocation: ptr, cap: cap, ptr: begin, end: end } } } @@ -1402,21 +1402,21 @@ impl fmt::Show for Vec { } /// An iterator that moves out of a vector. -pub struct MoveItems { +pub struct IntoIter { allocation: *mut T, // the block of memory allocated for the vector cap: uint, // the capacity of the vector ptr: *const T, end: *const T } -impl MoveItems { +impl IntoIter { /// Drops all items that have not yet been moved and returns the empty vector. #[inline] #[unstable] pub fn into_inner(mut self) -> Vec { unsafe { for _x in self { } - let MoveItems { allocation, cap, ptr: _ptr, end: _end } = self; + let IntoIter { allocation, cap, ptr: _ptr, end: _end } = self; mem::forget(self); Vec { ptr: allocation, cap: cap, len: 0 } } @@ -1427,7 +1427,7 @@ impl MoveItems { pub fn unwrap(self) -> Vec { self.into_inner() } } -impl Iterator for MoveItems { +impl Iterator for IntoIter { #[inline] fn next<'a>(&'a mut self) -> Option { unsafe { @@ -1461,7 +1461,7 @@ impl Iterator for MoveItems { } } -impl DoubleEndedIterator for MoveItems { +impl DoubleEndedIterator for IntoIter { #[inline] fn next_back<'a>(&'a mut self) -> Option { unsafe { @@ -1484,10 +1484,10 @@ impl DoubleEndedIterator for MoveItems { } } -impl ExactSizeIterator for MoveItems {} +impl ExactSizeIterator for IntoIter {} #[unsafe_destructor] -impl Drop for MoveItems { +impl Drop for IntoIter { fn drop(&mut self) { // destroy the remaining elements if self.cap != 0 { diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 1babde6066d..802be427189 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -235,13 +235,13 @@ impl VecMap { /// assert_eq!(vec, vec![(1, "a"), (2, "b"), (3, "c")]); /// ``` #[unstable = "matches collection reform specification, waiting for dust to settle"] - pub fn into_iter(&mut self) -> MoveItems { + pub fn into_iter(&mut self) -> IntoIter { fn filter((i, v): (uint, Option)) -> Option<(uint, A)> { v.map(|v| (i, v)) } let values = replace(&mut self.v, vec!()); - MoveItems { iter: values.into_iter().enumerate().filter_map(filter) } + IntoIter { iter: values.into_iter().enumerate().filter_map(filter) } } /// Return the number of elements in the map. @@ -608,7 +608,7 @@ macro_rules! double_ended_iterator { pub struct Entries<'a, V:'a> { front: uint, back: uint, - iter: slice::Items<'a, Option> + iter: slice::Iter<'a, Option> } iterator! { impl Entries -> (uint, &'a V), as_ref } @@ -619,7 +619,7 @@ double_ended_iterator! { impl Entries -> (uint, &'a V), as_ref } pub struct MutEntries<'a, V:'a> { front: uint, back: uint, - iter: slice::MutItems<'a, Option> + iter: slice::IterMut<'a, Option> } iterator! { impl MutEntries -> (uint, &'a mut V), as_mut } @@ -636,11 +636,11 @@ pub struct Values<'a, V: 'a> { } /// A consuming iterator over the key-value pairs of a map. -pub struct MoveItems { +pub struct IntoIter { iter: FilterMap< (uint, Option), (uint, V), - Enumerate>>, + Enumerate>>, fn((uint, Option)) -> Option<(uint, V)>> } @@ -662,11 +662,11 @@ impl<'a, V> DoubleEndedIterator<&'a V> for Values<'a, V> { } -impl Iterator<(uint, V)> for MoveItems { +impl Iterator<(uint, V)> for IntoIter { fn next(&mut self) -> Option<(uint, V)> { self.iter.next() } fn size_hint(&self) -> (uint, Option) { self.iter.size_hint() } } -impl DoubleEndedIterator<(uint, V)> for MoveItems { +impl DoubleEndedIterator<(uint, V)> for IntoIter { fn next_back(&mut self) -> Option<(uint, V)> { self.iter.next_back() } } diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 79fb11f3854..96f67ac4f7a 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -89,7 +89,7 @@ pub struct Formatter<'a> { precision: Option, buf: &'a mut (FormatWriter+'a), - curarg: slice::Items<'a, Argument<'a>>, + curarg: slice::Iter<'a, Argument<'a>>, args: &'a [Argument<'a>], } diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index efc92429afd..6092a45c97d 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -67,7 +67,7 @@ pub trait SliceExt for Sized? { fn slice_from<'a>(&'a self, start: uint) -> &'a [T]; fn slice_to<'a>(&'a self, end: uint) -> &'a [T]; fn split_at<'a>(&'a self, mid: uint) -> (&'a [T], &'a [T]); - fn iter<'a>(&'a self) -> Items<'a, T>; + fn iter<'a>(&'a self) -> Iter<'a, T>; fn split<'a, P>(&'a self, pred: P) -> Splits<'a, T, P> where P: FnMut(&T) -> bool; fn splitn<'a, P>(&'a self, n: uint, pred: P) -> SplitsN> @@ -92,7 +92,7 @@ pub trait SliceExt for Sized? { fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [T]; fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [T]; fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [T]; - fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T>; + fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T>; fn head_mut<'a>(&'a mut self) -> Option<&'a mut T>; fn tail_mut<'a>(&'a mut self) -> &'a mut [T]; fn init_mut<'a>(&'a mut self) -> &'a mut [T]; @@ -141,15 +141,15 @@ impl SliceExt for [T] { } #[inline] - fn iter<'a>(&'a self) -> Items<'a, T> { + fn iter<'a>(&'a self) -> Iter<'a, T> { unsafe { let p = self.as_ptr(); if mem::size_of::() == 0 { - Items{ptr: p, + Iter{ptr: p, end: (p as uint + self.len()) as *const T, marker: marker::ContravariantLifetime::<'a>} } else { - Items{ptr: p, + Iter{ptr: p, end: p.offset(self.len() as int), marker: marker::ContravariantLifetime::<'a>} } @@ -286,15 +286,15 @@ impl SliceExt for [T] { } #[inline] - fn iter_mut<'a>(&'a mut self) -> MutItems<'a, T> { + fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T> { unsafe { let p = self.as_mut_ptr(); if mem::size_of::() == 0 { - MutItems{ptr: p, + IterMut{ptr: p, end: (p as uint + self.len()) as *mut T, marker: marker::ContravariantLifetime::<'a>} } else { - MutItems{ptr: p, + IterMut{ptr: p, end: p.offset(self.len() as int), marker: marker::ContravariantLifetime::<'a>} } @@ -655,7 +655,7 @@ impl<'a, T> Default for &'a [T] { // Iterators // -// The shared definition of the `Item` and `MutItems` iterators +// The shared definition of the `Item` and `IterMut` iterators macro_rules! iterator { (struct $name:ident -> $ptr:ty, $elem:ty) => { #[experimental = "needs review"] @@ -738,14 +738,14 @@ macro_rules! make_slice { /// Immutable slice iterator #[experimental = "needs review"] -pub struct Items<'a, T: 'a> { +pub struct Iter<'a, T: 'a> { ptr: *const T, end: *const T, marker: marker::ContravariantLifetime<'a> } #[experimental] -impl<'a, T> ops::Slice for Items<'a, T> { +impl<'a, T> ops::Slice for Iter<'a, T> { fn as_slice_(&self) -> &[T] { self.as_slice() } @@ -763,7 +763,7 @@ impl<'a, T> ops::Slice for Items<'a, T> { } } -impl<'a, T> Items<'a, T> { +impl<'a, T> Iter<'a, T> { /// View the underlying data as a subslice of the original data. /// /// This has the same lifetime as the original slice, and so the @@ -774,20 +774,20 @@ impl<'a, T> Items<'a, T> { } } -impl<'a,T> Copy for Items<'a,T> {} +impl<'a,T> Copy for Iter<'a,T> {} -iterator!{struct Items -> *const T, &'a T} +iterator!{struct Iter -> *const T, &'a T} #[experimental = "needs review"] -impl<'a, T> ExactSizeIterator<&'a T> for Items<'a, T> {} +impl<'a, T> ExactSizeIterator<&'a T> for Iter<'a, T> {} -#[stable] -impl<'a, T> Clone for Items<'a, T> { - fn clone(&self) -> Items<'a, T> { *self } + #[experimental = "needs review"] +impl<'a, T> Clone for Iter<'a, T> { + fn clone(&self) -> Iter<'a, T> { *self } } #[experimental = "needs review"] -impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> { +impl<'a, T> RandomAccessIterator<&'a T> for Iter<'a, T> { #[inline] fn indexable(&self) -> uint { let (exact, _) = self.size_hint(); @@ -813,14 +813,14 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> { /// Mutable slice iterator. #[experimental = "needs review"] -pub struct MutItems<'a, T: 'a> { +pub struct IterMut<'a, T: 'a> { ptr: *mut T, end: *mut T, marker: marker::ContravariantLifetime<'a>, } #[experimental] -impl<'a, T> ops::Slice for MutItems<'a, T> { +impl<'a, T> ops::Slice for IterMut<'a, T> { fn as_slice_<'b>(&'b self) -> &'b [T] { make_slice!(T -> &'b [T]: self.ptr, self.end) } @@ -839,7 +839,7 @@ impl<'a, T> ops::Slice for MutItems<'a, T> { } #[experimental] -impl<'a, T> ops::SliceMut for MutItems<'a, T> { +impl<'a, T> ops::SliceMut for IterMut<'a, T> { fn as_mut_slice_<'b>(&'b mut self) -> &'b mut [T] { make_slice!(T -> &'b mut [T]: self.ptr, self.end) } @@ -857,7 +857,7 @@ impl<'a, T> ops::SliceMut for MutItems<'a, T> { } } -impl<'a, T> MutItems<'a, T> { +impl<'a, T> IterMut<'a, T> { /// View the underlying data as a subslice of the original data. /// /// To avoid creating `&mut` references that alias, this is forced @@ -870,10 +870,10 @@ impl<'a, T> MutItems<'a, T> { } } -iterator!{struct MutItems -> *mut T, &'a mut T} +iterator!{struct IterMut -> *mut T, &'a mut T} #[experimental = "needs review"] -impl<'a, T> ExactSizeIterator<&'a mut T> for MutItems<'a, T> {} +impl<'a, T> ExactSizeIterator<&'a mut T> for IterMut<'a, T> {} /// An abstraction over the splitting iterators, so that splitn, splitn_mut etc /// can be implemented once. diff --git a/src/libcore/str.rs b/src/libcore/str.rs index a89a7970ae9..e147229bcbd 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -167,7 +167,7 @@ Section: Iterators /// Created with the method `.chars()`. #[deriving(Clone, Copy)] pub struct Chars<'a> { - iter: slice::Items<'a, u8> + iter: slice::Iter<'a, u8> } // Return the initial codepoint accumulator for the first byte. @@ -315,7 +315,7 @@ impl<'a> DoubleEndedIterator<(uint, char)> for CharOffsets<'a> { /// External iterator for a string's bytes. /// Use with the `std::iter` module. -pub type Bytes<'a> = Map<&'a u8, u8, slice::Items<'a, u8>, BytesFn>; +pub type Bytes<'a> = Map<&'a u8, u8, slice::Iter<'a, u8>, BytesFn>; /// A temporary new type wrapper that ensures that the `Bytes` iterator /// is cloneable. @@ -893,7 +893,7 @@ Section: Misc /// `iter` reset such that it is pointing at the first byte in the /// invalid sequence. #[inline(always)] -fn run_utf8_validation_iterator(iter: &mut slice::Items) -> bool { +fn run_utf8_validation_iterator(iter: &mut slice::Iter) -> bool { loop { // save the current thing we're pointing at. let old = *iter; @@ -993,7 +993,7 @@ pub fn is_utf16(v: &[u16]) -> bool { /// of `u16`s. #[deriving(Clone)] pub struct Utf16Items<'a> { - iter: slice::Items<'a, u16> + iter: slice::Iter<'a, u16> } /// The possibilities for values decoded from a `u16` stream. #[deriving(Copy, PartialEq, Eq, Clone, Show)] @@ -2366,4 +2366,3 @@ impl<'a> Default for &'a str { #[stable] fn default() -> &'a str { "" } } - diff --git a/src/libgraphviz/maybe_owned_vec.rs b/src/libgraphviz/maybe_owned_vec.rs index be8761043c0..88483b6c935 100644 --- a/src/libgraphviz/maybe_owned_vec.rs +++ b/src/libgraphviz/maybe_owned_vec.rs @@ -63,7 +63,7 @@ impl<'a,T> IntoMaybeOwnedVector<'a,T> for &'a [T] { } impl<'a,T> MaybeOwnedVector<'a,T> { - pub fn iter(&'a self) -> slice::Items<'a,T> { + pub fn iter(&'a self) -> slice::Iter<'a,T> { match self { &Growable(ref v) => v.as_slice().iter(), &Borrowed(ref v) => v.iter(), diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 2bf9af90271..bd11f38c143 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -370,7 +370,7 @@ pub fn mod_enabled(level: u32, module: &str) -> bool { fn enabled(level: u32, module: &str, - iter: slice::Items) + iter: slice::Iter) -> bool { // Search for the longest match, the vector is assumed to be pre-sorted. for directive in iter.rev() { diff --git a/src/libregex/re.rs b/src/libregex/re.rs index 151587e423a..5c84c0a55d6 100644 --- a/src/libregex/re.rs +++ b/src/libregex/re.rs @@ -540,8 +540,8 @@ impl Regex { } pub enum NamesIter<'a> { - NamesIterNative(::std::slice::Items<'a, Option<&'static str>>), - NamesIterDynamic(::std::slice::Items<'a, Option>) + NamesIterNative(::std::slice::Iter<'a, Option<&'static str>>), + NamesIterDynamic(::std::slice::Iter<'a, Option>) } impl<'a> Iterator> for NamesIter<'a> { diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 2ffc5d8a510..967e7f070c5 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -65,7 +65,7 @@ impl LanguageItems { } } - pub fn items<'a>(&'a self) -> Enumerate>> { + pub fn items<'a>(&'a self) -> Enumerate>> { self.items.iter().enumerate() } diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index 30a47ff9132..6098e0065e0 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -18,7 +18,7 @@ use middle::ty_fold::{mod, TypeFoldable, TypeFolder}; use util::ppaux::Repr; use std::fmt; -use std::slice::Items; +use std::slice::Iter; use std::vec::Vec; use syntax::codemap::{Span, DUMMY_SP}; @@ -400,7 +400,7 @@ impl VecPerParamSpace { &self.get_slice(space)[index] } - pub fn iter<'a>(&'a self) -> Items<'a,T> { + pub fn iter<'a>(&'a self) -> Iter<'a,T> { self.content.iter() } diff --git a/src/librustc/middle/traits/mod.rs b/src/librustc/middle/traits/mod.rs index 3289acd0c2e..8028971a463 100644 --- a/src/librustc/middle/traits/mod.rs +++ b/src/librustc/middle/traits/mod.rs @@ -19,7 +19,7 @@ use middle::subst; use middle::ty::{mod, Ty}; use middle::infer::InferCtxt; use std::rc::Rc; -use std::slice::Items; +use std::slice::Iter; use syntax::ast; use syntax::codemap::{Span, DUMMY_SP}; @@ -304,7 +304,7 @@ impl<'tcx> ObligationCause<'tcx> { } impl<'tcx, N> Vtable<'tcx, N> { - pub fn iter_nested(&self) -> Items { + pub fn iter_nested(&self) -> Iter { match *self { VtableImpl(ref i) => i.iter_nested(), VtableFnPointer(..) => (&[]).iter(), @@ -338,7 +338,7 @@ impl<'tcx, N> Vtable<'tcx, N> { } impl<'tcx, N> VtableImplData<'tcx, N> { - pub fn iter_nested(&self) -> Items { + pub fn iter_nested(&self) -> Iter { self.nested.iter() } @@ -365,7 +365,7 @@ impl<'tcx, N> VtableImplData<'tcx, N> { } impl VtableBuiltinData { - pub fn iter_nested(&self) -> Items { + pub fn iter_nested(&self) -> Iter { self.nested.iter() } diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index a95c9e19906..c8c7297f790 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -73,9 +73,9 @@ impl<'a> Iterator for LinkedPath<'a> { } } -// HACK(eddyb) move this into libstd (value wrapper for slice::Items). +// HACK(eddyb) move this into libstd (value wrapper for slice::Iter). #[deriving(Clone)] -pub struct Values<'a, T:'a>(pub slice::Items<'a, T>); +pub struct Values<'a, T:'a>(pub slice::Iter<'a, T>); impl<'a, T: Copy> Iterator for Values<'a, T> { fn next(&mut self) -> Option { diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index d8de3d2db97..2f06271d8de 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -766,7 +766,7 @@ impl<'a> MethodDef<'a> { let fields = if raw_fields.len() > 0 { let mut raw_fields = raw_fields.into_iter().map(|v| v.into_iter()); let first_field = raw_fields.next().unwrap(); - let mut other_fields: Vec, P)>> + let mut other_fields: Vec, P)>> = raw_fields.collect(); first_field.map(|(span, opt_id, field)| { FieldInfo { diff --git a/src/libsyntax/owned_slice.rs b/src/libsyntax/owned_slice.rs index 8e418e46921..3023c547fb0 100644 --- a/src/libsyntax/owned_slice.rs +++ b/src/libsyntax/owned_slice.rs @@ -45,7 +45,7 @@ impl OwnedSlice { &*self.data } - pub fn move_iter(self) -> vec::MoveItems { + pub fn move_iter(self) -> vec::IntoIter { self.into_vec().into_iter() } diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index 8d050e34abf..946181770c8 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. use self::SmallVectorRepr::*; -use self::MoveItemsRepr::*; +use self::IntoIterRepr::*; use std::mem; use std::slice; @@ -111,17 +111,17 @@ impl SmallVector { /// Deprecated: use `into_iter`. #[deprecated = "use into_iter"] - pub fn move_iter(self) -> MoveItems { + pub fn move_iter(self) -> IntoIter { self.into_iter() } - pub fn into_iter(self) -> MoveItems { + pub fn into_iter(self) -> IntoIter { let repr = match self.repr { Zero => ZeroIterator, One(v) => OneIterator(v), Many(vs) => ManyIterator(vs.into_iter()) }; - MoveItems { repr: repr } + IntoIter { repr: repr } } pub fn len(&self) -> uint { @@ -135,17 +135,17 @@ impl SmallVector { pub fn is_empty(&self) -> bool { self.len() == 0 } } -pub struct MoveItems { - repr: MoveItemsRepr, +pub struct IntoIter { + repr: IntoIterRepr, } -enum MoveItemsRepr { +enum IntoIterRepr { ZeroIterator, OneIterator(T), - ManyIterator(vec::MoveItems), + ManyIterator(vec::IntoIter), } -impl Iterator for MoveItems { +impl Iterator for IntoIter { fn next(&mut self) -> Option { match self.repr { ZeroIterator => None, diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 8521e2216e9..6aa6b02857f 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -130,7 +130,7 @@ struct Table { struct Items<'a> { cur: Option<&'a Entry>, - items: slice::Items<'a, Option>>, + items: slice::Iter<'a, Option>>, } impl Table { diff --git a/src/test/compile-fail/resolve-conflict-type-vs-import.rs b/src/test/compile-fail/resolve-conflict-type-vs-import.rs index fa072fa62ab..de934286a7c 100644 --- a/src/test/compile-fail/resolve-conflict-type-vs-import.rs +++ b/src/test/compile-fail/resolve-conflict-type-vs-import.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::slice::Items; -//~^ ERROR import `Items` conflicts with type in this module +use std::slice::Iter; +//~^ ERROR import `Iter` conflicts with type in this module -struct Items; +struct Iter; fn main() { } diff --git a/src/test/run-pass/issue-13167.rs b/src/test/run-pass/issue-13167.rs index be3ee0e0783..1282077028f 100644 --- a/src/test/run-pass/issue-13167.rs +++ b/src/test/run-pass/issue-13167.rs @@ -11,7 +11,7 @@ use std::slice; pub struct PhfMapEntries<'a, T: 'a> { - iter: slice::Items<'a, (&'static str, T)>, + iter: slice::Iter<'a, (&'static str, T)>, } impl<'a, T> Iterator<(&'static str, &'a T)> for PhfMapEntries<'a, T> { -- cgit 1.4.1-3-g733a5 From 7f6177e64627110e5b9776bd5304d65806081390 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 26 Nov 2014 05:52:16 -0500 Subject: Fix fallout from changes. In cases where stage0 compiler is needed, we cannot use an `as` expression to coerce, so I used a one-off function instead (this is a no-op in stage0, but in stage1+ it triggers coercion from the fn pointer to the fn item type). --- src/libcore/str.rs | 1 + src/librustdoc/html/markdown.rs | 20 +++++++------ src/libstd/path/windows.rs | 14 +++++++-- src/libstd/thread_local/mod.rs | 24 +++++++++++++++- src/libsyntax/ext/base.rs | 28 ++++++++++++------ src/test/compile-fail/borrowck-autoref-3261.rs | 2 +- src/test/compile-fail/cast-to-bare-fn.rs | 2 +- .../coerce-bare-fn-to-closure-and-proc.rs | 15 ++++++++-- src/test/compile-fail/issue-10764.rs | 2 +- src/test/compile-fail/issue-9575.rs | 2 +- .../compile-fail/regions-lifetime-bounds-on-fns.rs | 2 +- src/test/compile-fail/regions-nested-fns.rs | 4 +-- src/test/compile-fail/static-reference-to-fn-1.rs | 2 +- src/test/compile-fail/static-reference-to-fn-2.rs | 12 ++++---- src/test/pretty/issue-4264.pp | 33 +++++++++++----------- src/test/run-pass/const-extern-function.rs | 2 +- .../run-pass/extern-compare-with-return-type.rs | 12 ++++---- src/test/run-pass/issue-10767.rs | 2 +- src/test/run-pass/issue-15444.rs | 1 + 19 files changed, 120 insertions(+), 60 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libcore/str.rs b/src/libcore/str.rs index a89a7970ae9..1cd58aee061 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -30,6 +30,7 @@ use iter::range; use kinds::Sized; use mem; use num::Int; +use ops::FnMut; use option::Option; use option::Option::{None, Some}; use ops::{Fn, FnMut}; diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 8b2f644dfe3..009079bd214 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -65,17 +65,21 @@ const HOEDOWN_EXTENSIONS: libc::c_uint = type hoedown_document = libc::c_void; // this is opaque to us +type blockcodefn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer, + *const hoedown_buffer, *mut libc::c_void); + +type headerfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer, + libc::c_int, *mut libc::c_void); + #[repr(C)] struct hoedown_renderer { opaque: *mut hoedown_html_renderer_state, - blockcode: Option, + blockcode: Option, blockquote: Option, blockhtml: Option, - header: Option, + header: Option, other: [libc::size_t, ..28], } @@ -281,8 +285,8 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { toc_builder: if print_toc {Some(TocBuilder::new())} else {None} }; (*(*renderer).opaque).opaque = &mut opaque as *mut _ as *mut libc::c_void; - (*renderer).blockcode = Some(block); - (*renderer).header = Some(header); + (*renderer).blockcode = Some(block as blockcodefn); + (*renderer).header = Some(header as headerfn); let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16); hoedown_document_render(document, ob, s.as_ptr(), @@ -354,8 +358,8 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) { unsafe { let ob = hoedown_buffer_new(DEF_OUNIT); let renderer = hoedown_html_renderer_new(0, 0); - (*renderer).blockcode = Some(block); - (*renderer).header = Some(header); + (*renderer).blockcode = Some(block as blockcodefn); + (*renderer).header = Some(header as headerfn); (*(*renderer).opaque).opaque = tests as *mut _ as *mut libc::c_void; let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16); diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index c2c17103554..9e4a66e0e5e 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -829,8 +829,12 @@ impl Path { let s = if self.has_nonsemantic_trailing_slash() { self.repr.slice_to(self.repr.len()-1) } else { self.repr.as_slice() }; - let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep } - else { is_sep_verbatim }); + let sep_test: fn(char) -> bool = if !prefix_is_verbatim(self.prefix) { + is_sep + } else { + is_sep_verbatim + }; + let idx = s.rfind(sep_test); let prefixlen = self.prefix_len(); self.sepidx = idx.and_then(|x| if x < prefixlen { None } else { Some(x) }); } @@ -1048,7 +1052,11 @@ fn parse_prefix<'a>(mut path: &'a str) -> Option { // None result means the string didn't need normalizing fn normalize_helper<'a>(s: &'a str, prefix: Option) -> (bool, Option>) { - let f = if !prefix_is_verbatim(prefix) { is_sep } else { is_sep_verbatim }; + let f: fn(char) -> bool = if !prefix_is_verbatim(prefix) { + is_sep + } else { + is_sep_verbatim + }; let is_abs = s.len() > prefix_len(prefix) && f(s.char_at(prefix_len(prefix))); let s_ = s.slice_from(prefix_len(prefix)); let s_ = if is_abs { s_.slice_from(1) } else { s_ }; diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index 4c33d1c418d..04718dcc6ae 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -189,11 +189,12 @@ macro_rules! __thread_local_inner { } }; - #[cfg(not(any(target_os = "macos", target_os = "linux")))] + #[cfg(all(stage0, not(any(target_os = "macos", target_os = "linux"))))] const INIT: ::std::thread_local::KeyInner<$t> = { unsafe extern fn __destroy(ptr: *mut u8) { ::std::thread_local::destroy_value::<$t>(ptr); } + ::std::thread_local::KeyInner { inner: ::std::cell::UnsafeCell { value: $init }, os: ::std::thread_local::OsStaticKey { @@ -203,6 +204,21 @@ macro_rules! __thread_local_inner { } }; + #[cfg(all(not(stage0), not(any(target_os = "macos", target_os = "linux"))))] + const INIT: ::std::thread_local::KeyInner<$t> = { + unsafe extern fn __destroy(ptr: *mut u8) { + ::std::thread_local::destroy_value::<$t>(ptr); + } + + ::std::thread_local::KeyInner { + inner: ::std::cell::UnsafeCell { value: $init }, + os: ::std::thread_local::OsStaticKey { + inner: ::std::thread_local::OS_INIT_INNER, + dtor: ::std::option::Option::Some(__destroy as unsafe extern fn(*mut u8)), + }, + } + }; + INIT }); } @@ -323,6 +339,12 @@ mod imp { // *should* be the case that this loop always terminates because we // provide the guarantee that a TLS key cannot be set after it is // flagged for destruction. + #[cfg(not(stage0))] + static DTORS: os::StaticKey = os::StaticKey { + inner: os::INIT_INNER, + dtor: Some(run_dtors as unsafe extern "C" fn(*mut u8)), + }; + #[cfg(stage0)] static DTORS: os::StaticKey = os::StaticKey { inner: os::INIT_INNER, dtor: Some(run_dtors), diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index aefbb2a1fea..f76c350902d 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -50,14 +50,16 @@ pub trait ItemDecorator { push: |P|); } -impl ItemDecorator for fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, |P|) { +impl ItemDecorator for F + where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, &ast::Item, |P|) +{ fn expand(&self, ecx: &mut ExtCtxt, sp: Span, meta_item: &ast::MetaItem, item: &ast::Item, push: |P|) { - self.clone()(ecx, sp, meta_item, item, push) + (*self)(ecx, sp, meta_item, item, push) } } @@ -70,14 +72,16 @@ pub trait ItemModifier { -> P; } -impl ItemModifier for fn(&mut ExtCtxt, Span, &ast::MetaItem, P) -> P { +impl ItemModifier for F + where F : Fn(&mut ExtCtxt, Span, &ast::MetaItem, P) -> P +{ fn expand(&self, ecx: &mut ExtCtxt, span: Span, meta_item: &ast::MetaItem, item: P) -> P { - self.clone()(ecx, span, meta_item, item) + (*self)(ecx, span, meta_item, item) } } @@ -93,13 +97,15 @@ pub trait TTMacroExpander { pub type MacroExpanderFn = for<'cx> fn(&'cx mut ExtCtxt, Span, &[ast::TokenTree]) -> Box; -impl TTMacroExpander for MacroExpanderFn { +impl TTMacroExpander for F + where F : for<'cx> Fn(&'cx mut ExtCtxt, Span, &[ast::TokenTree]) -> Box +{ fn expand<'cx>(&self, ecx: &'cx mut ExtCtxt, span: Span, token_tree: &[ast::TokenTree]) -> Box { - self.clone()(ecx, span, token_tree) + (*self)(ecx, span, token_tree) } } @@ -115,14 +121,18 @@ pub trait IdentMacroExpander { pub type IdentMacroExpanderFn = for<'cx> fn(&'cx mut ExtCtxt, Span, ast::Ident, Vec) -> Box; -impl IdentMacroExpander for IdentMacroExpanderFn { +impl IdentMacroExpander for F + where F : for<'cx> Fn(&'cx mut ExtCtxt, Span, ast::Ident, + Vec) -> Box +{ fn expand<'cx>(&self, cx: &'cx mut ExtCtxt, sp: Span, ident: ast::Ident, token_tree: Vec ) - -> Box { - self.clone()(cx, sp, ident, token_tree) + -> Box + { + (*self)(cx, sp, ident, token_tree) } } diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index 8c6e76e7746..1b4e5891f94 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -20,7 +20,7 @@ impl X { } fn main() { - let mut x = X(Either::Right(main)); + let mut x = X(Either::Right(main as fn())); (&mut x).with( |opt| { //~ ERROR cannot borrow `x` as mutable more than once at a time match opt { diff --git a/src/test/compile-fail/cast-to-bare-fn.rs b/src/test/compile-fail/cast-to-bare-fn.rs index 10a829fd794..1db813292b0 100644 --- a/src/test/compile-fail/cast-to-bare-fn.rs +++ b/src/test/compile-fail/cast-to-bare-fn.rs @@ -13,7 +13,7 @@ fn foo(_x: int) { } fn main() { let v: u64 = 5; let x = foo as extern "C" fn() -> int; - //~^ ERROR non-scalar cast + //~^ ERROR mismatched types let y = v as extern "Rust" fn(int) -> (int, int); //~^ ERROR non-scalar cast y(x()); diff --git a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs b/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs index 27e339180a6..52f4c4749e2 100644 --- a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs +++ b/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs @@ -8,12 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// Test that coercions from fn item types are ok, but not fn pointer +// types to closures/procs are not allowed. + fn foo() {} -fn main() { +fn fn_item_type() { let f = foo; let f_closure: || = f; - //~^ ERROR: cannot coerce non-statically resolved bare fn to closure - //~^^ HELP: consider embedding the function in a closure } + +fn fn_pointer_type() { + let f = foo as fn(); + let f_closure: || = f; + //~^ ERROR: mismatched types +} + +fn main() { } diff --git a/src/test/compile-fail/issue-10764.rs b/src/test/compile-fail/issue-10764.rs index 0733744b652..cd4ec495556 100644 --- a/src/test/compile-fail/issue-10764.rs +++ b/src/test/compile-fail/issue-10764.rs @@ -12,4 +12,4 @@ fn f(_: extern "Rust" fn()) {} extern fn bar() {} fn main() { f(bar) } -//~^ ERROR: expected `fn()`, found `extern "C" fn()` +//~^ ERROR mismatched types diff --git a/src/test/compile-fail/issue-9575.rs b/src/test/compile-fail/issue-9575.rs index aa3d9d9fef0..6e8f7ffb68d 100644 --- a/src/test/compile-fail/issue-9575.rs +++ b/src/test/compile-fail/issue-9575.rs @@ -10,6 +10,6 @@ #[start] fn start(argc: int, argv: *const *const u8, crate_map: *const u8) -> int { - //~^ ERROR start function expects type: `fn(int, *const *const u8) -> int` + //~^ ERROR incorrect number of function parameters 0 } diff --git a/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs b/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs index 773d6e2c703..4a42728da6f 100644 --- a/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs +++ b/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs @@ -15,7 +15,7 @@ fn a<'a, 'b:'a>(x: &mut &'a int, y: &mut &'b int) { fn b<'a, 'b>(x: &mut &'a int, y: &mut &'b int) { // Illegal now because there is no `'b:'a` declaration. - *x = *y; //~ ERROR mismatched types + *x = *y; //~ ERROR cannot infer } fn c<'a,'b>(x: &mut &'a int, y: &mut &'b int) { diff --git a/src/test/compile-fail/regions-nested-fns.rs b/src/test/compile-fail/regions-nested-fns.rs index cf0b615bb01..f4654367970 100644 --- a/src/test/compile-fail/regions-nested-fns.rs +++ b/src/test/compile-fail/regions-nested-fns.rs @@ -12,10 +12,10 @@ fn ignore(t: T) {} fn nested<'x>(x: &'x int) { let y = 3; - let mut ay = &y; //~ ERROR cannot infer + let mut ay = &y; ignore::< for<'z>|&'z int|>(|z| { - ay = x; + ay = x; //~ ERROR cannot infer ay = &y; ay = z; }); diff --git a/src/test/compile-fail/static-reference-to-fn-1.rs b/src/test/compile-fail/static-reference-to-fn-1.rs index c0d430908a1..bce397c4793 100644 --- a/src/test/compile-fail/static-reference-to-fn-1.rs +++ b/src/test/compile-fail/static-reference-to-fn-1.rs @@ -24,7 +24,7 @@ fn foo() -> Option { fn create() -> A<'static> { A { - func: &foo, //~ ERROR borrowed value does not live long enough + func: &foo, //~ ERROR mismatched types } } diff --git a/src/test/compile-fail/static-reference-to-fn-2.rs b/src/test/compile-fail/static-reference-to-fn-2.rs index 3a0f0a193cf..d7255c3ba06 100644 --- a/src/test/compile-fail/static-reference-to-fn-2.rs +++ b/src/test/compile-fail/static-reference-to-fn-2.rs @@ -9,9 +9,11 @@ // except according to those terms. struct StateMachineIter<'a> { - statefn: &'a fn(&mut StateMachineIter<'a>) -> Option<&'static str> + statefn: &'a StateMachineFunc<'a> } +type StateMachineFunc<'a> = fn(&mut StateMachineIter<'a>) -> Option<&'static str>; + impl<'a> Iterator<&'static str> for StateMachineIter<'a> { fn next(&mut self) -> Option<&'static str> { return (*self.statefn)(self); @@ -19,19 +21,19 @@ impl<'a> Iterator<&'static str> for StateMachineIter<'a> { } fn state1(self_: &mut StateMachineIter) -> Option<&'static str> { - self_.statefn = &state2; + self_.statefn = &(state2 as StateMachineFunc); //~^ ERROR borrowed value does not live long enough return Some("state1"); } fn state2(self_: &mut StateMachineIter) -> Option<(&'static str)> { - self_.statefn = &state3; + self_.statefn = &(state3 as StateMachineFunc); //~^ ERROR borrowed value does not live long enough return Some("state2"); } fn state3(self_: &mut StateMachineIter) -> Option<(&'static str)> { - self_.statefn = &finished; + self_.statefn = &(finished as StateMachineFunc); //~^ ERROR borrowed value does not live long enough return Some("state3"); } @@ -42,7 +44,7 @@ fn finished(_: &mut StateMachineIter) -> Option<(&'static str)> { fn state_iter() -> StateMachineIter<'static> { StateMachineIter { - statefn: &state1 //~ ERROR borrowed value does not live long enough + statefn: &(state1 as StateMachineFunc) //~ ERROR borrowed value does not live long enough } } diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp index 974af1e6f3e..e4389cd69dd 100644 --- a/src/test/pretty/issue-4264.pp +++ b/src/test/pretty/issue-4264.pp @@ -50,20 +50,20 @@ pub fn bar() { ((::std::fmt::format as - fn(&core::fmt::Arguments<'_>) -> collections::string::String)((&((::std::fmt::Arguments::new - as - fn(&[&str], &[core::fmt::Argument<'_>]) -> core::fmt::Arguments<'_>)((__STATIC_FMTSTR - as - &'static [&'static str]), - (&([] - as - [core::fmt::Argument<'_>; 0]) - as - &[core::fmt::Argument<'_>; 0])) - as - core::fmt::Arguments<'_>) - as - &core::fmt::Arguments<'_>)) + fn(&core::fmt::Arguments<'_>) -> collections::string::String {std::fmt::format})((&((::std::fmt::Arguments::new + as + fn(&[&str], &[core::fmt::Argument<'_>]) -> core::fmt::Arguments<'_> {core::fmt::Arguments<'a>::new})((__STATIC_FMTSTR + as + &'static [&'static str]), + (&([] + as + [core::fmt::Argument<'_>; 0]) + as + &[core::fmt::Argument<'_>; 0])) + as + core::fmt::Arguments<'_>) + as + &core::fmt::Arguments<'_>)) as collections::string::String) } } as collections::string::String); @@ -78,7 +78,8 @@ pub fn id(x: T) -> T { (x as T) } pub fn use_id() { let _ = ((id::<[int; (3u as uint)]> as - fn([int; 3]) -> [int; 3])(([(1 as int), (2 as int), (3 as int)] - as [int; 3])) as [int; 3]); + fn([int; 3]) -> [int; 3] {id})(([(1 as int), (2 as int), + (3 as int)] as [int; 3])) as + [int; 3]); } fn main() { } diff --git a/src/test/run-pass/const-extern-function.rs b/src/test/run-pass/const-extern-function.rs index be7c47dafc0..069ca6ecf49 100644 --- a/src/test/run-pass/const-extern-function.rs +++ b/src/test/run-pass/const-extern-function.rs @@ -18,6 +18,6 @@ struct S { } pub fn main() { - assert!(foopy == f); + assert!(foopy as extern "C" fn() == f); assert!(f == s.f); } diff --git a/src/test/run-pass/extern-compare-with-return-type.rs b/src/test/run-pass/extern-compare-with-return-type.rs index 057394b2624..3febff18704 100644 --- a/src/test/run-pass/extern-compare-with-return-type.rs +++ b/src/test/run-pass/extern-compare-with-return-type.rs @@ -18,15 +18,17 @@ extern fn uintret() -> uint { 22 } extern fn uintvoidret(_x: uint) {} extern fn uintuintuintuintret(x: uint, y: uint, z: uint) -> uint { x+y+z } +type uintuintuintuintret = extern fn(uint,uint,uint) -> uint; pub fn main() { - assert!(voidret1 == voidret1); - assert!(voidret1 != voidret2); + assert!(voidret1 as extern fn() == voidret1 as extern fn()); + assert!(voidret1 as extern fn() != voidret2 as extern fn()); - assert!(uintret == uintret); + assert!(uintret as extern fn() -> uint == uintret as extern fn() -> uint); - assert!(uintvoidret == uintvoidret); + assert!(uintvoidret as extern fn(uint) == uintvoidret as extern fn(uint)); - assert!(uintuintuintuintret == uintuintuintuintret); + assert!(uintuintuintuintret as uintuintuintuintret == + uintuintuintuintret as uintuintuintuintret); } diff --git a/src/test/run-pass/issue-10767.rs b/src/test/run-pass/issue-10767.rs index a30eb8120ea..d2895024187 100644 --- a/src/test/run-pass/issue-10767.rs +++ b/src/test/run-pass/issue-10767.rs @@ -12,5 +12,5 @@ pub fn main() { fn f() { }; - let _: Box = box f; + let _: Box = box() (f as fn()); } diff --git a/src/test/run-pass/issue-15444.rs b/src/test/run-pass/issue-15444.rs index f5618c2c7a3..0f4978d78dd 100644 --- a/src/test/run-pass/issue-15444.rs +++ b/src/test/run-pass/issue-15444.rs @@ -25,5 +25,6 @@ fn thing(a: int, b: int) -> int { } fn main() { + let thing: fn(int, int) -> int = thing; // coerce to fn type bar(&thing); } -- cgit 1.4.1-3-g733a5