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
{{ message }}
Repository navigation
RFC: Centralize on special types as a way of informing inference about special constraints #10834
As part of the discussion in #5922, it became clear that there are a number of cases in which we must inform the compiler about special constraints that pertain to specific types. These constraints almost always arise because of unsafe code that does things the compiler can't know about. We don't have a central mechanism for propagating such constraints:
Annotations like #[no_freeze] are used to inform the builtin-bounds.
Except for non-copyable, which has a special type.
Variance currently has no mechanism, so unused lifetime parameters don't necessarily behave like people expect.
I think we should centralize on one mechanism. My current thought is to employ 0-sized types for this. So we would remove the #[no_freeze] annotations and add types like Nonfreezable, as well as CovariantLifetime<'a> and so on. These would be lang items specially recognized by the compiler.
Nominating and adding to the agenda for next week.
Marker types seem relatively straightforward to use for structs, but could it result in awkwardness for enum variants, especially because they are more frequently destructured? Even if there they are easily ignored, there is still some programmer overhead in ignoring a field that does not contain any data.
NonCopyable as it is currenlty implemented (with a Drop impl) has some problems as it should - but doesn't currently - prevent the type from being used in a static variable. The std::unstable::atomics family uses NonCopyable which causes some strange issues like #10577.
One positive aspect of this is that it commits us to basically nothing in terms of backwards compatibility at the language level. If we later come up with a better way to do these, we can add that and also keep the marker types around without any awkwardness.
On Fri, Dec 06, 2013 at 06:41:20AM -0800, zkamsler wrote:
...Marker types seem relatively straightforward to use for structs, but could it result in awkwardness for enum variants..
There is an easy workaround. Convert
enum Foo { A(..), B(.., Noncopyable) }
to
struct Foo { v: Foo1, _nc: Noncopyable }
enum Foo1 { A(..), B(..) }
``
and then match on `x.v` instead of `x`.
I think it's not so common though to use enums as the "top-level" type
for unsafe things like `Rc` etc.
@sfackler I agree that non copyable should be integrated as a lang item into the compiler, though I don't think that we should necessarily prohibit types that contain dtors from appearing as static items (as I explained in that issue at some point).
Activity
nikomatsakis commentedon Dec 6, 2013
Some arguments I considered in favor of using marker types:
zkamsler commentedon Dec 6, 2013
Marker types seem relatively straightforward to use for structs, but could it result in awkwardness for enum variants, especially because they are more frequently destructured? Even if there they are easily ignored, there is still some programmer overhead in ignoring a field that does not contain any data.
sfackler commentedon Dec 6, 2013
NonCopyableas it is currenlty implemented (with aDropimpl) has some problems as it should - but doesn't currently - prevent the type from being used in a static variable. Thestd::unstable::atomicsfamily usesNonCopyablewhich causes some strange issues like #10577.glaebhoerl commentedon Dec 6, 2013
One positive aspect of this is that it commits us to basically nothing in terms of backwards compatibility at the language level. If we later come up with a better way to do these, we can add that and also keep the marker types around without any awkwardness.
nikomatsakis commentedon Dec 6, 2013
On Fri, Dec 06, 2013 at 06:41:20AM -0800, zkamsler wrote:
There is an easy workaround. Convert
to
nikomatsakis commentedon Dec 6, 2013
@sfackler I agree that non copyable should be integrated as a lang item into the compiler, though I don't think that we should necessarily prohibit types that contain dtors from appearing as static items (as I explained in that issue at some point).
nikomatsakis commentedon Dec 10, 2013
cc @thestinger, as one of the bigger users of these sorts of annotations. This was discussed in meeting on dec 10 and generally approved of.
pnkfelix commentedon Jan 9, 2014
Accepted for 1.0, P-backcompat-libs
15 remaining items
auto merge of #12016 : FlaPer87/rust/remove-non-copyable, r=alexcrichton
Auto merge of rust-lang#10834 - whee:gh-pages-retain-filter-state, r=…
Merge rust-lang#10834