-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Split elided_lifetime_in_paths into tied and untied #120808
base: master
Are you sure you want to change the base?
Split elided_lifetime_in_paths into tied and untied #120808
Conversation
This comment has been minimized.
This comment has been minimized.
As I've now tried to add this test twice and to help prevent trying to add it again... this fails because elision can't take place: fn top_level_nested_to_top_level_nested(v: &ContainsLifetime) -> &ContainsLifetime { v }
|
eaf0446
to
8f5390c
Compare
This comment has been minimized.
This comment has been minimized.
8f5390c
to
f1f5c32
Compare
f1f5c32
to
cc85718
Compare
This generally looks fine. I had a few questions about what we expect to happen in a corner case.
@rustbot label: +S-waiting-on-author -S-waiting-on-review |
Oh, I suppose there is still an open question about the use of the "tied"/"untied" terminology, which I admit threw me for a loop at first. I'm not sure which group is the best to handle resolving that question, though. And I'm also not entirely sure that resolving that question should block landing this work. Is resolving a question like that a matter for WG-diagnostics, or for T-lang? |
That's a great question that I don't have an answer for. I posed it in the Zulip thread hoping there was some existing terminology. Unfortunately, no one seemed aware of one. "Tied" made some intuitive sense for the small handful of people I asked one-on-one. It feels like this is something that we must have talked about before and potentially even documented somewhere, but 🤷 |
f6d8513
to
da16b9b
Compare
ELIDED_LIFETIMES_IN_PATHS_TIED, | ||
ELIDED_LIFETIMES_IN_PATHS_UNTIED, |
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.
If we are to nitpick about this, an elided lifetime refers to both Foo
and Foo<'_>
(as per the official lifetime elision rules), with the former being implicitly elided, and the latter, explicitly (very unfortunate that the original lint picked that name 😔). Hidden is a more concise word which we could reach for, now.
For the purpose of the lint, I'd also move the adjective around, since elided_lifetimes_in_paths_tied
does not roll off the tongue too much.
Finally, on the most controversial/debatable aspect of the exact word being picked here (e.g., "tied"), my own subjective two cents on the topic, would be to not overthink it, and use meaningful: meaningful_lifetimes_hidden_in_paths
. The other one could use free: free_lifetimes_hidden_in_paths
.
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'm sympathetic to this feedback, but some points arise when trying to implement some of the suggestions:
- Calling the lints
a_commonpart
andb_commonpart
means that they won't appear near each other in alphabetical lists (which are numerous). - There's another lint (
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT
) that should probably be updated. - I'm torn between "hidden lifetimes" and "lifetimes hidden".
- There's a lot of other "elided" lifetimes in
rustc_resolve
'slate.rs
. I don't know which style they mean. Having both terms with mixed meanings may make things worse until someone cleans up all the code.
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.
Yeah, fair enough
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.
Alright, I've pushed a commit on top that changes to lifetimes_hidden_in_paths
/ tied_lifetimes_hidden_in_paths
/ untied_lifetimes_hidden_in_paths
. This should allow us to see how we feel about it with some concrete code to look at.
TODO If we want to continue on this route, I did forget to rename the test files themselves.
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.
...and I removed that commit from this PR, although I still have it locally. It looks like this PR will have enough trouble getting feedback, so let's go smaller.
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.
When it comes to nomenclature of the lints, I have a bias towards keeping the name of the group as a substring of the individual lints, and I agree with some of daniel's observations, so my personal preference would be to name these lints ELIDED_LIFETIMES_IN_PATHS_EXPLICIT
(not 100% sure on this one) and ELIDED_LIFETIMES_IN_PATHS_HIDDEN
.
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 for pushing this forward! ❤️
☔ The latest upstream changes (presumably #121780) made this pull request unmergeable. Please resolve the merge conflicts. |
57a0a90
to
88dd6fc
Compare
Current assignee appears busy. r? rust-lang/compiler |
This will allow us to be smarter about when the lint is emitted, such as only when an output type is involved.
Please type @ |
1ae2d11
to
d6a8cd7
Compare
Didn't even realize it was in that state. It was moved there in #120808 (comment) and then immediately followed by a "oh maybe this still needs someone to look at it" style comment that didn't set it back. @rustbot ready |
Although I think that the "tied" terminology should be discussed before this merges, I expect that will just be a long giant bikeshed, so I'll go ahead and mark this as not a draft PR and then if someone "accidentally" merges it before that discussion, then we'll just have to live in that world. |
This comment has been minimized.
This comment has been minimized.
Types that contain a reference can be confusing when lifetime elision occurs: ```rust // Confusing fn foo(_: &u8) -> Bar { todo!() } // Less confusing fn foo(_: &u8) -> Bar<'_> { todo!() } ``` However, the previous lint did not distinguish when these types were not "tying" lifetimes across the function inputs / outputs: ```rust // Maybe a little confusing fn foo(_: Bar) {} // More explicit but noisier with less obvious value fn foo(_: Bar<'_>) {} ``` We now report different lints for each case, hopefully paving the way to marking the first case (when lifetimes are tied together) as warn-by-default. Additionally, when multiple errors occur in the same function during the tied case, they are coalesced into one error. There is also some help text pointing out where the lifetime source is.
d6a8cd7
to
0a10b56
Compare
If you make the lint unstable, you can delay that bikeshed until later. ;) (Lints can be associated with a feature gate to make them unstable.) |
@shepmaster I'm going to lang-nominate this to be discussed, otherwise it will never happen if it's more of a "suggestion" that's not on team calendars/radars. Please feel free to edit my comment or post a more accurate summary for T-lang to consider. Nominating for T-lang discussion: what should the split up Reproducing parts of PR description below:
@rustbot label +I-lang-nominated |
I don't think we want to rename and then immediately rename again. |
It would be good to get a summary of what exactly those lints are covering each. I'm actually not sure, I thought "tied" was about lifetimes that appear in the return type (which is why I think the lint name should involve the term |
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 don't have an opinion on these lints or their naming, but the implementation LGTM.
My suggestion would be |
Some thoughts on naming:
Side note that I expect that we may someday add "output elision" in contexts outside of function return values (e.g., associated type values or struct field types), but the name "output" seems generic enough to cover that. |
I also think we should remove this wording at least until we upgrade some lint to warn-by-default. |
Perhaps we could lean into the word "hidden". When I look at... struct S<'a>(&'a ());
fn f(x: &()) -> S { S(x) } ...I think of that lifetime on Then we could say that both elided and hidden uses expand implicitly into anonymous lifetime parameters, which can be written explicitly as |
I like "hidden", since we already use "lifetime elision" for all the existing cases, including |
Before merging
async fn
hard error case. Non-blocking.Description
Types that contain a reference can be confusing when lifetime elision occurs:
However, the previous lint did not distinguish when these types were not "tying" lifetimes across the function inputs / outputs:
We now report different lints for each case, hopefully paving the way to marking the first case (when lifetimes are tied together) as warn-by-default (#91639).
Additionally, when multiple errors occur in the same function during the tied case, they are coalesced into one error. There is also some help text pointing out where the lifetime source is.
To discuss
"Tied" terminology
The lints are called
elided_lifetimes_in_paths_tied
andelided_lifetimes_in_paths_untied
, under a lint group ofelided_lifetimes_in_paths
. The usage of "tied" and "untied" introduces new terminology for a concept that is not new.We had a discussion about other phrasing, but no super strong alternative arose. "tied" is not the most beautiful choice, but it's serviceable.
Beyond "tied", a good argument has been made that the current lint name is factually incorrect (tl;dr: both
Foo
andFoo<'_>
perform lifetime elision;Foo
has a hidden lifetime whileFoo<'_>
has explicit syntax). A follow up PR could rename these lints to be more accurate.Suggested resolution
Do nothing today. This phrasing is good enough to merge and we can always rename and leave aliases.
Alternate resolutions
Decorate the bikeshed for a few days/weeks/months/editions.
"Deprecated" terminology
The current wording of the diagnostic is (emphasis mine)
This suggests that at some point we want to completely stop supporting this and make it into a hard error that cannot be disabled. This seems like a strong prescription, given the turbulence this lint has had throughout its life.
Suggested resolution
Do nothing today. Assume we really do want to deprecate this capability. We may want to evaluate which cases we really want to deprecate (e.g.
fn(_: ContainsLifetime)
is generally considered harmless) and tweak the error message to better distinguish which patterns are on a path to being removed.Alternate resolutions
Decide we don't want to deprecate it and pick a softer wording.
Existing hard errors
async
and non-async
functions are treated differently today:It seems like the two cases should be the same.
Suggested resolution
Do nothing today. At some point, change
elided_lifetimes_in_paths_tied
to warn-by-default, then error-by-default (likely over an edition), then become a hard error (as suggested in the "deprecation" discussion). At that point, the two cases should be identical.Alternate resolutions
We could dial back the async fn hard error to become error-by-default or warn-by-default, matching whatever desired end state we want.