Skip to content

Add on_unmatch_args#154794

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
chenyukang:yukang-fix-152494-incomplete-macro-args
Apr 22, 2026
Merged

Add on_unmatch_args#154794
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
chenyukang:yukang-fix-152494-incomplete-macro-args

Conversation

@chenyukang
Copy link
Copy Markdown
Member

@chenyukang chenyukang commented Apr 4, 2026

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 4, 2026

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Apr 4, 2026
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 4, 2026
@chenyukang chenyukang force-pushed the yukang-fix-152494-incomplete-macro-args branch from 3eb0c39 to e3e5e61 Compare April 4, 2026 02:29
Copy link
Copy Markdown
Contributor

@mejrs mejrs left a comment

Choose a reason for hiding this comment

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

Thanks, great idea. I love this.

A few points

  • you need more tests, for invalid args, on invalid items, cross crate use, format parameters etc.
  • format parameters; do these make sense? Currently they are not handled at all, just silently ignored. In check_attr.rs you can call directive_visit_params and issue diagnostics for them. Would it be useful to have indexed parameters like {1}, {2} to reference arguments? Something to think about, perhaps.
  • 2c on the naming; I don't have a problem with the name perse, I just intensely dislike names that are really long. Also you don't have to use the exact name estebank suggested :) Something shorter would be lovely. Also consider whether this is something we could extend to functions etc?
  • Can you please add some docs about this in the unstable book: https://doc.rust-lang.org/nightly/unstable-book/

View changes since this review

Comment thread compiler/rustc_expand/src/mbe/macro_rules.rs
Comment thread compiler/rustc_expand/src/mbe/diagnostics.rs Outdated
@chenyukang
Copy link
Copy Markdown
Member Author

for naming, maybe on_missing_args maybe better, incase we can extend it in future?

@chenyukang chenyukang force-pushed the yukang-fix-152494-incomplete-macro-args branch from e3e5e61 to 75df17e Compare April 6, 2026 10:48
@chenyukang chenyukang changed the title Add on_incomplete_macro_args Add on_missing_args Apr 6, 2026
@rust-log-analyzer

This comment has been minimized.

@chenyukang chenyukang force-pushed the yukang-fix-152494-incomplete-macro-args branch from 75df17e to 2fed49b Compare April 6, 2026 11:57
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@chenyukang chenyukang marked this pull request as draft April 6, 2026 13:26
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 6, 2026
@rust-log-analyzer

This comment has been minimized.

@chenyukang chenyukang force-pushed the yukang-fix-152494-incomplete-macro-args branch from 595180d to 4898501 Compare April 6, 2026 13:43
@rust-log-analyzer

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@mejrs mejrs left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my earlier comments (I cannot click resolve myself 😮‍💨).

Finally, I just remembered that declarative macro derives and attributes exist - can you add tests (and perhaps support for them) as well? See #145208 and #144579.

View changes since this review

Comment thread compiler/rustc_expand/src/mbe/diagnostics.rs Outdated
Comment thread compiler/rustc_expand/src/mbe/diagnostics.rs Outdated
Comment thread src/doc/unstable-book/src/language-features/diagnostic-on-missing-args.md Outdated
@chenyukang chenyukang force-pushed the yukang-fix-152494-incomplete-macro-args branch from dc940ba to dde50f5 Compare April 7, 2026 02:22
@rust-log-analyzer

This comment has been minimized.

@chenyukang chenyukang force-pushed the yukang-fix-152494-incomplete-macro-args branch from dde50f5 to 2e0c595 Compare April 7, 2026 04:04
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 7, 2026
…JonathanBrouwer

Stabilize check-cfg suggestions for symbol

When I was working on rust-lang#154794, I found a weird CI fail rust-lang#154794 (comment), I finally found this caused by unstable cfg suggestions by using `FxHashSet`(from PR rust-lang#154777). Because my PR by luck insert a new symbol, which makes the final diagnostic order changed.

It's a standalone issue, so it's better to fix in a separate PR.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 7, 2026
…JonathanBrouwer

Stabilize check-cfg suggestions for symbol

When I was working on rust-lang#154794, I found a weird CI fail rust-lang#154794 (comment), I finally found this caused by unstable cfg suggestions by using `FxHashSet`(from PR rust-lang#154777). Because my PR by luck insert a new symbol, which makes the final diagnostic order changed.

It's a standalone issue, so it's better to fix in a separate PR.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 7, 2026
…JonathanBrouwer

Stabilize check-cfg suggestions for symbol

When I was working on rust-lang#154794, I found a weird CI fail rust-lang#154794 (comment), I finally found this caused by unstable cfg suggestions by using `FxHashSet`(from PR rust-lang#154777). Because my PR by luck insert a new symbol, which makes the final diagnostic order changed.

It's a standalone issue, so it's better to fix in a separate PR.
rust-timer added a commit that referenced this pull request Apr 7, 2026
Rollup merge of #154886 - chenyukang:yukang-fix-cfg-sugg, r=JonathanBrouwer

Stabilize check-cfg suggestions for symbol

When I was working on #154794, I found a weird CI fail #154794 (comment), I finally found this caused by unstable cfg suggestions by using `FxHashSet`(from PR #154777). Because my PR by luck insert a new symbol, which makes the final diagnostic order changed.

It's a standalone issue, so it's better to fix in a separate PR.
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 19, 2026

Some changes occurred to diagnostic attributes.

cc @mejrs

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 19, 2026
@chenyukang
Copy link
Copy Markdown
Member Author

@rustbot ready

Copy link
Copy Markdown
Contributor

@mejrs mejrs left a comment

Choose a reason for hiding this comment

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

I'm happy with the implementation, just a couple of nits - see comments.

We also need more tests documenting the current behavior (if any) when applied to macro_rules! derive and attribute macros, as well as all the procedural macro types. It's up to you if you do that in this PR or add it as todos on the tracking issue. I think I prefer the latter though.

@estebank do you have any comments? If not, r=me with nits fixed.

View changes since this review

Comment on lines +22 to +24
message = "pair! is missing its second argument",
label = "add the missing value here",
note = "this macro expects a type and a value, like `pair!(u8, 0)`",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The message and label were written with the "on missing args" semantics; they feel a little off now.

My suggestion:

#[diagnostic::on_unmatch_args(
    message = "invalid arguments to {This} macro invocation",
    label = "expected a type and value here",
    note = "this macro expects a type and a value, like `pair!(u8, 0)`",
    note = "see <link/to/docs>"
)]

Thoughts?

The same is true for many tests, but those don't really matter I suppose.

}

pair!(u8);
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please also show the compiler output below the example.

Comment thread library/core/src/mem/mod.rs Outdated
/// [`offset_of_slice`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-slice.html
#[stable(feature = "offset_of", since = "1.77.0")]
#[diagnostic::on_unmatch_args(
note = "this macro expects a container type and a dot-separated field or variant path, like `offset_of!(Type, field)`"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
note = "this macro expects a container type and a dot-separated field or variant path, like `offset_of!(Type, field)`"
note = "this macro expects a container type and a (nested) field path, like `offset_of!(Type, field)`"

offset_of! for enums is unstable, we shouldn't suggest it.

@mejrs mejrs added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 19, 2026
@chenyukang chenyukang force-pushed the yukang-fix-152494-incomplete-macro-args branch from 9518bba to 60f40d1 Compare April 20, 2026 01:09
@rust-bors

This comment has been minimized.

@chenyukang chenyukang force-pushed the yukang-fix-152494-incomplete-macro-args branch from 60f40d1 to e675ac9 Compare April 22, 2026 00:30
@rustbot

This comment has been minimized.

@mejrs
Copy link
Copy Markdown
Contributor

mejrs commented Apr 22, 2026

r? me

Sorry, one more thing I just noticed. In rustc_feature and the unstable book you reference #152494 as the tracking issue, but that is estebank's suggestion issue, not a tracking issue. Please create and link a proper tracking issue.

r=me with tracking issue

@rustbot rustbot assigned mejrs and unassigned estebank Apr 22, 2026
@chenyukang
Copy link
Copy Markdown
Member Author

r? me

Sorry, one more thing I just noticed. In rustc_feature and the unstable book you reference #152494 as the tracking issue, but that is estebank's suggestion issue, not a tracking issue. Please create and link a proper tracking issue.

r=me with tracking issue

ok, I placed it as a placeholder link and forget it 😅
I will create a new tracking issue.

@chenyukang chenyukang force-pushed the yukang-fix-152494-incomplete-macro-args branch from e675ac9 to 1f6541b Compare April 22, 2026 11:28
@chenyukang chenyukang force-pushed the yukang-fix-152494-incomplete-macro-args branch from 1f6541b to 8d75f0c Compare April 22, 2026 11:29
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 22, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@mejrs
Copy link
Copy Markdown
Contributor

mejrs commented Apr 22, 2026

Thanks for working on this :)

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 22, 2026

📌 Commit 8d75f0c has been approved by mejrs

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 22, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #154794 (Add on_unmatch_args)
 - #155133 (Document precision considerations of `Duration`-float methods)
 - #154283 (Remove `nodes_in_current_session` field and related assertions)
 - #155374 (rustdoc: fix a few spots where emit isn't respected)
 - #155587 (Immediately feed visibility on DefId creation)
 - #155622 (c-variadic: `va_arg` fixes )
 - #155629 (rustc_public: Add `constness` & `asyncness` in `FnDef`)
 - #155632 (Some metadata cleanups)
 - #155639 (BinOpAssign always returns unit)
 - #155647 (rustc-dev-guide subtree update)
@rust-bors rust-bors Bot merged commit 5ad7363 into rust-lang:main Apr 22, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 22, 2026
rust-timer added a commit that referenced this pull request Apr 22, 2026
Rollup merge of #154794 - chenyukang:yukang-fix-152494-incomplete-macro-args, r=mejrs

Add on_unmatch_args

Fixes #152494
r? @estebank
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Apr 24, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#154794 (Add on_unmatch_args)
 - rust-lang/rust#155133 (Document precision considerations of `Duration`-float methods)
 - rust-lang/rust#154283 (Remove `nodes_in_current_session` field and related assertions)
 - rust-lang/rust#155374 (rustdoc: fix a few spots where emit isn't respected)
 - rust-lang/rust#155587 (Immediately feed visibility on DefId creation)
 - rust-lang/rust#155622 (c-variadic: `va_arg` fixes )
 - rust-lang/rust#155629 (rustc_public: Add `constness` & `asyncness` in `FnDef`)
 - rust-lang/rust#155632 (Some metadata cleanups)
 - rust-lang/rust#155639 (BinOpAssign always returns unit)
 - rust-lang/rust#155647 (rustc-dev-guide subtree update)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide #[diagnostic::on_incomplete_macro_args] to customize macro call errors

5 participants