@@ -35,6 +35,7 @@ declare_lint_pass! {
3535 DEPRECATED_IN_FUTURE ,
3636 DEPRECATED_SAFE_2024 ,
3737 DEPRECATED_WHERE_CLAUSE_LOCATION ,
38+ DERIVE_HELPER_CLASHES_WITH_BUILTIN_ATTR ,
3839 DUPLICATE_MACRO_ATTRIBUTES ,
3940 ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT ,
4041 ELIDED_LIFETIMES_IN_PATHS ,
@@ -4237,6 +4238,75 @@ declare_lint! {
42374238 } ;
42384239}
42394240
4241+ declare_lint ! {
4242+ /// The `derive_helper_clashes_with_builtin_attr` lint detects cases where a derive macro's helper attribute
4243+ /// is the same name as that of a built-in attribute.
4244+ ///
4245+ /// ### Example
4246+ ///
4247+ /// ```rust,ignore (proc-macro)
4248+ /// #![crate_type = "proc-macro"]
4249+ /// #![deny(derive_helper_clashes_with_builtin_attr)]
4250+ ///
4251+ /// use proc_macro::TokenStream;
4252+ ///
4253+ /// #[proc_macro_derive(Trait, attributes(ignore))]
4254+ /// pub fn example(input: TokenStream) -> TokenStream {
4255+ /// TokenStream::new()
4256+ /// }
4257+ /// ```
4258+ ///
4259+ /// Produces:
4260+ ///
4261+ /// ```text
4262+ /// error: there exists a built-in attribute with the same name
4263+ /// --> file.rs:5:39
4264+ /// |
4265+ /// 5 | #[proc_macro_derive(Trait, attributes(ignore))]
4266+ /// | ^^^^^^
4267+ /// |
4268+ /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4269+ /// = note: for more information, see issue #0 <https://github.com/rust-lang/rust/issues/0>
4270+ /// = note: `#[deny(derive_helper_clashes_with_builtin_attr)]` (part of `#[deny(future_incompatible)]`) on by default
4271+ /// ```
4272+ ///
4273+ /// ### Explanation
4274+ ///
4275+ /// Attempting to use this helper attribute will throw an error:
4276+ ///
4277+ /// ```rust,ignore (needs-dependency)
4278+ /// #[derive(Trait)]
4279+ /// struct Example {
4280+ /// #[ignore]
4281+ /// fields: ()
4282+ /// }
4283+ /// ```
4284+ ///
4285+ /// Produces:
4286+ ///
4287+ /// ```text
4288+ /// error[E0659]: `ignore` is ambiguous
4289+ /// --> src/lib.rs:5:7
4290+ /// |
4291+ /// 5 | #[ignore]
4292+ /// | ^^^^^^ ambiguous name
4293+ /// |
4294+ /// = note: ambiguous because of a name conflict with a builtin attribute
4295+ /// = note: `ignore` could refer to a built-in attribute
4296+ /// note: `ignore` could also refer to the derive helper attribute defined here
4297+ /// --> src/lib.rs:3:10
4298+ /// |
4299+ /// 3 | #[derive(Trait)]
4300+ /// | ^^^^^
4301+ /// ```
4302+ pub DERIVE_HELPER_CLASHES_WITH_BUILTIN_ATTR ,
4303+ Deny ,
4304+ "same as a built-in attribute" ,
4305+ @future_incompatible = FutureIncompatibleInfo {
4306+ reason: fcw!( FutureReleaseError #0 ) ,
4307+ } ;
4308+ }
4309+
42404310declare_lint ! {
42414311 /// The `private_interfaces` lint detects types in a primary interface of an item,
42424312 /// that are more private than the item itself. Primary interface of an item is all
0 commit comments