-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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: Default trait kind-bounds based on sigil #7264
Comments
There is also a further question of whether the default should stay if you write a different bound; for example, should |
With traits instead of closures, you end up looking like |
I think I'm ok with defaults-by-sigil, and I think .. I actually don't mind defailts-all-same. Depends if we wind up keeping closures that copy stuff into their environment. As an aside: if I want to pass a I don't have a strong feeling on this. It's a tension between orthogonality and non-verbosity. |
Odds of that working are high, pending correct codegen for &Trait of course. With defaults-by-sigil or no defaults ("principled"), it would automatically work with |
This works ok with dynamically-sized types too. Instead of looking at the "trait store" (the glued-on sigil), you'd case on the thing surrounding the type. If it's a |
This is done. |
…_trait, r=llogiq Fix invalid syntax in `from_iter_instead_of_collect` suggestion First attempt at contributing, hopefully this is a good start and can be improved. :) fixes rust-lang#7259 changelog: [`from_iter_instead_of_collect`] fix invalid suggestion involving "as Trait"
I am working on #3569, and there has arisen a question of reasonable defaults. The question is exactly the same for traits as for closures, so WLOG I'll use closures as an example.
Part of the motivation is to be able to capture non-Owned and/or borrowed (non-static) things in
~fn()
and@fn()
closures. So, what today is written~fn()
and@fn()
will in the future mean the same as~fn:Owned()
and@fn:'static()
.But I anticipate the "implied bounds" we have today being far and away the most common use cases even when you can specify your own bounds (e.g., you wanna be able to use heap fns/traits as return types)... and it might be a pain to need to write
~fn:Owned()
and@fn:'static()
all the time. As much as I like the type grammar to be principled, I'm sitting on a diff that makes this change across libs std, extra, syntax, and rustc, and it's 73 files large.So my proposal is if you don't write a bounds list at all, the default bounds are used, and if you want to override that, you have to write an empty bounds list ("
~fn:()
"). I figure the defaults will be dependent on the pointer sigil; Niko also suggested having'static
be the default for all of them, but neither of us like that. So, here is a table which shows what the function types will look like in each proposed scheme.The potential downside of the defaults-by-sigil plan is that if you write something like
~fn:Const()
, it may be surprising that that doesn't mean the same as~fn:Const+Owned()
.One final option that I didn't show on the table is just to always keep the "default" bound, so you couldn't capture borrowed pointers in heap fns/traits, but you could further limit the environment with more bounds. So you couldn't write
~fn:()
and capture a & or @-pointer, but~fn:Const()
would mean the same as~fn:Const+Owned()
.The text was updated successfully, but these errors were encountered: