-
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
Make it possible to have const
impl
s for Iterator
#92433
Conversation
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
F: ~const FnMut(&Self::Item) -> R, | ||
F: ~const Drop, | ||
R: ~const Try<Output = bool>, | ||
R::Residual: Residual<Option<Self::Item>>, | ||
{ | ||
#[inline] | ||
fn check<I, V, R>( | ||
mut f: impl FnMut(&I) -> V, | ||
) -> impl FnMut((), I) -> ControlFlow<R::TryType> | ||
where | ||
V: Try<Output = bool, Residual = R>, | ||
R: Residual<Option<I>>, | ||
{ | ||
move |(), x| match f(&x).branch() { | ||
ControlFlow::Continue(false) => ControlFlow::CONTINUE, | ||
ControlFlow::Continue(true) => ControlFlow::Break(Try::from_output(Some(x))), | ||
ControlFlow::Break(r) => ControlFlow::Break(FromResidual::from_residual(r)), | ||
} | ||
<<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType: | ||
~const Try<Output = Option<Self::Item>>, | ||
<<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType: ~const FromResidual, | ||
Self::Item: ~const Drop, | ||
{ | ||
pub struct Check<F>(F); | ||
|
||
impl_const_closure! { | ||
impl<F, I, V, R> const FnMut for Check<F> | ||
where | ||
F: ~const FnMut(&I) -> V, | ||
F: ~const Drop, | ||
I: ~const Drop, | ||
V: ~const Try<Output = bool, Residual = R>, | ||
R: Residual<Option<I>>, | ||
R::TryType: ~const Try<Output = Option<I>>, | ||
R::TryType: ~const FromResidual, |
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.
Holy boilerplate. 😬
Maybe we need some "everything ~const" sugar?
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.
Adding ~const
super traits could possibly make this easier, however it needs work and we need to wait for it to land in bootstrap to incoporate its changes.
This comment has been minimized.
This comment has been minimized.
const
impl
s for Iterator
const
impl
s for Iterator
match self { | ||
ControlFlow::Continue(..) => None, | ||
ControlFlow::Continue(_x) => None, |
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.
what's up with that? please add a HACK
comment referencing the issue that will allow us to go back to the previous
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.
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.
Ah right, I remember this. Please open an issue for it and link it here
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.
I think I would prefer not to land this change until rustdoc's handling of ~const bounds is in better shape. Iterator
is such a central trait, it's used all the time by beginners, and many of its signatures are gnarly enough already prior to this PR that I think it's not the right tradeoff to introduce this much noise and glitchiness into it right now.
Now is the time to tap the brakes a little on filling the standard library with ~const and allow rustdoc to catch up a little. Maybe if the rustdoc folks aren't already on top of it, one of you would be willing to shift some attention over there?
Below is a representative screenshot of before and after. The before is completely within the reach of a beginner to understand. The after is totally unintelligible.
Someone needs to figure out what to do in rustdoc to avoid these API docs becoming unintelligible in the presence of ~const. Do ~const Drop bounds need to be signaled at all? Do ~const bounds need to be shunted behind an "expand" toggle or accordion or something?
@rust-lang/libs-api @rust-lang/libs @rust-lang/libs-contributors
Not only is that signature unintelligible to beginners, it's also unintelligible to at least one libs-api member. I don't know what |
You just found another issue that was introduced in #92229. Basically that PR removes
Yes, but most of the work needed (for rustdoc) is done in this PR, and the best way forward would be changes from the language side i.e. The specific regression has been fixed. After a thorough review I think the latest change only introduces minor noise on some methods and only major bound jargon on unstable @rustbot ready |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
At this point I still don't find this an acceptable regression in the usability of the Iterator
docs. I put more Before/After below. Someone from @rust-lang/libs-api should feel free to let me know if I am being too picky on this. I feel there needs to be more design work from the rustdoc side to find a way to simplify and present the more complex bounds that ~const
seems to necessitate.
I'm going to remove this PR from review by converting it to a draft and I don't plan to review it again, but would ask the author to send any rustdoc work separately for review by the rustdoc folks, or guidance on how to proceed here. We can keep this PR open as a draft to hold rebases of the Iterator
changes for comparison as any rustdoc fixes start landing in other PRs.
Before | After |
---|---|
In order to make no changes to the library documentation, we need two things:
There is another option which could be easier: Add an attribute to configure and prevent rustdoc from showing the actual complexity and show a minimized version, |
☔ The latest upstream changes (presumably #93457) made this pull request unmergeable. Please resolve the merge conflicts. |
…nds, r=GuillaumeGomez Improve rustdoc const bounds - Rustdoc no longer displays `~const` in trait bounds, because it currently means nothing for stable users, and because we still haven't decided on the final syntax yet. - Rustdoc will hide trait bounds where the trait is `Drop` AND it is `~const`, i.e. `~const Drop` bounds because it has no effect on stable users as well. - Because of additional logic that hides the whole `where` statement where it consists of `~const Drop` bounds (so it doesn't display `struct Foo<T>() where ;` like that), bounds that have no trait e.g. `where [T; N+1]: ;` are also hidden. Cherry-picked from rust-lang#92433.
@fee1-dead any updates on this? |
currently blocked on several other changes |
Currently based on #92432. PR is unblocked and considered to be ready when #92432 is merged and all the issue numbers are updated.