This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -195,3 +195,18 @@ fn shared_from_iter_trustedlen_no_fuse() {
195195 assert_trusted_len ( & iter) ;
196196 assert_eq ! ( & [ Box :: new( 42 ) , Box :: new( 24 ) ] , & * iter. collect:: <Rc <[ _] >>( ) ) ;
197197}
198+
199+ #[ test]
200+ fn weak_may_dangle ( ) {
201+ fn hmm < ' a > ( val : & ' a mut Weak < & ' a str > ) -> Weak < & ' a str > {
202+ val. clone ( )
203+ }
204+
205+ // Without #[may_dangle] we get:
206+ let mut val = Weak :: new ( ) ;
207+ hmm ( & mut val) ;
208+ // ~~~~~~~~ borrowed value does not live long enough
209+ //
210+ // `val` dropped here while still borrowed
211+ // borrow might be used here, when `val` is dropped and runs the `Drop` code for type `std::sync::Weak`
212+ }
Original file line number Diff line number Diff line change @@ -191,3 +191,18 @@ fn shared_from_iter_trustedlen_no_fuse() {
191191 assert_trusted_len ( & iter) ;
192192 assert_eq ! ( & [ Box :: new( 42 ) , Box :: new( 24 ) ] , & * iter. collect:: <Rc <[ _] >>( ) ) ;
193193}
194+
195+ #[ test]
196+ fn weak_may_dangle ( ) {
197+ fn hmm < ' a > ( val : & ' a mut Weak < & ' a str > ) -> Weak < & ' a str > {
198+ val. clone ( )
199+ }
200+
201+ // Without #[may_dangle] we get:
202+ let mut val = Weak :: new ( ) ;
203+ hmm ( & mut val) ;
204+ // ~~~~~~~~ borrowed value does not live long enough
205+ //
206+ // `val` dropped here while still borrowed
207+ // borrow might be used here, when `val` is dropped and runs the `Drop` code for type `std::rc::Weak`
208+ }
You can’t perform that action at this time.
0 commit comments