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
rust: remove all uses of unstable pragma "in_band_lifetimes" #1646
Conversation
Given that the tracking issue is making fairly slow progress (no substantive updates since 2017) and the feature's only being use as syntactic sugar it seems like this is a useful way to remove an unstable feature. |
The placeholder lifetime |
This is a pretty big step backward for Rust usability. In particular, I find having to write Do we know this feature is dead? What benefit does removing this give us? |
It seems that indeed On the other side, this may make changes like #1628 (if we decided to implement them) more bloated. Overall, I'm rather neutral to this change, but reducing the number of unstable features could be beneficial to the project. |
@bradjc You need to write This PR is part of a series I'm working on with @gkelly to make as much of Tock as possible compile under a stable Rust toolchain. In can set up a tracking issue to mirror a doc I have with all of the feature gates I'm hoping to remove. |
Similar to #1650, I think this should go in a global tracking issue for unstable features. |
Ask and you shall receive: #1654. Sorry for the abrupt spray of PRs. I'm new to Tock, and I took enthusiasm on my first cleanup PR as a sign to move forward at full speed. |
I disagree. Considering the feature is enabled at the module level, rather than file, I found it extremely confusing that those lifetime declarations were necessary in some places, but not others. Without knowing the feature existed or was in use, it was difficult to reconcile that difference. |
I also feel like this is a major step back in usability. It's fairly important that Tock be able to be accessible both to "Most Rust programmers working in stable" as well as embedded C programmers for whom this is their first exposure to Rust. I certainly cannot explain in one simple sentence to someone who has never seen Rust what As I see it, currently the compiler is capable of figuring this out completely, as evidenced by the currently extant code base. Going back and manually adding a large number of |
If the issue is that we are not using this consistently, I would argue (strongly) that we should add this to more places, rather than remove it. |
For whatever it's worth, when we were new to Tock (but had done some Rust), the use of |
@mcy we all very much appreciate your contributions! And thanks for creating the issue! |
If I can summarize the sides so far: for
against
|
I agree it's better to let the compiler figure things out when it can, but it's this any different than extraneous In other words, it sucks that Rust is overly verbose in impl blocks, but lifetimes in particular is a relatively small delta. |
Perhaps it would be better to avoid using |
This is really at the crux, imo. If this is indeed unlikely to be stabilized, we probably can't reasonable go against typical use of Rust in the rest of the ecosystem in the long run and, despite whatever distaste we might have for this syntax choice, will just have to but the bullet. Perhaps it's worth confirming the status of this feature for those of us who would prefer to keep the current syntax. |
I would say that impl hil::time::Time for MachineTimer<'a> { then the reader can wonder where A case where it could be confusing is when multiple lifetimes are involved, such as: impl Iterator for Entropy8To32Iter<'_, '_> If only the first lifetime is used, we could end up with syntax like follows: impl<'a> Iterator for Entropy8To32Iter<'a, '_> To be more specific, in the draft of #1628 I ended up with something like this: impl<T: 'a + ?Sized> Deref for Borrowed<'a, '_, T> { which would be the following without the unstable feature. impl<'a, T: 'a + ?Sized> Deref for Borrowed<'a, '_, T> { If that's too unclear, the two lifetimes could be named: impl<'a, 'ker, T: 'a + ?Sized> Deref for Borrowed<'a, 'ker, T> { |
Another thing that I noticed when working on #1628 is that in-band lifetimes are only allowed in some contexts. In the other cases, either a pre-declared lifetime or an anonymous lifetime had to be used. I think it can add to the confusion of the unstable feature. |
Totally agreed but a reasonable remedy for this concern in particular would also be to enable the feature everywhere :) |
My bad, my comment wasn't clear enough. What I meant is that even when in-band lifetimes are enabled, the Rust compiler doesn't allow one to declare in-band lifetimes in some syntactic contexts. For example, the following code #![feature(in_band_lifetimes)]
use core::marker::PhantomData;
pub struct A<'a> {
foo: PhantomData<&'a ()>,
}
pub fn bar<F>(f: F) -> u32
where
F: FnOnce(A<'a>) -> u32
{
f(A { foo: PhantomData })
} triggers the following error:
Note: This example is a simplified version of what is found in Instead, one can write either of the following, none of which require the in-band lifetime feature. pub fn bar<'a, F>(f: F) -> u32
where
F: FnOnce(A<'a>) -> u32 or pub fn bar<F>(f: F) -> u32
where
F: FnOnce(A<'_>) -> u32 Note that in the second case, just replacing Overall, in-band lifetimes have a limited scope in terms of allowed syntax. |
This was discussed on the core call today. Major conclusions:
What this means for this PR specifically: Once updated to current master, we should merge it. |
df2f0bb
to
139a2a5
Compare
This commit removes the use of the unstable pragma "in_band_lifetimes" everywhere. This change is a noop, since it consits of either adding lifetime annotations, or changing exlicit lifetimes ('a) to placeholder liftimes ('_).
139a2a5
to
a48efc9
Compare
Rebased on master, and also removed all in_band_lifetimes uses introduced from adding the stm32f3xx chip and from adding the apollo3 chip. cc @alistair23 this will probably cause some conflicts with your outstanding apollo3 PRs, sorry about that. |
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.
Hopefully this change is pretty straightforward. I didn't actually look through all 117 files.
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.
bors d+
As mentioned on #core in slack, this touches a huge number of files and will require frequent rebasing if it doesn't go through with some priority. Since it's really just a syntax (non-functional) change it should be reasonably safe. I'm going to go ahead an mark this last-call
now as well, with plans to go ahead and merge end of day / early tomorrow.
✌️ mcy can now approve this pull request. To approve and merge a pull request, simply reply with |
@hudson-ayers that d+ is really meant to say that you should go ahead and merge this roughly EoB today |
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.
bors r+
Pull Request Overview
This commit removes the use of the unstable pragma "in_band_lifetimes" everywhere. The main culprit turned out to be the
capsules
crate.Testing Strategy
This change is a noop, since it consits of either adding required lifetime annotations, or changing exlicit lifetimes
'a
to placeholder liftimes'_
.make allcheck
should be sufficient to show this change is correct. In general, I tried to make the change that required minimal changes to the AST.TODO or Help Wanted
N/A
Documentation Updated
/docs
, or no updates are required.Formatting
make formatall
.