diff -Nru rust-synstructure-0.9.0/Cargo.toml rust-synstructure-0.10.1/Cargo.toml --- rust-synstructure-0.9.0/Cargo.toml 1970-01-01 00:00:00.000000000 +0000 +++ rust-synstructure-0.10.1/Cargo.toml 1970-01-01 00:00:00.000000000 +0000 @@ -12,7 +12,7 @@ [package] name = "synstructure" -version = "0.9.0" +version = "0.10.1" authors = ["Nika Layzell "] include = ["src/**/*", "Cargo.toml", "README.md", "LICENSE"] description = "Helper methods and macros for custom derives" @@ -28,7 +28,7 @@ version = "0.6" [dependencies.syn] -version = "0.14" +version = "0.15" features = ["visit", "extra-traits"] [dependencies.unicode-xid] diff -Nru rust-synstructure-0.9.0/Cargo.toml.orig rust-synstructure-0.10.1/Cargo.toml.orig --- rust-synstructure-0.9.0/Cargo.toml.orig 2018-06-04 18:07:09.000000000 +0000 +++ rust-synstructure-0.10.1/Cargo.toml.orig 2018-10-28 03:47:44.000000000 +0000 @@ -1,6 +1,6 @@ [package] name = "synstructure" -version = "0.9.0" +version = "0.10.1" authors = ["Nika Layzell "] description = "Helper methods and macros for custom derives" @@ -16,7 +16,7 @@ simple-derive = [] [dependencies] -syn = { version = "0.14", features = ["visit", "extra-traits"] } +syn = { version = "0.15", features = ["visit", "extra-traits"] } proc-macro2 = "0.4" quote = "0.6" unicode-xid = "0.1" diff -Nru rust-synstructure-0.9.0/.cargo_vcs_info.json rust-synstructure-0.10.1/.cargo_vcs_info.json --- rust-synstructure-0.9.0/.cargo_vcs_info.json 1970-01-01 00:00:00.000000000 +0000 +++ rust-synstructure-0.10.1/.cargo_vcs_info.json 1970-01-01 00:00:00.000000000 +0000 @@ -0,0 +1,5 @@ +{ + "git": { + "sha1": "7b2f07739ce9971b0c5fbdb253e48d446ab58585" + } +} diff -Nru rust-synstructure-0.9.0/debian/cargo-checksum.json rust-synstructure-0.10.1/debian/cargo-checksum.json --- rust-synstructure-0.9.0/debian/cargo-checksum.json 2018-08-03 13:43:07.000000000 +0000 +++ rust-synstructure-0.10.1/debian/cargo-checksum.json 2018-11-15 04:27:48.000000000 +0000 @@ -1 +1 @@ -{"package":"85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7","files":{}} +{"package":"73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015","files":{}} diff -Nru rust-synstructure-0.9.0/debian/changelog rust-synstructure-0.10.1/debian/changelog --- rust-synstructure-0.9.0/debian/changelog 2018-08-03 13:43:07.000000000 +0000 +++ rust-synstructure-0.10.1/debian/changelog 2018-11-15 04:27:48.000000000 +0000 @@ -1,3 +1,10 @@ +rust-synstructure (0.10.1-1) unstable; urgency=medium + + * Team upload. + * Package synstructure 0.10.1 from crates.io using debcargo 2.2.8 + + -- Wolfgang Silbermayr Wed, 14 Nov 2018 20:27:48 -0800 + rust-synstructure (0.9.0-1) unstable; urgency=medium * Package synstructure 0.9.0 from crates.io using debcargo 2.2.5 diff -Nru rust-synstructure-0.9.0/debian/control rust-synstructure-0.10.1/debian/control --- rust-synstructure-0.9.0/debian/control 2018-08-03 13:43:07.000000000 +0000 +++ rust-synstructure-0.10.1/debian/control 2018-11-15 04:27:48.000000000 +0000 @@ -2,19 +2,20 @@ Section: rust Priority: optional Build-Depends: debhelper (>= 11), - dh-cargo (>= 6), + dh-cargo (>= 10), cargo:native , rustc:native , libstd-rust-dev , librust-proc-macro2-0.4+default-dev , librust-quote-0.6+default-dev , - librust-syn-0.14+default-dev , - librust-syn-0.14+extra-traits-dev , - librust-syn-0.14+visit-dev , + librust-syn-0.15+default-dev , + librust-syn-0.15+extra-traits-dev , + librust-syn-0.15+visit-dev , librust-unicode-xid-0.1+default-dev Maintainer: Debian Rust Maintainers -Uploaders: Ximin Luo -Standards-Version: 4.1.5 +Uploaders: + Ximin Luo +Standards-Version: 4.2.0 Vcs-Git: https://salsa.debian.org/rust-team/debcargo-conf.git [src/synstructure] Vcs-Browser: https://salsa.debian.org/rust-team/debcargo-conf/tree/master/src/synstructure @@ -25,9 +26,9 @@ ${misc:Depends}, librust-proc-macro2-0.4+default-dev, librust-quote-0.6+default-dev, - librust-syn-0.14+default-dev, - librust-syn-0.14+extra-traits-dev, - librust-syn-0.14+visit-dev, + librust-syn-0.15+default-dev, + librust-syn-0.15+extra-traits-dev, + librust-syn-0.15+visit-dev, librust-unicode-xid-0.1+default-dev Provides: librust-synstructure+default-dev (= ${binary:Version}), @@ -35,12 +36,12 @@ librust-synstructure-0-dev (= ${binary:Version}), librust-synstructure-0+default-dev (= ${binary:Version}), librust-synstructure-0+simple-derive-dev (= ${binary:Version}), - librust-synstructure-0.9-dev (= ${binary:Version}), - librust-synstructure-0.9+default-dev (= ${binary:Version}), - librust-synstructure-0.9+simple-derive-dev (= ${binary:Version}), - librust-synstructure-0.9.0-dev (= ${binary:Version}), - librust-synstructure-0.9.0+default-dev (= ${binary:Version}), - librust-synstructure-0.9.0+simple-derive-dev (= ${binary:Version}) + librust-synstructure-0.10-dev (= ${binary:Version}), + librust-synstructure-0.10+default-dev (= ${binary:Version}), + librust-synstructure-0.10+simple-derive-dev (= ${binary:Version}), + librust-synstructure-0.10.1-dev (= ${binary:Version}), + librust-synstructure-0.10.1+default-dev (= ${binary:Version}), + librust-synstructure-0.10.1+simple-derive-dev (= ${binary:Version}) Description: Helper methods and macros for custom derives - Rust source code This package contains the source for the Rust synstructure crate, packaged by debcargo for use with cargo and dh-cargo. diff -Nru rust-synstructure-0.9.0/debian/copyright.debcargo.hint rust-synstructure-0.10.1/debian/copyright.debcargo.hint --- rust-synstructure-0.9.0/debian/copyright.debcargo.hint 2018-08-03 13:43:07.000000000 +0000 +++ rust-synstructure-0.10.1/debian/copyright.debcargo.hint 2018-11-15 04:27:48.000000000 +0000 @@ -22,7 +22,7 @@ Files: debian/* Copyright: 2018 Debian Rust Maintainers - 2018 FIXME (overlay) Your Name + 2018 Ximin Luo License: MIT License: MIT diff -Nru rust-synstructure-0.9.0/debian/debcargo.toml rust-synstructure-0.10.1/debian/debcargo.toml --- rust-synstructure-0.9.0/debian/debcargo.toml 2018-08-03 13:43:07.000000000 +0000 +++ rust-synstructure-0.10.1/debian/debcargo.toml 2018-11-15 04:27:48.000000000 +0000 @@ -1 +1,2 @@ overlay = "." +uploaders = ["Ximin Luo "] diff -Nru rust-synstructure-0.9.0/debian/watch rust-synstructure-0.10.1/debian/watch --- rust-synstructure-0.9.0/debian/watch 2018-08-03 13:43:07.000000000 +0000 +++ rust-synstructure-0.10.1/debian/watch 2018-11-15 04:27:48.000000000 +0000 @@ -1,4 +1,5 @@ version=4 -opts=filenamemangle=s/.*\/(.*)\/download/synstructure-$1\.tar\.gz/g\ - https://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=crates.io/synstructure .*/crates/synstructure/@ANY_VERSION@/download +opts=filenamemangle=s/.*\/(.*)\/download/synstructure-$1\.tar\.gz/g,\ +uversionmangle=s/(\d)[_\.\-\+]?((RC|rc|pre|dev|beta|alpha)\d*)$/$1~$2/ \ +https://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=crates.io/synstructure .*/crates/synstructure/@ANY_VERSION@/download diff -Nru rust-synstructure-0.9.0/src/lib.rs rust-synstructure-0.10.1/src/lib.rs --- rust-synstructure-0.9.0/src/lib.rs 2018-06-04 18:07:09.000000000 +0000 +++ rust-synstructure-0.10.1/src/lib.rs 2018-10-28 03:54:40.000000000 +0000 @@ -181,7 +181,7 @@ // implementations. #[doc(hidden)] pub use quote::*; -use proc_macro2::TokenStream; +use proc_macro2::{TokenStream, TokenTree}; use unicode_xid::UnicodeXID; @@ -193,6 +193,21 @@ #[doc(hidden)] pub mod macros; +/// Changes how bounds are added +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum AddBounds { + /// Add for fields and generics + Both, + /// Fields only + Fields, + /// Generics only + Generics, + /// None + None, + #[doc(hidden)] + __Nonexhaustive, +} + /// The type of binding to use when generating a pattern. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum BindStyle { @@ -541,7 +556,7 @@ /// # } /// ``` pub fn pat(&self) -> TokenStream { - let mut t = TokenStream::empty(); + let mut t = TokenStream::new(); if let Some(prefix) = self.prefix { prefix.to_tokens(&mut t); quote!(::).to_tokens(&mut t); @@ -621,7 +636,7 @@ F: FnMut(&Field, usize) -> T, T: ToTokens, { - let mut t = TokenStream::empty(); + let mut t = TokenStream::new(); if let Some(prefix) = self.prefix { quote!(#prefix ::).to_tokens(&mut t); } @@ -690,7 +705,7 @@ R: ToTokens, { let pat = self.pat(); - let mut body = TokenStream::empty(); + let mut body = TokenStream::new(); for binding in &self.bindings { token::Brace::default().surround(&mut body, |body| { f(binding).to_tokens(body); @@ -956,6 +971,7 @@ omitted_variants: bool, ast: &'a DeriveInput, extra_impl: Vec, + add_bounds: AddBounds, } impl<'a> Structure<'a> { @@ -1013,6 +1029,7 @@ omitted_variants: false, ast: ast, extra_impl: vec![], + add_bounds: AddBounds::Both, } } @@ -1078,7 +1095,7 @@ F: FnMut(&BindingInfo) -> R, R: ToTokens, { - let mut t = TokenStream::empty(); + let mut t = TokenStream::new(); for variant in &self.variants { variant.each(&mut f).to_tokens(&mut t); } @@ -1132,7 +1149,7 @@ I: ToTokens, R: ToTokens, { - let mut t = TokenStream::empty(); + let mut t = TokenStream::new(); for variant in &self.variants { variant.fold(&init, &mut f).to_tokens(&mut t); } @@ -1186,7 +1203,7 @@ F: FnMut(&VariantInfo) -> R, R: ToTokens, { - let mut t = TokenStream::empty(); + let mut t = TokenStream::new(); for variant in &self.variants { let pat = variant.pat(); let body = f(variant); @@ -1251,6 +1268,54 @@ self } + /// Specify which bounds should be generated by impl-generating functions + /// such as `gen_impl`, `bound_impl`, and `unsafe_bound_impl`. + /// + /// The default behaviour is to generate both field and generic bounds from + /// type parameters. + /// + /// # Example + /// ``` + /// # #[macro_use] extern crate quote; + /// # extern crate synstructure; + /// # #[macro_use] extern crate syn; + /// # use synstructure::*; + /// # fn main() { + /// let di: syn::DeriveInput = parse_quote! { + /// enum A { + /// B(T), + /// C(Option), + /// } + /// }; + /// let mut s = Structure::new(&di); + /// + /// // Limit bounds to only generics. + /// s.add_bounds(AddBounds::Generics); + /// + /// assert_eq!( + /// s.bound_impl(quote!(krate::Trait), quote!{ + /// fn a() {} + /// }).to_string(), + /// quote!{ + /// #[allow(non_upper_case_globals)] + /// const _DERIVE_krate_Trait_FOR_A: () = { + /// extern crate krate; + /// impl krate::Trait for A + /// where T: krate::Trait, + /// U: krate::Trait + /// { + /// fn a() {} + /// } + /// }; + /// }.to_string() + /// ); + /// # } + /// ``` + pub fn add_bounds(&mut self, mode: AddBounds) -> &mut Self { + self.add_bounds = mode; + self + } + /// Filter the variants matched by this `Structure` object. This has 2 effects: /// /// * Match arms destructuring these variants will no longer be generated by @@ -1508,7 +1573,12 @@ /// If the method contains any macros in type position, all parameters will /// be considered bound. This is because we cannot determine which type /// parameters are bound by type macros. - pub fn add_trait_bounds(&self, bound: &TraitBound, where_clause: &mut Option) { + pub fn add_trait_bounds( + &self, + bound: &TraitBound, + where_clause: &mut Option, + mode: AddBounds, + ) { let mut seen = HashSet::new(); let mut pred = |ty: Type| if !seen.contains(&ty) { seen.insert(ty.clone()); @@ -1537,18 +1607,28 @@ for variant in &self.variants { for binding in &variant.bindings { - for &seen in &binding.seen_generics { - if seen { - pred(binding.ast().ty.clone()); - break; + match mode { + AddBounds::Both | AddBounds::Fields => { + for &seen in &binding.seen_generics { + if seen { + pred(binding.ast().ty.clone()); + break; + } + } } + _ => {} } - for param in binding.referenced_ty_params() { - pred(Type::Path(TypePath { - qself: None, - path: (*param).clone().into(), - })); + match mode { + AddBounds::Both | AddBounds::Generics => { + for param in binding.referenced_ty_params() { + pred(Type::Path(TypePath { + qself: None, + path: (*param).clone().into(), + })); + } + } + _ => {} } } } @@ -1624,7 +1704,7 @@ path.into_token_stream(), body.into_token_stream(), quote!(), - true, + None, ) } @@ -1698,7 +1778,7 @@ path.into_token_stream(), body.into_token_stream(), quote!(unsafe), - true, + None, ) } @@ -1762,7 +1842,7 @@ path.into_token_stream(), body.into_token_stream(), quote!(), - false, + Some(AddBounds::None), ) } @@ -1827,7 +1907,7 @@ path.into_token_stream(), body.into_token_stream(), quote!(unsafe), - false, + Some(AddBounds::None), ) } @@ -1836,8 +1916,9 @@ path: TokenStream, body: TokenStream, safety: TokenStream, - add_bounds: bool, + mode: Option, ) -> TokenStream { + let mode = mode.unwrap_or(self.add_bounds); let name = &self.ast.ident; let mut gen_clone = self.ast.generics.clone(); gen_clone.params.extend(self.extra_impl.clone().into_iter()); @@ -1848,9 +1929,7 @@ .expect("`path` argument must be a valid rust trait bound"); let mut where_clause = where_clause.cloned(); - if add_bounds { - self.add_trait_bounds(&bound, &mut where_clause); - } + self.add_trait_bounds(&bound, &mut where_clause, mode); let dummy_const: Ident = sanitize_ident(&format!( "_DERIVE_{}_FOR_{}", @@ -2046,116 +2125,84 @@ /// ); /// # } /// ``` + /// + /// Use `add_bounds` to change which bounds are generated. pub fn gen_impl(&self, cfg: TokenStream) -> TokenStream { - use syn::buffer::{TokenBuffer, Cursor}; - use syn::synom::PResult; - use proc_macro2::TokenStream; - - /* Parsing Logic */ - fn parse_gen_impl( - c: Cursor, - ) -> PResult< - ( - Option, - TraitBound, - TokenStream, - syn::Generics, - ), - > { - // `gen` - let (id, c) = syn!(c, Ident)?; - if id != "gen" { - let ((), _) = reject!(c,)?; - unreachable!() - } + use syn::parse::{Parser, ParseStream, Result}; + + // Syn requires parsers to be methods conforming to a strict signature + let do_parse = |input: ParseStream| -> Result { + // Helper lambda to parse the prefix of a gen block. + let parse_prefix = |input: ParseStream| -> Result<_> { + if input.parse::()? != "gen" { + return Err(input.error("")); + } + let safety = input.parse::>()?; + let _ = input.parse::()?; + Ok(safety) + }; - // `impl` or unsafe impl` - let (unsafe_kw, c) = option!(c, keyword!(unsafe))?; - let (_, c) = syn!(c, token::Impl)?; + let mut before = vec![]; + loop { + if let Ok(_) = parse_prefix(&input.fork()) { + break; + } + before.push(input.parse::()?); + } - // NOTE: After this point we assume they meant to write a gen impl, - // so we panic if we run into an error. + // Parse the prefix "for real" + let safety = parse_prefix(input)?; // optional `<>` - let (mut generics, c) = syn!(c, Generics) - .expect("Expected an optional `<>` with generics after `gen impl`"); + let mut generics = input.parse::()?; // @bound - let (bound, c) = syn!(c, TraitBound) - .expect("Expected a trait bound after `gen impl`"); + let bound = input.parse::()?; // `for @Self` - let (_, c) = keyword!(c, for) - .expect("Expected `for` after trait bound"); - let (_, c) = do_parse!(c, syn!(Token![@]) >> keyword!(Self) >> (())) - .expect("Expected `@Self` after `for`"); + let _ = input.parse::()?; + let _ = input.parse::()?; + let _ = input.parse::()?; // optional `where ...` - // XXX: We have to do this awkward if let because option!() doesn't - // provide enough type information to call expect(). - let c = if let Ok((where_clause, c)) = syn!(c, WhereClause) { - generics.where_clause = Some(where_clause); - c - } else { c }; - - let ((_, body), c) = braces!(c, syn!(TokenStream)) - .expect("Expected an impl body after `@Self`"); - - Ok(((unsafe_kw, bound, body, generics), c)) - } - - let buf = TokenBuffer::new2(cfg.into()); - let mut c = buf.begin(); - let mut before = vec![]; - - // Use uninitialized variables here to avoid using the "break with value" - // language feature, which requires Rust 1.19+. - let ((unsafe_kw, bound, body, mut generics), after) = { - let gen_impl; - let cursor; + generics.where_clause = input.parse()?; - loop { - if let Ok((gi, c2)) = parse_gen_impl(c) { - gen_impl = gi; - cursor = c2; - break; - } else if let Some((tt, c2)) = c.token_tree() { - c = c2; - before.push(tt); - } else { - panic!("Expected a gen impl block"); - } - } - - (gen_impl, cursor.token_stream()) + // Body of the impl + let body; + braced!(body in input); + let body = body.parse::()?; + + // Tokens following impl + let after = input.parse::()?; + + /* Codegen Logic */ + let name = &self.ast.ident; + + // Add the generics from the original struct in, and then add any + // additional trait bounds which we need on the type. + merge_generics(&mut generics, &self.ast.generics); + self.add_trait_bounds(&bound, &mut generics.where_clause, self.add_bounds); + let (impl_generics, _, where_clause) = generics.split_for_impl(); + let (_, ty_generics, _) = self.ast.generics.split_for_impl(); + + let dummy_const: Ident = sanitize_ident(&format!( + "_DERIVE_{}_FOR_{}", + (&bound).into_token_stream(), + name.into_token_stream(), + )); + + Ok(quote! { + #[allow(non_upper_case_globals)] + const #dummy_const: () = { + #(#before)* + #safety impl #impl_generics #bound for #name #ty_generics #where_clause { + #body + } + #after + }; + }) }; - - /* Codegen Logic */ - let name = &self.ast.ident; - - // Add the generics from the original struct in, and then add any - // additional trait bounds which we need on the type. - merge_generics(&mut generics, &self.ast.generics); - self.add_trait_bounds(&bound, &mut generics.where_clause); - let (impl_generics, _, where_clause) = generics.split_for_impl(); - let (_, ty_generics, _) = self.ast.generics.split_for_impl(); - - let dummy_const: Ident = sanitize_ident(&format!( - "_DERIVE_{}_FOR_{}", - (&bound).into_token_stream(), - name.into_token_stream(), - )); - - quote! { - #[allow(non_upper_case_globals)] - const #dummy_const: () = { - #(#before)* - #unsafe_kw impl #impl_generics #bound for #name #ty_generics #where_clause { - #body - } - #after - }; - } + Parser::parse2(do_parse, cfg).expect("Failed to parse gen_impl") } } diff -Nru rust-synstructure-0.9.0/src/macros.rs rust-synstructure-0.10.1/src/macros.rs --- rust-synstructure-0.9.0/src/macros.rs 2018-06-04 18:07:09.000000000 +0000 +++ rust-synstructure-0.10.1/src/macros.rs 2018-10-28 03:42:09.000000000 +0000 @@ -172,7 +172,7 @@ /// # Note /// /// This feature is implemented behind the `simple-derive` feature, and is only -/// avaliable when that feature is enabled. +/// available when that feature is enabled. /// /// # Example ///