rust/library/alloc
bors 47a90f4520 Auto merge of #85535 - dtolnay:weakdangle, r=kennytm
Weak's type parameter may dangle on drop

Way back in 34076bc0c9, #\[may_dangle\] was added to Rc\<T\> and Arc\<T\>'s Drop impls. That appears to have been because a test added in #28929 used Arc and Rc with dangling references at drop time. However, Weak was not covered by that test, and therefore no #\[may_dangle\] was forced to be added at the time.

As far as dropping, Weak has *even less need* to interact with the T than Rc and Arc do. Roughly speaking #\[may_dangle\] describes generic parameters that the outer type's Drop impl does not interact with except by possibly dropping them; no other interaction (such as trait method calls on the generic type) is permissible. It's clear this applies to Rc's and Arc's drop impl, which sometimes drop T but otherwise do not interact with one. It applies *even more* to Weak. Dropping a Weak cannot ever cause T's drop impl to run. Either there are strong references still in existence, in which case better not drop the T. Or there are no strong references still in existence, in which case the T would already have been dropped previously by the drop of the last strong count.
2021-05-26 01:17:02 +00:00
..
benches remove InPlaceIterable marker from Peekable due to unsoundness 2021-05-19 01:41:09 +02:00
src Auto merge of #85535 - dtolnay:weakdangle, r=kennytm 2021-05-26 01:17:02 +00:00
tests Add Weak may_dangle tests 2021-05-20 19:42:29 -07:00
Cargo.toml Add support for const operands and options to global_asm! 2021-05-13 22:31:57 +01:00