Detect bad number of generics caused by bad derive - #160695
Open
estebank wants to merge 1 commit into
Open
Conversation
Collaborator
|
HIR ty lowering was modified cc @fmease |
This comment has been minimized.
This comment has been minimized.
When a derive macro expands the annotated item's name directly using `quote!`, it keep the item's Span context (instead of having a new context). This means that the generic Span context machinery which provides feedback that an error happened due to a derive doesn't kick in. If a derive macro isn't written to take into account the existence of type parameters, an error for "mismatched number of type parameters" will be emitted. We now detect the case when this happens due to the derive macro, and customize the output to point that out, as well as avoid giving suggestions that will always be wrong.
CenTdemeern1
reviewed
Aug 7, 2026
Comment on lines
+561
to
+563
| "it looks like this derive macro might not support annotating items with type \ | ||
| parameters", | ||
| ); |
Contributor
There was a problem hiding this comment.
it might be more accurate to say "generic parameters" as this applies to the other types of generic parameters too (lifetimes, const params)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a derive macro expands the annotated item's name directly using
quote!, it keep the item's Span context (instead of having a new context). This means that the generic Span context machinery which provides feedback that an error happened due to a derive doesn't kick in.If a derive macro isn't written to take into account the existence of type parameters, an error for "mismatched number of type parameters" will be emitted. We now detect the case when this happens due to the derive macro, and customize the output to point that out, as well as avoid giving suggestions that will always be wrong.
Partially address #160463 (this doesn't detect a nameres error caused by referencing type parameter within a derive).
r? @petrochenkov