error: redundant closure
--> serde_derive/src/bound.rs:53:19
|
53 | .flat_map(|predicates| predicates.to_vec());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `[T]::to_vec`
|
note: the lint level is defined here
--> serde_derive/src/lib.rs:18:22
|
18 | #![deny(clippy::all, clippy::pedantic)]
| ^^^^^^^^^^^^^^^^
= note: `#[deny(clippy::redundant_closure_for_method_calls)]` implied by `#[deny(clippy::pedantic)]`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
error: redundant closure
--> serde_derive/src/bound.rs:75:19
|
75 | .flat_map(|predicates| predicates.to_vec());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `[T]::to_vec`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
error: this expression borrows a reference (`&syn::Type`) that is immediately dereferenced by the compiler
--> serde_derive/src/internals/check.rs:399:37
|
399 | if let Type::Path(ty) = ungroup(&field.ty) {
| ^^^^^^^^^ help: change this to: `field.ty`
|
note: the lint level is defined here
--> serde_derive/src/lib.rs:18:9
|
18 | #![deny(clippy::all, clippy::pedantic)]
| ^^^^^^^^^^^
= note: `#[deny(clippy::needless_borrow)]` implied by `#[deny(clippy::all)]`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
error: this expression borrows a reference (`&str`) that is immediately dereferenced by the compiler
--> serde_derive/src/de.rs:478:52
|
478 | &type_path, params, fields, false, cattrs, &expecting,
| ^^^^^^^^^^ help: change this to: `expecting`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
error: this expression borrows a reference (`&str`) that is immediately dereferenced by the compiler
--> serde_derive/src/de.rs:564:76
|
564 | let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, &expecting));
| ^^^^^^^^^^ help: change this to: `expecting`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
error: this expression borrows a reference (`&str`) that is immediately dereferenced by the compiler
--> serde_derive/src/de.rs:925:51
|
925 | &type_path, params, fields, true, cattrs, &expecting,
| ^^^^^^^^^^ help: change this to: `expecting`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
error: this expression borrows a reference (`&str`) that is immediately dereferenced by the compiler
--> serde_derive/src/de.rs:1066:76
|
1066 | let visit_seq = Stmts(deserialize_seq_in_place(params, fields, cattrs, &expecting));
| ^^^^^^^^^^ help: change this to: `expecting`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
error: this expression borrows a reference (`&proc_macro2::TokenStream`) that is immediately dereferenced by the compiler
--> serde_derive/src/de.rs:2288:80
|
2288 | let fallthrough_borrowed_arm = fallthrough_borrowed.as_ref().unwrap_or(&fallthrough_arm);
| ^^^^^^^^^^^^^^^^ help: change this to: `fallthrough_arm`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
error: this expression borrows a reference (`&syn::Member`) that is immediately dereferenced by the compiler
--> serde_derive/src/ser.rs:1102:43
|
1102 | get_member(params, field, &member)
| ^^^^^^^ help: change this to: `member`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
error: consider adding a `;` to the last statement for consistent formatting
--> serde_derive/src/internals/attr.rs:559:25
|
559 | serde_path.set(&m.path, path)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `serde_path.set(&m.path, path);`
|
note: the lint level is defined here
--> serde_derive/src/lib.rs:18:22
|
18 | #![deny(clippy::all, clippy::pedantic)]
| ^^^^^^^^^^^^^^^^
= note: `#[deny(clippy::semicolon_if_nothing_returned)]` implied by `#[deny(clippy::pedantic)]`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
error: consider adding a `;` to the last statement for consistent formatting
--> serde_derive/src/internals/attr.rs:1612:9
|
1612 | cx.error_spanned_by(lit, format!("failed to parse path: {:?}", string.value()))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `cx.error_spanned_by(lit, format!("failed to parse path: {:?}", string.value()));`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
error: consider adding a `;` to the last statement for consistent formatting
--> serde_derive/src/internals/attr.rs:1623:9
|
1623 | cx.error_spanned_by(lit, format!("failed to parse path: {:?}", string.value()))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `cx.error_spanned_by(lit, format!("failed to parse path: {:?}", string.value()));`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
error: consider adding a `;` to the last statement for consistent formatting
--> serde_derive/src/internals/attr.rs:1649:9
|
1649 | / cx.error_spanned_by(
1650 | | lit,
1651 | | format!("failed to parse type: {} = {:?}", attr_name, string.value()),
1652 | | )
| |_________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
help: add a `;` here
|
1649 | cx.error_spanned_by(
1650 | lit,
1651 | format!("failed to parse type: {} = {:?}", attr_name, string.value()),
1652 | );
|
error: consider adding a `;` to the last statement for consistent formatting
--> serde_derive/src/internals/check.rs:260:9
|
260 | / cx.error_spanned_by(
261 | | cont.original,
262 | | format!("variant field name `{}` conflicts with internal tag", tag),
263 | | )
| |_________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
help: add a `;` here
|
260 | cx.error_spanned_by(
261 | cont.original,
262 | format!("variant field name `{}` conflicts with internal tag", tag),
263 | );
|
error: consider adding a `;` to the last statement for consistent formatting
--> serde_derive/src/de.rs:2090:9
|
2090 | flat_fields.extend(aliases.iter().map(|alias| (alias, ident)))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `flat_fields.extend(aliases.iter().map(|alias| (alias, ident)));`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
warning: lint `clippy::filter_map` has been removed: this lint has been replaced by `manual_filter_map`, a more specific lint
--> serde_derive/src/lib.rs:42:5
|
42 | clippy::filter_map,
| ^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(renamed_and_removed_lints)]` on by default
warning: lint `clippy::filter_map` has been removed: this lint has been replaced by `manual_filter_map`, a more specific lint
--> serde_derive/src/lib.rs:42:5
|
42 | clippy::filter_map,
| ^^^^^^^^^^^^^^^^^^
error: used `flat_map` where `filter_map` could be used instead
--> serde_derive/src/bound.rs:52:10
|
52 | .flat_map(|field| from_field(&field.attrs))
| ^^^^^^^^ help: try: `filter_map`
|
note: the lint level is defined here
--> serde_derive/src/lib.rs:18:22
|
18 | #![deny(clippy::all, clippy::pedantic)]
| ^^^^^^^^^^^^^^^^
= note: `#[deny(clippy::flat_map_option)]` implied by `#[deny(clippy::pedantic)]`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#flat_map_option
error: used `flat_map` where `filter_map` could be used instead
--> serde_derive/src/bound.rs:74:10
|
74 | .flat_map(|variant| from_variant(&variant.attrs))
| ^^^^^^^^ help: try: `filter_map`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#flat_map_option
https://github.com/rust-lang/rust-clippy/issues/7054
error: all if blocks contain the same code at the end
--> serde_derive/src/de.rs:2160:5
|
2160 | / &fallthrough_arm_tokens
2161 | | };
| |_____^
|
note: the lint level is defined here
--> serde_derive/src/lib.rs:18:9
|
18 | #![deny(clippy::all, clippy::pedantic)]
| ^^^^^^^^^^^
= note: `#[deny(clippy::branches_sharing_code)]` implied by `#[deny(clippy::all)]`
= note: The end suggestion probably needs some adjustments to use the expression result correctly
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code
help: consider moving the end statements out like this
|
2160 | }
2161 | &fallthrough_arm_tokens;
|
https://github.com/rust-lang/rust-clippy/issues/6797
error[E0382]: use of partially moved value: `self`
--> serde_derive/src/internals/attr.rs:71:24
|
71 | self.value.map(|value| (self.tokens, value))
| ----^^^^^^^----------------------
| | | |
| | | use occurs due to use in closure
| | value used here after partial move
| `self.value` partially moved due to this method call
|
note: this function takes ownership of the receiver `self`, which moves `self.value`
--> /home/david/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:485:38
|
485 | pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> {
| ^^^^
= note: partial move occurs because `self.value` has type `std::option::Option<T>`, which does not implement the `Copy` trait
Unlike expr macros, macros in type position in a derive input are rare
enough that it's not worth supporting for an issue that has such an easy
workaround (just replace `Self` in the macro input with your type name).
This usage is fine. It's mirroring trait signatures in syn::visit::Visit.
error: unused `self` argument
--> serde_derive/src/bound.rs:241:24
|
241 | fn visit_macro(&mut self, _mac: &'ast syn::Macro) {}
| ^^^^^^^^^
|
note: the lint level is defined here
--> serde_derive/src/lib.rs:18:22
|
18 | #![deny(clippy::all, clippy::pedantic)]
| ^^^^^^^^^^^^^^^^
= note: `#[deny(clippy::unused_self)]` implied by `#[deny(clippy::pedantic)]`
= help: consider refactoring to a associated function
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_self
The builtin visitor is fairly expensive to compile (3700 lines of code),
particularly if something else in the dependency graph also enables
syn/full. For the usage in serde_derive, it turns out to be easy to
replace.
The BorrowedDeserializer was added in #1917, but only makes sense for
&str and &[u8], not for u64 which also needs to be have an
IdentifierDeserializer impl.
Both of these modules are doc(hidden) and commented "Not public API",
but incorrect downstream code sometimes still references them. Naming
the module __private will make it more likely to be noticed in code
review.
error: use `std::ptr::eq` when comparing raw pointers
--> serde_derive/src/de.rs:362:12
|
362 | if field as *const Field == transparent_field as *const Field {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::eq(field, transparent_field)`
|
note: the lint level is defined here
--> serde_derive/src/lib.rs:18:9
|
18 | #![deny(clippy::all, clippy::pedantic)]
| ^^^^^^^^^^^
= note: `#[deny(clippy::ptr_eq)]` implied by `#[deny(clippy::all)]`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_eq
* Deserialize adjacently tagged newtype variants with optional content as None instead of erroring when content field is missing
* refactor to remove duplicate code and remove panic
Also changed the generated code to have at least one thing refer to the
path directly, rather than via `use` -- This shows that the impl *can*
work without `use`, but doesn't actually do all the work to remove the
`use` lines unless we decide we need this feature to work on the 2015
edition
This is intended to be used by other crates which provide their own proc
macros and use serde internally. Today there's no consistent way to put
`#[derive(Deserialize)]` on a struct that consistently works, since
crates may be using either `features = ["derive"]` or relying on
`serde_derive` separately.
Even if we assume that everyone is using `features = ["derive"]`,
without this commit, any crate which generates
`#[derive(serde::Deserialize)]` forces its consumers to put `serde` in
their `Cargo.toml`, even if they aren't otherwise using serde for
anything.
Examples of crates which suffer from this in the real world are
tower-web and swirl.
With this feature, it's expected that these crates would have `pub
extern crate serde;` in some accessible path, and add
`#[serde(serde_path = "that_crate::wherever::serde")]` anywhere they
place serde's derives. Those crates would also have to derive
`that_crate::whatever::serde::Deserialize`, or `use` the macros
explicitly beforehand.
The test for this is a little funky, as it's testing this in a way that
is not the intended use case, or even one we want to support. It has its
own module which re-exports all of serde, but defines its own
`Serialize` and `Deserialize` traits. We then test that we generated
impls for those traits, instead of serde's. The only other way to test
this would be to create a new test crate which does not depend on serde,
but instead depends on `serde_derive` and a third crate which publicly
re-exports serde. This feels like way too much overhead for a single
test case, hence the funky test given.
I didn't see anywhere in this repo to document this attribute, so I
assume the docs will have to be done as a separate PR to a separate
repo.
Fixes#1487
Added ui test struct-representation/internally-tagged-unit
Added ui test struct-representation/internally-tagged-tuple
Limited the serde(tag = "...") to enums and structs with named field
The following changes are included:
- Delete per-file license notices at the top of each file.
- Delete the first paragraph of LICENSE-MIT (an inaccurate
pseudo-copyright line), leaving only the text of the MIT license.
Nothing about the license of Serde code has changed, only our
understanding of how to correctly communicate that license has changed.
This mirrors an equivalent change being applied in the rust-lang/rust
repository.