Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the wrong suggestion to add a format literal "{}" directly where a proc macro is invoked. #116298

Closed
wants to merge 1 commit into from

Conversation

cafce25
Copy link

@cafce25 cafce25 commented Sep 30, 2023

Fixes #116190

@rustbot
Copy link
Collaborator

rustbot commented Sep 30, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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. labels Sep 30, 2023
@cafce25
Copy link
Author

cafce25 commented Sep 30, 2023

I'm not done yet, sorry for the troubles.
@rustbot author

@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 Sep 30, 2023
@rust-log-analyzer

This comment has been minimized.

@cafce25 cafce25 marked this pull request as ready for review October 1, 2023 14:06
@cafce25
Copy link
Author

cafce25 commented Oct 1, 2023

@rustbot review

@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 Oct 1, 2023
@@ -587,6 +587,12 @@ impl Span {
matches!(outer_expn.kind, ExpnKind::Macro(..)) && outer_expn.collapse_debuginfo
}

/// Returns `true` if `span` originates in a macros 2.0 expansion
Copy link
Contributor

Choose a reason for hiding this comment

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

Why macros 2.0 specifically, why is it relevant to this error?

Copy link
Author

Choose a reason for hiding this comment

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

Maybe I'm confused on nomenclature, the wrong help is emitted for proc macros only, with declarative macros the compiler puts the suggestion in the correct place. Aren't proc marcos and macros 2.0 the same thing essentially? If not this should probably just read proc macro expansion instead of macros 2.0 expansion

Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't proc marcos and macros 2.0 the same thing essentially?

No, not at all.
Both declarative and procedural macros can use both old and macro 2.0 hygiene.

This situation is far from being unique, I suggest checking what other diagnostics do (fn in_external_macro or something like that).

@@ -186,6 +186,8 @@ fn make_format_args(
],
Applicability::MaybeIncorrect,
);
} else if unexpanded_fmt_span.in_proc_macro_expansion() {
err.help("you might be missing a string literal to format with in the definition of this macro");
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of compiler suggestions are skipped for code from macros, but suggestions to look into the macro like this are typically not emitted in such cases.

| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: you might be missing a string literal to format with in the definition of this macro
= note: this error originates in the derive macro `format_in_macro::derive` (in Nightly builds, run with -Z macro-backtrace for more info)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see the issue from #116190 (#[derive("{}", macros::bare_println)]) in the test outputs.
Could you add all the tests and make them pass in one commit, and then apply compiler fixes and corresponding test updates in the second commit?

@petrochenkov petrochenkov 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 Oct 11, 2023
@JohnCSimon
Copy link
Member

@cafce25

ping from triage - can you post your status on this PR? There hasn't been an update in a few weeks. Thanks!

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@cafce25
Copy link
Author

cafce25 commented Nov 14, 2023

Hi @JohnCSimon,

I've started to work on the feedback from petrochenkov, unfortunately I didn't have too much time in the past few weeks.
Fortunately the big project at work which partially took my hours should be finished this week and I will have some time for further work this weekend / next week so I expect this to be ready for another round of review by end of next week.

@rustbot
Copy link
Collaborator

rustbot commented Nov 23, 2023

There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

You can start a rebase with the following commands:

$ # rebase
$ git rebase -i master
$ # delete any merge commits in the editor that appears
$ git push --force-with-lease

The following commits are merge commits:

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Nov 23, 2023
@dtolnay dtolnay removed the has-merge-commits PR has merge commits, merge with caution. label Jan 21, 2024
@Dylan-DPC
Copy link
Member

@cafce25 any updates on this? if this ready for review you can comment with @rustbot ready

@JohnCSimon
Copy link
Member

@cafce25

Ping from triage: I'm closing this due to inactivity, Please reopen when you are ready to continue with this.
Note: if you are going to continue please open the PR BEFORE you push to it, else you won't be able to reopen - this is a quirk of github.
Thanks for your contribution.

@rustbot label: +S-inactive

@JohnCSimon JohnCSimon closed this Apr 14, 2024
@rustbot rustbot added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing format literal in output of derive macro puts the string literal within the derive attribute
7 participants