Skip to content

Improve error reporting about mismatched signature in with and default attributes#2558

Merged
oli-obk merged 3 commits into
serde-rs:masterfrom
Mingun:correct-span
Oct 21, 2024
Merged

Improve error reporting about mismatched signature in with and default attributes#2558
oli-obk merged 3 commits into
serde-rs:masterfrom
Mingun:correct-span

Conversation

@Mingun

@Mingun Mingun commented Aug 7, 2023

Copy link
Copy Markdown
Contributor

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

Mingun commented Aug 7, 2023

Copy link
Copy Markdown
Contributor Author

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

Mingun commented Aug 4, 2024

Copy link
Copy Markdown
Contributor Author

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.

@oli-obk oli-obk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are great improvements. It seems like there is still space for rustc to provide more diagnostics attributes, but nothing that we can fix ok this end

@oli-obk
oli-obk merged commit 04bb76b into serde-rs:master Oct 21, 2024
@Mingun
Mingun deleted the correct-span branch October 21, 2024 20:16
@Veetaha

Veetaha commented Oct 21, 2024

Copy link
Copy Markdown

@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

@dtolnay

dtolnay commented Oct 22, 2024

Copy link
Copy Markdown
Member

The failing ui test was from a non-textual conflict with 8e1ae68. 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

dtolnay commented Oct 22, 2024

Copy link
Copy Markdown
Member

Reported rust-lang/rust#132024.

@oli-obk

oli-obk commented Oct 22, 2024

Copy link
Copy Markdown
Member

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

@Turbo87

Turbo87 commented Oct 22, 2024

Copy link
Copy Markdown

it looks like this change might have unintended side effects. rust-lang/crates.io#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants