Conversation
|
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 |
3eb0c39 to
e3e5e61
Compare
There was a problem hiding this comment.
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.rsyou can calldirective_visit_paramsand 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/
compiler/rustc_attr_parsing/src/attributes/diagnostic/on_missing_args.rs
Show resolved
Hide resolved
|
for naming, maybe |
e3e5e61 to
75df17e
Compare
This comment has been minimized.
This comment has been minimized.
75df17e to
2fed49b
Compare
|
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. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
595180d to
4898501
Compare
This comment has been minimized.
This comment has been minimized.
| This attribute currently applies to declarative macros such as `macro_rules!` and `pub macro`. | ||
| It only affects diagnostics for incomplete invocations; other matcher failures continue to use the | ||
| usual macro diagnostics. |
There was a problem hiding this comment.
This is not quite what I understood from #152494.
I think @estebank's idea is that it should trigger when no macro arm matches, not just when it is incomplete. For example the current implementation does not trigger with the following invocations:
#[diagnostic::on_missing_args(
note = "this macro expects a type and a value, like `pair!(u8, 0)`",
note = "make sure to pass both arguments",
)]
macro_rules! pair {
//~^ NOTE when calling this macro
($ty:ty, $value:expr) => {};
//~^ NOTE while trying to match `,`
}
pair!(u8, <);
pair!(u8, 0, 42);I think triggering on no match makes more sense. Maybe then the name should be on_no_match? on_failed_match? on_fallthrough? (please do wait for consensus before renaming everything 😅 ).
There was a problem hiding this comment.
yes, seems 'on_unmatch_args` is a proper name, if we extend this diagnostic to more scenarios, such as like:
#![feature(diagnostic_on_missing_args)]
#[diagnostic::on_missing_args(
message = "invalid route method",
note = "this macro expects a action, like `{This}!(get \"/hello\")`"
)]
macro_rules! route {
(get $path:literal) => {};
}
fn main() {
route!(post "/");
}we also can report:
error: invalid route method
--> tests/ui/diagnostic_namespace/on_missing_args/other_match_macro_error.rs:12:12
|
7 | macro_rules! route {
| ------------------ when calling this macro
...
12 | route!(post "/");
| ^^^^ no rules expected this token in macro call
|
note: while trying to match `get`
--> tests/ui/diagnostic_namespace/on_missing_args/other_match_macro_error.rs:8:6
|
8 | (get $path:literal) => {};
| ^^^
= note: this macro expects a action, like `route!(get "/hello")`
error: aborting due to 1 previous errordc940ba to
dde50f5
Compare
This comment has been minimized.
This comment has been minimized.
dde50f5 to
2e0c595
Compare
…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 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 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.
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.
Fixes #152494
r? @estebank