nrc / derive-new

derive simple constructor functions for Rust structs
MIT License
525 stars 35 forks source link

`PhantomData` detection is brittle #34

Open eira-fransham opened 6 years ago

eira-fransham commented 6 years ago

Currently it will generate false positives on cases like:

struct PhantomData;

#[derive(new)]
struct Foo { bar: PhantomData }

and false negatives on cases like:

use std::marker::PhantomData as PD;

#[derive(new)]
struct Foo { bar: PD }
Lucretiel commented 2 years ago

Unfortunately, this isn't possible to solve with a proc macro. Proc macros run before any useful type information is available, so the only thing they have to go on is the actual type names that are present in the definition of the decorated type.