mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-25 20:57:55 +00:00
4bddf1b953
This prevents diagnostics being rendered like `serde_core::ser::Serialize`
and `serde_core::de::Deserialize` in projects that have no direct
dependency on serde_core.
The attributes make error messages arguably sometimes worse than
pre-serde_core by always rendering `serde::Serialize` and never
`Serialize` when `use serde::Serialize` is in scope, which rustc's
default message construction knows to recognize. But this is probably
negligible.
I explored the alternative of setting `[lib] name = "serde"` in
serde_core/Cargo.toml which also prevents `serde_core::ser::Serialize`
in messages, but has the unwanted effect of also inserting the following
noise into every such error:
note: there are multiple different versions of crate `serde` in the dependency graph
--> $WORKSPACE/serde_core/src/ser/mod.rs:225:1
|
225 | pub trait Serialize {
| ^^^^^^^^^^^^^^^^^^^ this is the required trait
|
::: src/main.rs:1:1
|
1 | struct MyStruct;
| --------------- this type doesn't implement the required trait
...
4 | let _ = serde_json::to_string(&MyStruct);
| ----------
| |
| one version of crate `serde` used here, as a dependency of crate `serde`
| one version of crate `serde` used here, as a dependency of crate `serde_json`
|
::: $WORKSPACE/serde/src/private/de.rs:2347:1
|
2347 | pub trait IdentifierDeserializer<'de, E: Error> {
| ----------------------------------------------- this is the found trait
= help: you can use `cargo tree` to explore your dependency tree
The "this is the found trait" pointing to `IdentifierDeserializer` seems
like a compiler bug...
114 lines
4.4 KiB
Plaintext
114 lines
4.4 KiB
Plaintext
error[E0277]: the trait bound `MyStruct: serde::Serialize` is not satisfied
|
|
--> tests/ui/unimplemented/required_by_dependency.rs:4:35
|
|
|
|
|
4 | serde_test::assert_ser_tokens(&MyStruct, &[]);
|
|
| ----------------------------- ^^^^^^^^^ unsatisfied trait bound
|
|
| |
|
|
| required by a bound introduced by this call
|
|
|
|
|
help: the trait `serde_core::ser::Serialize` is not implemented for `MyStruct`
|
|
--> tests/ui/unimplemented/required_by_dependency.rs:1:1
|
|
|
|
|
1 | struct MyStruct;
|
|
| ^^^^^^^^^^^^^^^
|
|
= note: for local types consider adding `#[derive(serde::Serialize)]` to your `MyStruct` type
|
|
= note: for types from other crates check whether the crate offers a `serde` feature flag
|
|
= help: the following other types implement trait `serde_core::ser::Serialize`:
|
|
&'a T
|
|
&'a mut T
|
|
()
|
|
(T,)
|
|
(T0, T1)
|
|
(T0, T1, T2)
|
|
(T0, T1, T2, T3)
|
|
(T0, T1, T2, T3, T4)
|
|
and $N others
|
|
note: required by a bound in `assert_ser_tokens`
|
|
--> $CARGO/serde_test-$VERSION/src/assert.rs
|
|
|
|
|
| pub fn assert_ser_tokens<T>(value: &T, tokens: &[Token])
|
|
| ----------------- required by a bound in this function
|
|
| where
|
|
| T: ?Sized + Serialize,
|
|
| ^^^^^^^^^ required by this bound in `assert_ser_tokens`
|
|
|
|
error[E0277]: the trait bound `MyStruct: serde::Deserialize<'de>` is not satisfied
|
|
--> tests/ui/unimplemented/required_by_dependency.rs:5:34
|
|
|
|
|
5 | serde_test::assert_de_tokens(&MyStruct, &[]);
|
|
| ---------------------------- ^^^^^^^^^ unsatisfied trait bound
|
|
| |
|
|
| required by a bound introduced by this call
|
|
|
|
|
help: the trait `serde_core::de::Deserialize<'_>` is not implemented for `MyStruct`
|
|
--> tests/ui/unimplemented/required_by_dependency.rs:1:1
|
|
|
|
|
1 | struct MyStruct;
|
|
| ^^^^^^^^^^^^^^^
|
|
= note: for local types consider adding `#[derive(serde::Deserialize)]` to your `MyStruct` type
|
|
= note: for types from other crates check whether the crate offers a `serde` feature flag
|
|
= help: the following other types implement trait `serde_core::de::Deserialize<'de>`:
|
|
&'a Path
|
|
&'a [u8]
|
|
&'a str
|
|
()
|
|
(T,)
|
|
(T0, T1)
|
|
(T0, T1, T2)
|
|
(T0, T1, T2, T3)
|
|
and $N others
|
|
note: required by a bound in `assert_de_tokens`
|
|
--> $CARGO/serde_test-$VERSION/src/assert.rs
|
|
|
|
|
| pub fn assert_de_tokens<'de, T>(value: &T, tokens: &'de [Token])
|
|
| ---------------- required by a bound in this function
|
|
| where
|
|
| T: Deserialize<'de> + PartialEq + Debug,
|
|
| ^^^^^^^^^^^^^^^^ required by this bound in `assert_de_tokens`
|
|
|
|
error[E0277]: can't compare `MyStruct` with `MyStruct`
|
|
--> tests/ui/unimplemented/required_by_dependency.rs:5:34
|
|
|
|
|
5 | serde_test::assert_de_tokens(&MyStruct, &[]);
|
|
| ---------------------------- ^^^^^^^^^ no implementation for `MyStruct == MyStruct`
|
|
| |
|
|
| required by a bound introduced by this call
|
|
|
|
|
= help: the trait `PartialEq` is not implemented for `MyStruct`
|
|
note: required by a bound in `assert_de_tokens`
|
|
--> $CARGO/serde_test-$VERSION/src/assert.rs
|
|
|
|
|
| pub fn assert_de_tokens<'de, T>(value: &T, tokens: &'de [Token])
|
|
| ---------------- required by a bound in this function
|
|
| where
|
|
| T: Deserialize<'de> + PartialEq + Debug,
|
|
| ^^^^^^^^^ required by this bound in `assert_de_tokens`
|
|
help: consider annotating `MyStruct` with `#[derive(PartialEq)]`
|
|
|
|
|
1 + #[derive(PartialEq)]
|
|
2 | struct MyStruct;
|
|
|
|
|
|
|
error[E0277]: `MyStruct` doesn't implement `Debug`
|
|
--> tests/ui/unimplemented/required_by_dependency.rs:5:34
|
|
|
|
|
5 | serde_test::assert_de_tokens(&MyStruct, &[]);
|
|
| ---------------------------- ^^^^^^^^^ the trait `Debug` is not implemented for `MyStruct`
|
|
| |
|
|
| required by a bound introduced by this call
|
|
|
|
|
= note: add `#[derive(Debug)]` to `MyStruct` or manually `impl Debug for MyStruct`
|
|
note: required by a bound in `assert_de_tokens`
|
|
--> $CARGO/serde_test-$VERSION/src/assert.rs
|
|
|
|
|
| pub fn assert_de_tokens<'de, T>(value: &T, tokens: &'de [Token])
|
|
| ---------------- required by a bound in this function
|
|
| where
|
|
| T: Deserialize<'de> + PartialEq + Debug,
|
|
| ^^^^^ required by this bound in `assert_de_tokens`
|
|
help: consider annotating `MyStruct` with `#[derive(Debug)]`
|
|
|
|
|
1 + #[derive(Debug)]
|
|
2 | struct MyStruct;
|
|
|
|