-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
RFC: Generalize Freeze, etc. into custom-defined does-not-contain traits #10879
Comments
That |
Hmm. Would that still be sufficient to rule out cycles? I think it might be, but I'm having a hard time thinking straight enough to convince myself. In that case it might be better to just straight-up make this a trait itself, instead of relying on magic attributes:
I was shying away from this earlier because it seems potentially harder to implement, but I have no actual idea. At this point the
True, which is why I said the The current built-in traits could potentially be reimplemented on top of this as well, so they would no longer have to be baked-in to the compiler, only
I don't know how feasible it would be to implement a general |
cc me |
Until we have our story straight about trait matching (#5527), I'd be reluctant to add features, and this seems like it's ultimately really a feature request for "negative" traits. I think those are feasible to support at some point, though. |
I was thinking of this as more of a refactor-and-generalize, with added power falling out as a side benefit. If it doesn't make things "nicer" then it's probably not a good idea. I did think of negated traits as a potential alternative way to achieve similar functionality, but:
I also don't think the two ideas have much in common: |
I no longer think this is relevant and a good idea. |
…,xFrednet [`ptr_cast_constness`]: Only lint on casts which don't change type fixes rust-lang#10874 changelog: [`ptr_cast_constness`]: Only lint on casts which don't change type
Rust currently has a few built-in traits which all basically mean "does not contain Foo".
Freeze
: no&mut
,Cell
, orRefCell
.Send
: no managed or borrowed pointers.'static
: no non-'static
borrowed pointers. Combined with the proposal to use marker types in #10834, perhaps this could be generalized to user-defined does-not-contain traits, with compiler support.This would be useful for, for example, preventing cycles in
Rc
, in the spirit of #10837 but at a semantic rather than syntactic level. You could write something like:This would solve the problem of existentially quantified types the same way as the built-in traits: any existentially quantified type could only be passed to this
new()
if it explicitly had aNoRc
bound (e.g.~ToStr:NoRc
). This might still be too high a burden, so there would probably be other constructors as well, as now, including aFreeze
-based and an unconstrained one, but this is still finer-grained, at least, than the current situation.This might also help with #10869, and with another crazy idea I've been thinking about that I'm not ready to post yet.
The text was updated successfully, but these errors were encountered: