Skip to content

Spurious legacy_derive_helpers lint when unrelated attribute fails to resolve #81871

Closed
@Aaron1011

Description

@Aaron1011

The following code:

// src/lib.rs
use proc_macro::{TokenStream};

#[proc_macro_derive(MyDerive, attributes(my_helper))]
pub fn my_derive(_target: TokenStream) -> TokenStream {
    TokenStream::new()
}


// src/main.rs

#![dummy]

use derive_helper::*;

#[derive(MyDerive)]
#[my_helper]
struct Foo {}

fn main() {}

produces the following errors:

error: cannot find attribute `dummy` in this scope
 --> src/main.rs:1:4
  |
1 | #![dummy]
  |    ^^^^^

error: cannot determine resolution for the attribute macro `derive`
 --> src/main.rs:5:3
  |
5 | #[derive(MyDerive)]
  |   ^^^^^^
  |
  = note: import resolution is stuck, try simplifying macro imports

error: cannot determine resolution for the derive macro `MyDerive`
 --> src/main.rs:5:10
  |
5 | #[derive(MyDerive)]
  |          ^^^^^^^^
  |
  = note: import resolution is stuck, try simplifying macro imports

error: cannot determine resolution for the attribute macro `my_helper`
 --> src/main.rs:6:3
  |
6 | #[my_helper]
  |   ^^^^^^^^^
  |
  = note: import resolution is stuck, try simplifying macro imports

warning: derive helper attribute `my_helper` is used before it is introduced
 --> src/main.rs:6:3
  |
5 | #[derive(MyDerive)]
  |          -------- the attribute is introduced here
6 | #[my_helper]
  |   ^^^^^^^^^
  |
  = note: `#[warn(legacy_derive_helpers)]` on by default
  = 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 #79202 <https://github.com/rust-lang/rust/issues/79202>

error: aborting due to 4 previous errors; 1 warning emitted

The legacy_derive_helpers warning is spurious and will disappear if #![dummy] is removed.

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions