Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no way to `unsafe impl` `'static` #31196

Closed
reem opened this Issue Jan 26, 2016 · 6 comments

Comments

Projects
None yet
4 participants
@reem
Copy link
Contributor

reem commented Jan 26, 2016

This would be extremely useful when using invariant lifetimes as a marker for e.g. safe unchecked indexing, it would be nice to be able to say unsafe impl<'id> 'static for InvariantLifetime<'id> {} (where InvariantLifetime<'a> is PhantomData<fn(&'a ()) -> &'a ()>).

@reem

This comment has been minimized.

Copy link
Contributor Author

reem commented Jan 26, 2016

I am not sure if this is at all feasible, if it's completely bonkers feel free to close.

@huonw

This comment has been minimized.

Copy link
Member

huonw commented Jan 26, 2016

This feels somewhat crazy, but it'd be oh-so-useful: I've had to box things behind trait objects just so that I can erase the lifetime (transmuting Box<Trait + 'a> to Box<Trait + 'static>) for cases when I'm guaranteeing lifetime correctness in some external way.

cc @rust-lang/lang

@reem

This comment has been minimized.

Copy link
Contributor Author

reem commented Jan 26, 2016

If we had 'anonymous/injected type parameter which doesn't unify with anything but itself' as a native part of the type system, it would also solve this problem (using lifetimes for this is admittedly a hack).

@huonw

This comment has been minimized.

Copy link
Member

huonw commented Jan 26, 2016

That solves using lifetimes as a tag, but not having to (ab)use trait objects to force things to be 'static (unlike the marker traits).

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jan 26, 2016

This is currently dangerous because rustc assumes that every lifetime that is :'static equals 'static. Also, this would be very dangerous with Any.

@aturon aturon removed the I-nominated label Jan 30, 2016

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Jan 30, 2016

The lang team discussed this issue, and felt that while there are plausible motivations for the feature, there are also significant dangers. We would consider a fleshed out RFC in this area presenting a strong argument for the importance of the feature and mitigation of the pitfalls that have been raised here.

@aturon aturon closed this Jan 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.