Skip to content

Deriving zeroize::Zeroize requires the Zeroize trait to already be in scope #1271

@LikeLakers2

Description

@LikeLakers2

Hi, while trying to add zeroize support to a crate I'm making, I found that I was getting a weird error about the Zeroize trait not being in scope:

error[E0405]: cannot find trait `Zeroize` in this scope
  --> src\lib.rs:13:40
   |
13 | #[cfg_attr(feature = "zeroize", derive(zeroize::Zeroize))]
   |                                        ^^^^^^^^^^^^^^^^ not found in this scope
   |
   = note: this error originates in the derive macro `zeroize::Zeroize` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this trait
   |
 3 + use zeroize::Zeroize;
   |

Here's a minimal reproduction (unfortunately I can't send a playground link, since the playground doesn't provide the zeroize derives):

#[derive(zeroize::Zeroize)]
struct A;

The fix is relatively simple:

use zeroize::Zeroize;

#[derive(zeroize::Zeroize)]
struct A;

though having a trait in scope solely for a derive feels... wrong.

I will note that serde is able to derive without its relevant traits in scope:

#[derive(serde::Serialize, serde::Deserialize)]
struct A;

So perhaps zeroize should be changed to do the same?

Thank you for your time, and hopefully this is a relatively easy fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions