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
I decided you're right, we ought to try &'static T as possessing the static bound for all T, since there are already other parts of the type system that rely on the fact that for all &'foo T, T cannot have region pointers that have shorter lifetime than 'foo
Here is a testcase for putting &'static fn() closures into trait objects. Of course sendable closures are also interesting (do we have to use extern fn for that?).
/*
error: cannot pack type `~Test`, which does not fulfill `'static`, as a trait bounded by 'static
let trait_obj = (~t) as ~EvalOnce:'static;
^~~~~~~~~~~~~~~~~~~~~~~~~
*/
struct Test {
f: &'static fn:'static(),
}
trait EvalOnce {
fn eval(~self);
}
impl EvalOnce for Test {
fn eval(~self) {
(self.f)();
}
}
fn test_me() {
let t: Test = Test { f: || { } };
let trait_obj = (~t) as ~EvalOnce:'static;
}
@nikomatsakis the natural generalization here, assuming we finish #5121 by allowing lifetime kind bounds other than 'static, is that fn foo<T:'b>(x: &'a T) { ... } would imply that actually T: 'a + 'b, right?
Activity
nikomatsakis commentedon Jun 21, 2013
no bug. The type parameter
T
could contain borrowed pointers, as the error message correctly pointed out. You want:bblum commentedon Jun 22, 2013
Not to mean this should change, but it should also be impossible to (safely) construct a
&'static &'r T
, right?nikomatsakis commentedon Jun 23, 2013
That is true.
nikomatsakis commentedon Jun 28, 2013
I decided you're right, we ought to try
&'static T
as possessing the static bound for all T, since there are already other parts of the type system that rely on the fact that for all&'foo T
, T cannot have region pointers that have shorter lifetime than'foo
bluss commentedon Jul 2, 2013
Here is a testcase for putting &'static fn() closures into trait objects. Of course sendable closures are also interesting (do we have to use extern fn for that?).
msullivan commentedon Aug 23, 2013
Seconding the nomination for feature complete, I suppose?
catamorphism commentedon Sep 5, 2013
accepted for production-ready
pnkfelix commentedon Mar 20, 2014
Could be added backwards-compatibly in the future. Assigning P-low, not 1.0 blocker.
pnkfelix commentedon Mar 24, 2014
@nikomatsakis the natural generalization here, assuming we finish #5121 by allowing lifetime kind bounds other than
'static
, is thatfn foo<T:'b>(x: &'a T) { ... }
would imply that actuallyT: 'a + 'b
, right?'static
kind bound. #13113'static
. #15423Auto merge of rust-lang#7268 - mbartlett21:update_semi, r=Manishearth