Open crepererum opened 2 years ago
AFAIK this is intended, the lifetime is only required to outlive the last use of the value containing it, and in your example the PhantomData
is not used anymore after s.create_ref()
. This see through fields unless the type implements Drop
, which is why implementing Drop
for Ref
changes the behaviour.
This see through fields unless the type implements
Drop
Is this documented somewhere? (I guess so, but I'm failing to find it or to know what to search for)
I tried this code:
(Playground link)
I expected to see this happen:
It fails to compile because we hold a mutable reference to
s
and calluse_it
.Instead, this happened:
It compiles and the output is:
Meta
Happens on both stable (currently
1.63.0
) and nightly (currently1.65.0-nightly (2022-08-14 801821d1560f84e4716f)
)Explanation
You might wonder why someone would build such a construct: In the actual code the
DropTester
is aparking_lot
ArcMutexGuard
that provides access to some internal field (owned byS
) and I've tried to use lifetimes to avoid that someone would hold the reference wrapper (Ref
) while using some other methods onS
.