serde/test_suite/tests/ui/unimplemented/required_locally.stderr
David Tolnay 4bddf1b953
Override diagnostic::on_unimplemented message of all serde_core traits
This prevents diagnostics being rendered like `serde_core::ser::Serialize`
and `serde_core:🇩🇪: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...
2025-09-13 13:59:52 -07:00

66 lines
2.3 KiB
Plaintext

error[E0277]: the trait bound `MyStruct: serde::Serialize` is not satisfied
--> tests/ui/unimplemented/required_locally.rs:21:15
|
21 | to_string(&MyStruct);
| --------- ^^^^^^^^^ unsatisfied trait bound
| |
| required by a bound introduced by this call
|
help: the trait `Serialize` is not implemented for `MyStruct`
--> tests/ui/unimplemented/required_locally.rs:18:1
|
18 | 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 `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 `to_string`
--> tests/ui/unimplemented/required_locally.rs:6:8
|
4 | fn to_string<T>(_: &T) -> String
| --------- required by a bound in this function
5 | where
6 | T: Serialize,
| ^^^^^^^^^ required by this bound in `to_string`
error[E0277]: the trait bound `MyStruct: serde::Deserialize<'de>` is not satisfied
--> tests/ui/unimplemented/required_locally.rs:22:23
|
22 | let _: MyStruct = from_str("");
| ^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait `Deserialize<'_>` is not implemented for `MyStruct`
--> tests/ui/unimplemented/required_locally.rs:18:1
|
18 | 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 `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 `from_str`
--> tests/ui/unimplemented/required_locally.rs:13:8
|
11 | fn from_str<'de, T>(_: &'de str) -> T
| -------- required by a bound in this function
12 | where
13 | T: Deserialize<'de>,
| ^^^^^^^^^^^^^^^^ required by this bound in `from_str`