-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Make iter::Empty<T> Send and Sync for any T #57682
Conversation
r? @dtolnay (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@rust-lang/libs FYI @bors r+ |
📌 Commit f973f37165249e18671306f4d380973647355f4c has been approved by |
This comment has been minimized.
This comment has been minimized.
Hm, I guess it cannot be done currently, as for |
@bors r- |
error: function pointers in const fn are unstable
--> src/libcore/iter/sources.rs:277:11
|
277 | Empty(marker::PhantomData)
| ^^^^^^^^^^^^^^^^^^^ Strange. I guess an |
I wonder if special casing |
It sounds like this has been implemented already but not stabilized yet. Adding Line 73 in ceb2512
Any suggestions @oli-obk? |
@dtolnay For The recourse you have here is to use something other than |
@xfix -- I would go ahead and add unsafe impls. playground |
@dtolnay oh right; yeah, |
f973f37
to
3b49f7e
Compare
Or, I have another idea how to do it without |
3b49f7e
to
5b60b2a
Compare
Arguably abusing a bug, but IMO |
5b60b2a
to
4ead708
Compare
@xfix That's not a bug; an intentional choice was made in min_const_fn to not recurse into data types. |
@Centril I don't know, compiler rejecting |
@xfix It's an intentional inconsistency ;) (see #53604 (review), #53604 (comment)) and doesn't really have to do with |
This comment has been minimized.
This comment has been minimized.
4ead708
to
313c628
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little crazy for my taste. I would prefer to see plain old unsafe impls over this.
Or, add a more readable and better tested mechanism internal to libcore for establishing variance and auto traits. By standardizing on something like this over PhantomData<T>
/ PhantomData<fn() -> T>
/ PhantomData<PhantomFnWorkaround<T>>
, the variance and auto trait impls become clearly visible during code reviews and we are more likely to catch when they are wrong for some type.
pub struct Empty<T>(phantom_data![T, Covariant + AlwaysSendSync]);
We would want to support any combination of {Covariant, Contravariant, Invariant} × {AlwaysSendSync, NeverSendSync, InheritSendSync}.
Ping from triage @xfix, can you update to the unsafe impls as requested? |
ping from triage @xfix any updates on this? |
ping from triage @xfix Unfortunately we haven't heard from you on this in a while, so I'm closing the PR to keep things tidy. Don't worry though, if you'll have time again in the future please reopen this PR, we'll be happy to review it again! |
Please re-open this merge request. That's pretty funny. I said this a year ago.
And then now I'm writing code that went
The code looks like this. pub async fn fetch_fortunes(&self) -> Vec<Fortune> {
self.client
.query_raw(&self.fortune, iter::empty())
.await
.unwrap()
.map(|row| row.unwrap())
.map(|row| Fortune {
id: row.get(0),
message: Cow::Owned(row.get(1)),
})
.collect::<Vec<_>>()
.await
}
|
@xfix given the difference between when the PR was closed and now, it would be easier to create a new PR :) |
Notably, we cannot reopen this merge request due to GitHub limitations. We would be happy to review a new version! |
Make iter::Empty<T> Send and Sync for any T Continuing from rust-lang#57682 It's quite funny, when I initially submitted this pull request, I said "Likely nobody will be using that property of `iter::empty`", but then a year later I got a compilation error because it wasn't `Send` and `Sync`. Unfortunately, `PhantomData<fn() -> T>` still errors out. Oh well. I proposed ` struct PhantomFnWorkaround<T>(fn() -> T);`, but dtolnay did not like it, so using explicit implementations.
Make iter::Empty<T> Send and Sync for any T Continuing from rust-lang#57682 It's quite funny, when I initially submitted this pull request, I said "Likely nobody will be using that property of `iter::empty`", but then a year later I got a compilation error because it wasn't `Send` and `Sync`. Unfortunately, `PhantomData<fn() -> T>` still errors out. Oh well. I proposed ` struct PhantomFnWorkaround<T>(fn() -> T);`, but dtolnay did not like it, so using explicit implementations.
Just because it can be. Likely nobody will be using that property of
iter::empty
, but at the same time, there is no reason to not allow it.