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

Specify scope in out_of_scope_macro_calls lint #128080

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

Conversation

estebank
Copy link
Contributor

warning: cannot find macro `in_root` in the crate root
  --> $DIR/key-value-expansion-scope.rs:1:10
   |
LL | #![doc = in_root!()]
   |          ^^^^^^^ not found in the crate root
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
   = help: import `macro_rules` with `use` to make it callable above its definition
   = note: `#[warn(out_of_scope_macro_calls)]` on by default

r? @petrochenkov

```
warning: cannot find macro `in_root` in the crate root
  --> $DIR/key-value-expansion-scope.rs:1:10
   |
LL | #![doc = in_root!()]
   |          ^^^^^^^ not found in the crate root
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue rust-lang#124535 <rust-lang#124535>
   = help: import `macro_rules` with `use` to make it callable above its definition
   = note: `#[warn(out_of_scope_macro_calls)]` on by default
```
@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 Jul 23, 2024
@estebank
Copy link
Contributor Author

Split off from #126810

@petrochenkov
Copy link
Contributor

This PR (and probably some other diagnostics in #126810) mix up two different things

  • the set of places in which the name is looked up - "the current scope" (ident), or "module foo" (foo::ident), or "the crate root" (crate::ident) or "extern prelude" (::ident)
  • the location from which the name is resolved - "enum E", or "trait Bar", or "the crate root" as well

In the example above

warning: cannot find macro `in_root` in the crate root

in_root is not looked up in the crate root, like it may seem from the message.
It is looked up in the current scope from the crate root module.

warning: cannot find macro `in_root` in the current scope from the crate root module

That's how I'd word it if I extended the message.

I'm not sure what exactly should go after "from" for the clarification to be useful.
The ModuleKind-based location in this PR will only report modules, enums and traits (or nothing in blocks).
Seems arbitrary, but also ok as an approximation.
Or maybe just not do this and keep things as is because the clarification is not useful enough, not sure.


Note: renaming "this scope" to "the current scope" would look like a slight improvement to me, but it's a massive mechanical change, probably worth doing last after more meaningful changes settle down.

@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 Jul 23, 2024
@bors
Copy link
Contributor

bors commented Aug 28, 2024

☔ The latest upstream changes (presumably #129665) made this pull request unmergeable. Please resolve the merge conflicts.

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.

4 participants