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

Forbid object types which are not object safe #19482

Closed
nrc opened this issue Dec 3, 2014 · 10 comments
Closed

Forbid object types which are not object safe #19482

nrc opened this issue Dec 3, 2014 · 10 comments
Labels
P-low Low priority

Comments

@nrc
Copy link
Member

nrc commented Dec 3, 2014

We currently only check for object safety when coercing a concrete object to a trait object. We should prevent the programmer writing object types which are not object safe.

@nrc nrc added the I-nominated label Dec 3, 2014
@nrc
Copy link
Member Author

nrc commented Dec 3, 2014

backwards incompatible

@brson brson added P-low Low priority and removed I-nominated labels Dec 11, 2014
@nikomatsakis
Copy link
Contributor

True but I think it can only break dead code -- you can't produce instances of those types. Seems like this doesn't have to be fixed for 1.0.

@brson
Copy link
Contributor

brson commented Dec 11, 2014

P-low. Seems like it won't break any useful code. Justabug?

@nikomatsakis
Copy link
Contributor

(That is, it's probably the kind of bug we can fix at some point. Not that I don't want to fix it.)

@ftxqxd
Copy link
Contributor

ftxqxd commented Dec 13, 2014

I think this would also break public functions that take non-object-safe trait objects as parameters (e.g., pub fn foo(x: Box<ObjectUnsafe>)), so long as they aren’t called within the crate.

@steveklabnik
Copy link
Member

Traige: we did this, didn't we?

@jonas-schievink
Copy link
Contributor

Looks like #21953 is a duplicate which was closed

@bluss
Copy link
Member

bluss commented Jan 1, 2016

Is FnOnce object safe? Its methods can't be called through an object. Add is the same way (currently object safe but not callable).

@steveklabnik
Copy link
Member

@jonas-schievink yup!

@nikomatsakis
Copy link
Contributor

@bluss FnOnce is considered object safe. Basically, the restriction against calling call_once(self) is enforced on the caller side by requiring that callee be Sized (and hopefully we will lift this restruction eventually). Put another way, if I write fn foo<T:FnOnce()>(t: T), I can't have T=FnOnce() anyway because T: Sized would not hold. If I write fn foo<T:FnOnce()+?Sized>(t: T), then T=FnOnce() is possible, but t() will fail to compile because T: Sized does not hold. So it works out either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-low Low priority
Projects
None yet
Development

No branches or pull requests

7 participants