Skip to content

Warnings in code generated by proc_macro_derive should be on derive() attr #37563

Closed
@SimonSapin

Description

@SimonSapin

… not on the type definition.

This warning started appearing in Servo recently:

warning: unreachable expression, #[warn(unreachable_code)] on by default
   --> /home/simon/projects/servo1/components/script_traits/lib.rs:403:1
    |
403 | pub enum Milliseconds {}
    | ^^^^^^^^^^^^^^^^^^^^^^^^

warning: unreachable expression, #[warn(unreachable_code)] on by default
   --> /home/simon/projects/servo1/components/script_traits/lib.rs:406:1
    |
406 | pub enum Nanoseconds {}
    | ^^^^^^^^^^^^^^^^^^^^^^^

It turns out that these types have #[derive(Clone, Copy, HeapSizeOf)], with a dependency defining #[proc_macro_derive(HeapSizeOf)]. The warning is in code generated by this macro.

But at first I couldn’t figure it out. I had to ask on IRC and sfackler suggested it could be generated code.

It would have helped if the span of the error was not on the type definition, but on the attribute that caused code to be generated in the first place. Something like this:

405 | #[derive(Clone, Copy, HeapSizeOf)]
    |                       ^^^^^^^^^^

The error message could also mention macros or generated code, like "unreachable expression in expansion of derive_HeapSizeOf".

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions