File tree 2 files changed +30
-0
lines changed
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() {
195
195
assert_trusted_len ( & iter) ;
196
196
assert_eq ! ( & [ Box :: new( 42 ) , Box :: new( 24 ) ] , & * iter. collect:: <Rc <[ _] >>( ) ) ;
197
197
}
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() {
191
191
assert_trusted_len ( & iter) ;
192
192
assert_eq ! ( & [ Box :: new( 42 ) , Box :: new( 24 ) ] , & * iter. collect:: <Rc <[ _] >>( ) ) ;
193
193
}
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