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

Merged
merged 2 commits into from
Feb 21, 2025

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

@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

This comment was marked as resolved.

@alex-semenyuk alex-semenyuk 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 30, 2024
@JohnCSimon
Copy link
Member

@estebank
ping from triage - can you post your status on this PR? This PR has not received an update in a few months.

@petrochenkov
Copy link
Contributor

@estebank Do you plan to return to this?

```
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
```
@estebank
Copy link
Contributor Author

Rebased and reworded the message to be inline with your comment, @petrochenkov.


I'm wondering what we should do for the case that would look like

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

I agree that we should differentiate the two concepts, I'm just also unsure on how to that in a way that can be conveyed to our users in a reasonable way.

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-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 Feb 20, 2025
@petrochenkov
Copy link
Contributor

I'm wondering what we should do for the case that would look like

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

Probably skip the "from" part if the $location is "this scope" (== make the location optional).

@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 Feb 20, 2025
@estebank
Copy link
Contributor Author

Re: the redundant wording/making the location optional, we have no test in the codebase that shows that case, so I'd like to leave the optionality of that output for a separate PR.

@estebank estebank 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 Feb 20, 2025
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 20, 2025

📌 Commit 835d434 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 20, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Feb 20, 2025
…rochenkov

Specify scope in `out_of_scope_macro_calls` lint

```
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
```

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 20, 2025
Rollup of 12 pull requests

Successful merges:

 - rust-lang#128080 (Specify scope in `out_of_scope_macro_calls` lint)
 - rust-lang#135354 ([Debuginfo] Add MSVC Synthetic and Summary providers to LLDB)
 - rust-lang#135630 (add more `s390x` target features)
 - rust-lang#136089 (Reduce `Box::default` stack copies in debug mode)
 - rust-lang#136148 (Optionally add type names to `TypeId`s.)
 - rust-lang#137192 (Remove obsolete Windows ThinLTO+TLS workaround)
 - rust-lang#137204 (Clarify MIR dialects and phases)
 - rust-lang#137299 (Simplify `Postorder` customization.)
 - rust-lang#137302 (Use a probe to avoid registering stray region obligations when re-checking drops in MIR typeck)
 - rust-lang#137305 (Tweaks in and around `rustc_middle`)
 - rust-lang#137313 (Some codegen_llvm cleanups)
 - rust-lang#137333 (Use `edition = "2024"` in the compiler (redux))

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: test-various
try-job: x86_64-msvc-1
try-job: x86_64-msvc-2
try-job: i686-msvc-1
try-job: i686-msvc-2
try-job: i686-mingw-1
try-job: i686-mingw-2
try-job: i686-mingw-3
try-job: x86_64-gnu-nopt
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Feb 20, 2025
…rochenkov

Specify scope in `out_of_scope_macro_calls` lint

```
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
```

r? ``@petrochenkov``
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 21, 2025
Rollup of 10 pull requests

Successful merges:

 - rust-lang#128080 (Specify scope in `out_of_scope_macro_calls` lint)
 - rust-lang#135630 (add more `s390x` target features)
 - rust-lang#136089 (Reduce `Box::default` stack copies in debug mode)
 - rust-lang#137192 (Remove obsolete Windows ThinLTO+TLS workaround)
 - rust-lang#137204 (Clarify MIR dialects and phases)
 - rust-lang#137299 (Simplify `Postorder` customization.)
 - rust-lang#137302 (Use a probe to avoid registering stray region obligations when re-checking drops in MIR typeck)
 - rust-lang#137305 (Tweaks in and around `rustc_middle`)
 - rust-lang#137313 (Some codegen_llvm cleanups)
 - rust-lang#137333 (Use `edition = "2024"` in the compiler (redux))

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: aarch64-gnu
try-job: armhf-gnu
try-job: i686-mingw-1
try-job: i686-mingw-2
try-job: i686-mingw-3
try-job: test-various
try-job: x86_64-gnu-nopt
try-job: x86_64-msvc-1
try-job: x86_64-msvc-2
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 21, 2025
…kingjubilee

Rollup of 10 pull requests

Successful merges:

 - rust-lang#128080 (Specify scope in `out_of_scope_macro_calls` lint)
 - rust-lang#135630 (add more `s390x` target features)
 - rust-lang#136089 (Reduce `Box::default` stack copies in debug mode)
 - rust-lang#137192 (Remove obsolete Windows ThinLTO+TLS workaround)
 - rust-lang#137204 (Clarify MIR dialects and phases)
 - rust-lang#137299 (Simplify `Postorder` customization.)
 - rust-lang#137302 (Use a probe to avoid registering stray region obligations when re-checking drops in MIR typeck)
 - rust-lang#137305 (Tweaks in and around `rustc_middle`)
 - rust-lang#137313 (Some codegen_llvm cleanups)
 - rust-lang#137333 (Use `edition = "2024"` in the compiler (redux))

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 21, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#128080 (Specify scope in `out_of_scope_macro_calls` lint)
 - rust-lang#135630 (add more `s390x` target features)
 - rust-lang#136089 (Reduce `Box::default` stack copies in debug mode)
 - rust-lang#137204 (Clarify MIR dialects and phases)
 - rust-lang#137299 (Simplify `Postorder` customization.)
 - rust-lang#137302 (Use a probe to avoid registering stray region obligations when re-checking drops in MIR typeck)
 - rust-lang#137305 (Tweaks in and around `rustc_middle`)
 - rust-lang#137313 (Some codegen_llvm cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 12e6b48 into rust-lang:master Feb 21, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Feb 21, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 21, 2025
Rollup merge of rust-lang#128080 - estebank:out-of-scope-macro, r=petrochenkov

Specify scope in `out_of_scope_macro_calls` lint

```
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
```

r? ```@petrochenkov```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants