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

New lint: using #[macro_use] instead of a use statement #5179

Closed
Aaron1011 opened this issue Feb 16, 2020 · 2 comments · Fixed by #5230
Closed

New lint: using #[macro_use] instead of a use statement #5179

Aaron1011 opened this issue Feb 16, 2020 · 2 comments · Fixed by #5230
Labels
A-lint Area: New lints E-hard Call for participation: This a hard problem and requires more experience or effort to work on good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions T-macros Type: Issues with macros and macro expansion

Comments

@Aaron1011
Copy link
Member

Aaron1011 commented Feb 16, 2020

In the Rust 2018 edition, you can directly import exported macros via a normal use statement, instead of using the blanket #[macro_use] attribute. This makes it clear exactly which items you are importing, and avoids the need to use extern crate.

As far as I know, there are no cases where #[macro_use] works but use some_crate::some_macro doesn't.

@flip1995 flip1995 added E-hard Call for participation: This a hard problem and requires more experience or effort to work on good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints T-macros Type: Issues with macros and macro expansion labels Feb 16, 2020
@flip1995
Copy link
Member

good first issue: just warning on #[macro_use] use ...;

Hard: finding the macros used by the import, and building an auto applicable suggestion.

@flip1995 flip1995 added the L-suggestion Lint: Improving, adding or fixing lint suggestions label Feb 16, 2020
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Feb 26, 2020
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Feb 26, 2020
@DevinR528 DevinR528 mentioned this issue Feb 26, 2020
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Feb 27, 2020
@SOF3
Copy link

SOF3 commented Mar 2, 2020

One known case is diesel. The code generated by diesel macros assume that all diesel macros have been brought into scope, and would generate something like #[derive(Identifiable)] instead of #[derive(diesel::Identifiable)].

Nevertheless, personally I (and probably other people too) would create a subcrate in the workspace only for the diesel schema, so as not to corrupt my symbol scope with diesel derive macros, and it is obvious not to use this clippy lint in such a schema subcrate. So, this is probably not a critical problem.

DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Mar 2, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Mar 2, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Mar 3, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
bors added a commit that referenced this issue Mar 3, 2020
Macro use

---

changelog: This lint enforces Rust 2018 idiom of importing macro's directly without `#[macro_use]` fixes #5179 .
bors added a commit that referenced this issue Mar 4, 2020
Macro use

---

changelog: This lint enforces Rust 2018 idiom of importing macro's directly without `#[macro_use]` fixes #5179 .
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Mar 4, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
bors added a commit that referenced this issue Mar 5, 2020
Macro use

---

changelog: This lint enforces Rust 2018 idiom of importing macro's directly without `#[macro_use]` fixes #5179 .
@bors bors closed this as completed in 23d2b21 Mar 5, 2020
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Mar 5, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Mar 11, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Mar 18, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Mar 24, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Apr 3, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Apr 10, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Apr 16, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Apr 19, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Apr 20, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Apr 21, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
DevinR528 added a commit to DevinR528/rust-clippy that referenced this issue Apr 27, 2020
cargo dev update lints

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

warn on macro_use attr (issue rust-lang#5179)

fixed suggestion, check edition, ran `tests/ui/update-all-references.sh`

fixed failing tests with update-references.sh

update-references.sh for missing-doc-impl.rs

use if_chain

cargo dev fmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints E-hard Call for participation: This a hard problem and requires more experience or effort to work on good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants