You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use fallible_collections::btree::BTreeMap;fnmain(){letmut map;let s = "...".to_owned();
map = BTreeMap::<&str,&str>::new();
map.try_insert(&s,&s).unwrap();// s is dropped// then map is dropped}
However, that ends up materializing a (&'dangling str, &'dangling str) as part of doing self.for_each(drop). As I understand it, it's UB to touch/pass/return dangling references like that by value.
The text was updated successfully, but these errors were encountered:
Based on rust-lang/unsafe-code-guidelines#283 I believe the following code illustrates UB:
The drop of
map
is running this Drop impl:fallible_collections/src/btree/map.rs
Lines 129 to 135 in 2742886
Based on the IntoIterator impl for BTreeMap, that's converting
BTreeMap<&'dangling str, &'dangling str>
intoIntoIter<&'dangling str, &'dangling str>
:fallible_collections/src/btree/map.rs
Lines 1350 to 1352 in 2742886
and dropping the IntoIter using this impl:
fallible_collections/src/btree/map.rs
Lines 1368 to 1370 in 2742886
However, that ends up materializing a
(&'dangling str, &'dangling str)
as part of doingself.for_each(drop)
. As I understand it, it's UB to touch/pass/return dangling references like that by value.The text was updated successfully, but these errors were encountered: