Skip to content

diagnostics: hide expansion of builtin-like macros #141314

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mejrs
Copy link
Contributor

@mejrs mejrs commented May 20, 2025

As of late I've gotten more and more annoyed by notes like note: this error originates in the macro $crate::__export::format_args.

This PR hides that message if it comes from an expansion of a macro that uses features like fmt_internals. If its expansion is an implementation detail we shouldn't be mentioning it. This covers macros like vec!, format! and so on, but not the more mundane ones like assert_eq! and todo!!

@rustbot
Copy link
Collaborator

rustbot commented May 20, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 May 20, 2025
@rust-log-analyzer

This comment has been minimized.

|| aiu.contains(&sym::print_internals)
|| aiu.contains(&sym::liballoc_internals)
}),
)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth pulling everything after the first || out into a separate variable.

Also, I don't really understand how this works, i.e. how allow_internal_unstable is involved. A brief comment explaining it would be useful.

@nnethercote
Copy link
Contributor

Generally looks good, I will r+ once the tests all pass the the suggestion above is addressed. Thanks.

@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 May 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 21, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@@ -193,16 +193,12 @@ error: asm template must be a string literal
|
LL | asm!(format!("{{{}}}", 0), in(reg) foo);
| ^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
Copy link
Member

Choose a reason for hiding this comment

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

Does -Zmacro-backtrace still work for builtin-like macros with this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I've added two tests for it.

@petrochenkov
Copy link
Contributor

I just recently rejected this change in #138379.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@mejrs
Copy link
Contributor Author

mejrs commented May 21, 2025

I just recently rejected this change in #138379.

I was unaware of this PR, thanks for linking it.

Personally I do not find the -Zmacro-backtrace flag generally useful and recommending its use by default feels like spam. I'm of the opinion that helps and notes should be targeted and we should only emit them if we can be generally sure (or at least suspect that) the user will find them useful. We should not emit it by default if an error happens anywhere near a macro.

This PR targets macros that are mostly just thin wrappers around some unstable/internal function/macro/intrinsic, and if an error happens it's never because the macro itself did something weird. Most of them have specialized diagnostic paths in the compiler anyway.

Putting aside the question of whether we should recommend it less, I'm also happy to discuss the metric by which to decide that. Filtering on allow_internal_unstable isn't really a principled method but IMO it happens to target the ones that are least useful to backtrace into. But the cases where I did find -Zmacro-backtrace useful were when I was writing my own macros. So maybe we should only display it if the macros are crate/workspace local? Or maybe when the macro in question has branches, so we can show which path the macro took? Maybe we should just show the backtrace in that case rather then tell the user to use the flag?

Finally, consider that there is a cost to showing messages to the user as well. The more text we shove into an user's face, the less attention that user will pay to a particular note or help message that might actually be well targeted and useful.

I'm happy to hear yours and others' thoughts about this.

@rustbot
Copy link
Collaborator

rustbot commented May 21, 2025

The Miri subtree was changed

cc @rust-lang/miri

@nnethercote
Copy link
Contributor

I think this PR is good. I agree that the removed parts of the messages are low-value.

I just recently rejected this change in #138379.

@petrochenkov, can you explain more? I read that PR and I guess this comment is the most relevant one, but it's hard to tell exactly how the original version of that PR overlaps with this PR. A fresh explanation would be helpful.

@petrochenkov
Copy link
Contributor

petrochenkov commented May 22, 2025

I can only rehash what I said in #138379 (comment).
There are many macros in the ecosystem that are implementation details, the ones in libstd are not special in any way, and their internals are not less interesting to the user than any of the third-party macro internals (maybe even more interesting actually), and the compiler shouldn't "know" anything about libstd in general, besides the lang/diagnostic item interface.

@oli-obk
Copy link
Contributor

oli-obk commented May 22, 2025

This feels similar to track_caller hiding functions from the panic location and even const eval backtraces. As suggested by some folk, maybe just an annotation per macro would be best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

7 participants