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
Implied bounds from non-static T in Parc<T>::project
use pared::sync::Parc;fnmain(){let s = "Hello World!".to_owned();let x = Parc::new(&());let x = x.project(|_| s.as_str());// why this works?// even though there are seemingly so many// 'static bounds already?// here's a short explanation:// it first coerces the Parc<&'static ()> to some Parc<&'short ()>,// and then the callback to project, for<'a> FnOnce(&'a &'short ()) -> &'a str// is only required to be able to handle any lifetime `'a` with `'short: 'a`// which is fine as long as `'short` is shorter than up to the point `s` dropsprintln!("{:?}",&*x);// "Hello World!"drop(s);println!("{:?}",&*x);// garbage / use-after-free}
A possible fix I could imagine is adding T: 'static to project.
Dropping of non-'static content through Parc::from_arc
This is probably just clearly missing the U: 'static, since… this just works:
use pared::sync::Parc;use std::sync::Arc;structPrintOnDrop<'a>(&'astr);implDropforPrintOnDrop<'_>{fndrop(&mutself){println!("dropping: {:?}",self.0);}}fnmain(){let s = "Hello World!".to_owned();let arc = Arc::new(PrintOnDrop(&s));let p = Parc::from_arc(&arc, |_| &());drop(arc);drop(s);// finallydrop(p);// garbage / use-after-free// type being Parc<()> means this is a type// that doesn't have any lifetime restrictions anymore// i.e. this can still be used/dropped AFTER `s` is gone,// without complaints from the compiler}
The same applies to Prc and to try_ variants of the APIs.
The text was updated successfully, but these errors were encountered:
Implied bounds from non-static
T
inParc<T>::project
A possible fix I could imagine is adding
T: 'static
toproject
.This issue is – very roughly – inspired by Kimundi/owning-ref-rs#71
Dropping of non-
'static
content throughParc::from_arc
This is probably just clearly missing the
U: 'static
, since… this just works:The same applies to
Prc
and totry_
variants of the APIs.The text was updated successfully, but these errors were encountered: