diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-12-18 22:52:48 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-12-22 00:14:56 -0800 |
| commit | a76a80276852f05f30adaa4d2a8a2729b5fc0bfa (patch) | |
| tree | 118a535c640013b22519f38dfa9af893dc5986a4 /src/libsyntax/ext | |
| parent | 34d680009205de2302b902d8f9f5f7ae7a042f1a (diff) | |
| download | rust-a76a80276852f05f30adaa4d2a8a2729b5fc0bfa.tar.gz rust-a76a80276852f05f30adaa4d2a8a2729b5fc0bfa.zip | |
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]
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/deriving/decodable.rs | 32 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/encodable.rs | 25 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/mod.rs | 18 | ||||
| -rw-r--r-- | src/libsyntax/ext/mtwt.rs | 2 |
4 files changed, 59 insertions, 18 deletions
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,6 +21,16 @@ use parse::token::InternedString; use parse::token; use ptr::P; +pub fn expand_deriving_rustc_decodable<F>(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P<Item>), +{ + expand_deriving_decodable_imp(cx, span, mitem, item, push, "rustc_serialize") +} + pub fn expand_deriving_decodable<F>(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, @@ -28,17 +38,28 @@ pub fn expand_deriving_decodable<F>(cx: &mut ExtCtxt, push: F) where F: FnOnce(P<Item>), { + expand_deriving_decodable_imp(cx, span, mitem, item, push, "serialize") +} + +fn expand_deriving_decodable_imp<F>(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F, + krate: &'static str) where + F: FnOnce(P<Item>), +{ 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<F>(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<F>(cx: &mut ExtCtxt, } fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span, - substr: &Substructure) -> P<Expr> { + substr: &Substructure, + krate: &str) -> P<Expr> { 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,6 +97,16 @@ use ext::deriving::generic::ty::*; use parse::token; use ptr::P; +pub fn expand_deriving_rustc_encodable<F>(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F) where + F: FnOnce(P<Item>), +{ + expand_deriving_encodable_imp(cx, span, mitem, item, push, "rustc_serialize") +} + pub fn expand_deriving_encodable<F>(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, @@ -104,17 +114,28 @@ pub fn expand_deriving_encodable<F>(cx: &mut ExtCtxt, push: F) where F: FnOnce(P<Item>), { + expand_deriving_encodable_imp(cx, span, mitem, item, push, "serialize") +} + +fn expand_deriving_encodable_imp<F>(cx: &mut ExtCtxt, + span: Span, + mitem: &MetaItem, + item: &Item, + push: F, + krate: &'static str) where + F: FnOnce(P<Item>), +{ 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<HashMap<(SyntaxContext,Ident,Name),SyntaxContext>>, } -#[deriving(Copy, PartialEq, Encodable, Decodable, Hash, Show)] +#[deriving(PartialEq, RustcEncodable, RustcDecodable, Hash, Show, Copy)] pub enum SyntaxContext_ { EmptyCtxt, Mark (Mrk,SyntaxContext), |
