serde icon indicating copy to clipboard operation
serde copied to clipboard

Improve error reporting about mismatched signature in `with` and `default` attributes

Open Mingun opened this issue 2 years ago • 2 comments

This PR changes the errors reported by rustc when signature of function specified in

  • #[serde(with = "...")]
  • #[serde(deserialize_with = "...")]
  • #[serde(serialize_with = "...")]
  • #[serde(default = "...")]

is wrong. With this PR error will point to the "...".

Mingun avatar Aug 07 '23 10:08 Mingun

Strange, but order of implementations shown in failed run is different from my (my removed, GitHub runner added):

    = help: the following other types implement trait `Serializer`:
-             FlatMapSerializer<'a, M>
-             &'a mut Formatter<'b>
              _::_serde::__private::ser::content::ContentSerializer<E>
+             FlatMapSerializer<'a, M>
+             &'a mut Formatter<'b>

This can create difficulties in local testing.

Mingun avatar Aug 07 '23 10:08 Mingun

Probably the order of suggested implementations is heavy dependent on rustc version. With rustc 1.82.0-nightly (fbccf5053 2024-07-27) the local output is the same as at GitHub.

Mingun avatar Aug 04 '24 19:08 Mingun

@oli-obk looks like the merge of this PR broke master CI. The CI on this PR was green some time ago, and it broke with time

Veetaha avatar Oct 21 '24 22:10 Veetaha

The failing ui test was from a non-textual conflict with https://github.com/serde-rs/serde/commit/8e1ae68569db46251a88997e5e212392d4ad83ea. Fixed in #2839. (Also #2840).

It is unfortunate that:

   = help: the following other types implement trait `Serializer`:
             &mut Formatter<'a>
             FlatMapSerializer<'a, M>
             _::_serde::__private::ser::content::ContentSerializer<E>

is the set of impls chosen to be suggested by rustc. Is there something we can do with doc(hidden) to exclude nonpublic APIs from this error message? If not, this needs to be reported as a rustc bug.

dtolnay avatar Oct 22 '24 02:10 dtolnay

Reported https://github.com/rust-lang/rust/issues/132024.

dtolnay avatar Oct 22 '24 04:10 dtolnay

is the set of impls chosen to be suggested by rustc. Is there something we can do with doc(hidden) to exclude nonpublic APIs from this error message? If not, this needs to be reported as a rustc bug.

We'll get diagnostics::do_not_suggest or sth. Iirc it's being worked on or works on nightly already

oli-obk avatar Oct 22 '24 08:10 oli-obk

it looks like this change might have unintended side effects. https://github.com/rust-lang/crates.io/pull/9720 upgrades crates.io from v1.0.210 to v1.0.211 and we are now seeing various "not found in this scope" errors that were not there before.

Turbo87 avatar Oct 22 '24 09:10 Turbo87