PhantomData question


#1

an example from rust docs mentions PhantomData type:

use std::marker::PhantomData;

struct Slice<'a, T: 'a> {
    start: *const T,
    end: *const T,
    phantom: PhantomData<&'a T>,
}

but what should I do if I have a struct that is not parametrized by a type?

struct MutProbeVisitor<'a, 'tcx: 'a> {
    input_types: Vec<Ty<'tcx>>,
    phantom: PhantomData<'a>
}

in that case rust complain about missing type parameter for PhantomData.
Without PhantomData, it complains about unused lifetime. Without lifetime things don’t live long enough.

Is there a solution for that?


#2

Perhaps

struct MutProbeVisitor<'a, 'tcx: 'a> {
    input_types: Vec<Ty<'tcx>>,
    phantom: PhantomData<&'a ()>
}

#3

Of course. Thanks.