Do not suggest adding semicolon/changing delimiters for macros in item position that originates in macros#97377
Conversation
|
(rust-highfive has picked a reviewer for you, use r? to override) |
|
Thanks for the PR, @ChayimFriedman2! That FIXME suggests that there's a diagnostics design decision to be made here. |
There was a problem hiding this comment.
What happens if you instead use the following? Is the FIXME still applicable then? I suspect it might not be.
| if !span.from_expansion() { | |
| if !span.can_be_used_for_suggestions() { |
There was a problem hiding this comment.
That doesn't work. can_be_used_for_suggestions() only checks for derive macros where the span they emit is different from the span of themselves. This will both provide incorrect suggestions for those macros and still fail as with the FIXME.
rust/compiler/rustc_span/src/lib.rs
Lines 575 to 583 in 49c82f3
There was a problem hiding this comment.
What about using in_derive_expansion and only gate on those, then?
There was a problem hiding this comment.
I've thought about that, but attribute macros should not suggest help either; and probably neither should declarative macros from separate crates.
There was a problem hiding this comment.
Could you then checks for !matches!(kind, ExprKind::Macro(MacroKind::Derive | MacroKind::Attr, _)) and using tcx.sess().source_map().lookup_char_pos(span.lo()).file on both the suggestion span and the callsite span to see if they belong to the same file?
Also, an additional test for those cases so that we see when the suggestion should appear in the same file might be useful. That might be easy to do for a macro by example. You might need to expand the test to also have an "external crate" example to check for that case too.
Would you have time to get these things done in this PR?
There was a problem hiding this comment.
Soon. But should it be the same file or same crate?
There was a problem hiding this comment.
And what about function-like proc macros? How can I differentiate those?
There was a problem hiding this comment.
Ah, you're right. @petrochenkov what would the best way of checking that a span doesn't correspond to a proc-macro of any type nor a macro by example from a foreign crate, while parsing an item?
There was a problem hiding this comment.
@petrochenkov friendly ping, if you have advice re: ^
I'm ok with landing with if !span.from_expansion() {, at least for now. Would you mind rebasing @ChayimFriedman2?
|
☔ The latest upstream changes (presumably #98066) made this pull request unmergeable. Please resolve the merge conflicts. |
498dc12 to
01ff48b
Compare
…m position that originates in macros
01ff48b to
0ef4098
Compare
|
@bors r+ |
|
📌 Commit 0ef4098 has been approved by |
Rollup of 5 pull requests Successful merges: - rust-lang#97377 (Do not suggest adding semicolon/changing delimiters for macros in item position that originates in macros) - rust-lang#97675 (Make `std::mem::needs_drop` accept `?Sized`) - rust-lang#98118 (Test NLL fix of bad lifetime inference for reference captured in closure.) - rust-lang#98166 (Add rustdoc-json regression test for rust-lang#98009) - rust-lang#98169 (Keyword docs: Link to wikipedia article for dynamic dispatch) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #91800.