Skip to content

Commit cec05d8

Browse files
authored
Rollup merge of rust-lang#157479 - JonathanBrouwer:macro-use-root, r=Kivooeo
Warn when `#[macro_use]` or `#[macro_escape]` is used on the crate root Fixes rust-lang#157250
2 parents 14ee503 + 0071bd1 commit cec05d8

10 files changed

Lines changed: 272 additions & 238 deletions

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const MACRO_USE_TEMPLATE: AttributeTemplate = template!(
3535
const MACRO_USE_ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
3636
Allow(Target::Mod),
3737
Allow(Target::ExternCrate),
38-
Allow(Target::Crate),
3938
Error(Target::WherePredicate),
4039
]);
4140

tests/ui/attributes/attr-on-mac-call.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ warning: `#[macro_use]` attribute cannot be used on macro calls
173173
LL | #[macro_use]
174174
| ^^^^^^^^^^^^
175175
|
176-
= help: `#[macro_use]` can be applied to crates, extern crates, and modules
176+
= help: `#[macro_use]` can be applied to extern crates and modules
177177
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
178178

179179
warning: `#[must_use]` attribute cannot be used on macro calls

tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
#![allow(x5300)] //~ WARN unknown lint: `x5300`
4343
#![forbid(x5200)] //~ WARN unknown lint: `x5200`
4444
#![deny(x5100)] //~ WARN unknown lint: `x5100`
45-
#![macro_use] // (allowed if no argument; see issue-43160-gating-of-macro_use.rs)
45+
#![macro_use] //~ WARN attribute cannot be used on
46+
//~| WARN previously accepted
47+
//~| HELP can be applied to
48+
//~| HELP remove the attribute
4649
// skipping testing of cfg
4750
// skipping testing of cfg_attr
4851
#![should_panic] //~ WARN attribute cannot be used on

0 commit comments

Comments
 (0)