Skip to content

Add check for invalid #[macro_export] arguments #107911

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Feb 26, 2023
Merged

Add check for invalid #[macro_export] arguments #107911

merged 1 commit into from
Feb 26, 2023

Conversation

blyxyas
Copy link
Member

@blyxyas blyxyas commented Feb 10, 2023

Resolves #107231
Sorry if I made something wrong, this is my first contribution to the repo.

@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2023

r? @TaKO8Ki

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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 Feb 10, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2023

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @TaKO8Ki

@blyxyas blyxyas changed the title [#107231] Fix issue [#107231] Fix #[macro_export(invalid, arguments)] issue Feb 10, 2023
@compiler-errors
Copy link
Member

compiler-errors commented Feb 10, 2023

two things about the title - 1. it doesn't need the issue number in the title, and 2. can you make it more "functional"? like, what does it do? e.g. "add a check for invalid macro_export arguments" or something.

@blyxyas blyxyas changed the title [#107231] Fix #[macro_export(invalid, arguments)] issue Add check for invalid #[macro_export] arguments Feb 10, 2023
@rust-log-analyzer

This comment has been minimized.

///
pub INVALID_MACRO_EXPORT_ARGUMENTS,
Deny,
"There aren't any attributes named \"invalid_parameters\"",
Copy link
Member

Choose a reason for hiding this comment

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

Why does this message reference "invalid_parameters"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

attr.span,
errors::MacroExport::Normal,
);
} else if let Some(meta_item_list) = attr.meta_item_list() {
Copy link
Member

Choose a reason for hiding this comment

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

What if it's a #[macro_export = ".."]?

Copy link
Member Author

Choose a reason for hiding this comment

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

When testing this:

error: malformed `macro_export` attribute input
  --> fake-test-src-base/invalid_macro_export_argument.rs:31:1
   |
LL | #[macro_export = "Not a valid value"] //~ WARN `not_local_inner_macros` isn't a valid `#[macro_export]` argument
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |

It seems like Rust already gives an error in that case.When testing this:

error: malformed `macro_export` attribute input
  --> fake-test-src-base/invalid_macro_export_argument.rs:31:1
   |
LL | #[macro_export = "Not a valid value"] //~ WARN `not_local_inner_macros` isn't a valid `#[macro_export]` argument
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |

It seems like Rust already gives an error in that case.

///
///
pub INVALID_MACRO_EXPORT_ARGUMENTS,
Deny,
Copy link
Member

Choose a reason for hiding this comment

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

This needs to start out at a warn level, not Deny, or else it'll break a bunch of crates that are using this incorrectly currently.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok
Does this need a future incompatible warn?

Copy link
Member

Choose a reason for hiding this comment

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

That can be added in a follow-up

@blyxyas
Copy link
Member Author

blyxyas commented Feb 14, 2023

The code is all fixed, but testing gives an error and I don't know why. The stderr doesn't show any diff and cannot see what I'm doing wrong.

With these input: TESTNAME="invalid_macro_export_argument" x test tests/ui
it gives the following output:

Output
failures:

---- [ui] tests/ui/invalid_macro_export_argument.rs stdout ----

error: ui test compiled successfully!
status: exit status: 0
command: "/home/alejandra/git/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "/home/alejandra/git/rust/tests/ui/invalid_macro_export_argument.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--remap-path-prefix=/home/alejandra/git/rust/tests/ui=fake-test-src-base" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/home/alejandra/git/rust/build/x86_64-unknown-linux-gnu/test/ui/invalid_macro_export_argument" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/home/alejandra/git/rust/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/home/alejandra/git/rust/build/x86_64-unknown-linux-gnu/test/ui/invalid_macro_export_argument/auxiliary"
stdout: none
--- stderr -------------------------------
warning: `#[macro_export]` can only take 1 or 0 arguments
  --> fake-test-src-base/invalid_macro_export_argument.rs:1:1
   |
LL | #[macro_export(hello, world)] //~ WARN `#[macro_export]` can only take 1 or 0 arguments
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(invalid_macro_export_arguments)]` on by default

warning: `not_local_inner_macros` isn't a valid `#[macro_export]` argument
  --> fake-test-src-base/invalid_macro_export_argument.rs:6:16
   |
LL | #[macro_export(not_local_inner_macros)] //~ WARN `not_local_inner_macros` isn't a valid `#[macro_export]` argument
   |                ^^^^^^^^^^^^^^^^^^^^^^

warning: 2 warnings emitted
------------------------------------------



failures:
    [ui] tests/ui/invalid_macro_export_argument.rs

test result: FAILED. 4 passed; 1 failed; 14429 ignored; 0 measured; 0 filtered out; finished in 0.23s

Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
Build completed unsuccessfully in 0:00:02

The lint level has been changed to a Warn level, so I changed //~ ERROR to //~ WARN and it still gives me an error (without any diffs).

Is there something that I'm doing wrong?

@compiler-errors
Copy link
Member

If you make it a warning, then you need to mark the test with // check-pass, or else we expect a failure. You can also just add a #![deny(invalid_macro_export_arguments)] to make them into an error just for your UI test.

@compiler-errors compiler-errors 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 14, 2023
@blyxyas
Copy link
Member Author

blyxyas commented Feb 16, 2023

@rustbot label: -S-waiting-on-author +S-waiting-on-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 Feb 16, 2023
@compiler-errors
Copy link
Member

Can you squash these into one commit? I think this is ready to go after that.

@compiler-errors
Copy link
Member

Whoops, sorry, forgot to approve.

r? @compiler-errors @bors r+

@bors
Copy link
Collaborator

bors commented Feb 22, 2023

📌 Commit 05838b5 has been approved by compiler-errors

It is now in the queue for this repository.

@rustbot rustbot assigned compiler-errors and unassigned TaKO8Ki Feb 22, 2023
@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 22, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 22, 2023
…er-errors

Add check for invalid #[macro_export] arguments

Resolves rust-lang#107231
Sorry if I made something wrong, this is my first contribution to the repo.
@blyxyas
Copy link
Member Author

blyxyas commented Feb 22, 2023

@rustbot label: -T-bootstrap

@rustbot rustbot added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) and removed T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Feb 22, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 22, 2023

Some changes occurred in src/tools/cargo

cc @ehuss

@blyxyas
Copy link
Member Author

blyxyas commented Feb 22, 2023

@rustbot label: -T-bootstrap
Sorry to Eric Huss for the mention. Im fighting with Git right now trying to resolve the conflict.

@rustbot rustbot removed the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Feb 22, 2023
@compiler-errors
Copy link
Member

@blyxyas, I can push to your branch and rebase this if you're having trouble.

@blyxyas
Copy link
Member Author

blyxyas commented Feb 22, 2023

I'd appreciate that a lot. Thanks

@compiler-errors
Copy link
Member

I'll wait for CI to check this PR, then I can re-approve.

In the future, git pull --rebase origin master (or instead of origin, whatever your remote for rust-lang/rust.git is called) is the easiest way to rebase past things like this. Submodules can be a pain though.

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Feb 23, 2023

📌 Commit e39fe37 has been approved by compiler-errors

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 23, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 23, 2023
…er-errors

Add check for invalid #[macro_export] arguments

Resolves rust-lang#107231
Sorry if I made something wrong, this is my first contribution to the repo.
@compiler-errors
Copy link
Member

@bors rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 25, 2023
…mpiler-errors

Rollup of 7 pull requests

Successful merges:

 - rust-lang#105736 (Test that the compiler/library builds with validate-mir)
 - rust-lang#107291 ([breaking change] Remove a rustdoc back compat warning)
 - rust-lang#107675 (Implement -Zlink-directives=yes/no)
 - rust-lang#107848 (Split `x setup` sub-actions to CLI arguments)
 - rust-lang#107911 (Add check for invalid #[macro_export] arguments)
 - rust-lang#108229 ([107049] Recognise top level keys in config.toml.example)
 - rust-lang#108333 (Make object bound candidates sound in the new trait solver)

Failed merges:

 - rust-lang#108337 (hir-analysis: make a helpful note)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit cf049ac into rust-lang:master Feb 26, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 26, 2023
ZhongRuoyu added a commit to ZhongRuoyu/tremor-runtime that referenced this pull request May 1, 2023
This fixes build failure with Rust 1.69+. According to [^1], "the only
valid argument is `#[macro_export(local_inner_macros)]` or no argument
(`#[macro_export]`)".

The check for invalid `#[macro_export]` arguments was added in
rust-lang/rust#107911 and first released in Rust 1.69.0.

[^1]: https://github.com/rust-lang/rust/blob/1.69.0/compiler/rustc_lint_defs/src/builtin.rs#L4129

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
Licenser pushed a commit to tremor-rs/tremor-runtime that referenced this pull request May 1, 2023
This fixes build failure with Rust 1.69+. According to [^1], "the only
valid argument is `#[macro_export(local_inner_macros)]` or no argument
(`#[macro_export]`)".

The check for invalid `#[macro_export]` arguments was added in
rust-lang/rust#107911 and first released in Rust 1.69.0.

[^1]: https://github.com/rust-lang/rust/blob/1.69.0/compiler/rustc_lint_defs/src/builtin.rs#L4129

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
Licenser pushed a commit to tremor-rs/tremor-runtime that referenced this pull request May 2, 2023
This fixes build failure with Rust 1.69+. According to [^1], "the only
valid argument is `#[macro_export(local_inner_macros)]` or no argument
(`#[macro_export]`)".

The check for invalid `#[macro_export]` arguments was added in
rust-lang/rust#107911 and first released in Rust 1.69.0.

[^1]: https://github.com/rust-lang/rust/blob/1.69.0/compiler/rustc_lint_defs/src/builtin.rs#L4129

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
fnasraoui pushed a commit to fnasraoui/tremor-runtime that referenced this pull request May 5, 2023
This fixes build failure with Rust 1.69+. According to [^1], "the only
valid argument is `#[macro_export(local_inner_macros)]` or no argument
(`#[macro_export]`)".

The check for invalid `#[macro_export]` arguments was added in
rust-lang/rust#107911 and first released in Rust 1.69.0.

[^1]: https://github.com/rust-lang/rust/blob/1.69.0/compiler/rustc_lint_defs/src/builtin.rs#L4129

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
Signed-off-by: fn500i <fnasraoui@wayfair.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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.

#[macro_export(hello, world)]
7 participants