-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Split elided_lifetime_in_paths into finer-grained lints #120808
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
base: master
Are you sure you want to change the base?
Split elided_lifetime_in_paths into finer-grained lints #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
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! ❤️
This comment was marked as resolved.
This comment was marked as resolved.
57a0a90
to
88dd6fc
Compare
r? @oli-obk (for a second opinion, unless you're busy) |
The tests should include the following cases as well, with the lints enabled:
This will prevent us from accidentally changing whether |
compiler/rustc_hir/src/hir.rs
Outdated
/// Details not yet needed. Feel free to give useful | ||
/// categorization to these usages. | ||
Other, | ||
} |
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.
Can we avoid having this enum and have the lint compute where the type appears?
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.
Specifically: you can look at the parent, or implement the lint on paths and look at the first segment
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 know how to do this to achieve the goals. Interested parties can watch as I flail about over in Zulip.
☔ The latest upstream changes (presumably #142962) made this pull request unmergeable. Please resolve the merge conflicts. |
@rustbot author |
b0e622e
to
39f3df2
Compare
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. Some changes occurred in need_type_info.rs cc @lcnr HIR ty lowering was modified cc @fmease |
This comment has been minimized.
This comment has been minimized.
39f3df2
to
b2869df
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
Removing the `issue-91763` test as the implementation is completely different now. Bootstrap forces `rust_2018_idioms` to the warning level in the rustc_lint doctests using `-Zcrate-attr`. This overrides the doctest's crate-level `deny` attributes, so I've changed those to be statement-level attributes.
b2869df
to
10448cc
Compare
@rustbot ready |
paths containing hidden lifetime parameters are deprecated | ||
lint_hidden_lifetime_in_path_suggestion = | ||
indicate the anonymous lifetime |
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.
indicate the anonymous lifetime | |
indicate the inferred lifetime |
I'd probably say "inferred" here for a couple reasons. One, I'm planning to update the Reference to call this the inferred lifetime (as we call _
the inferred type/const). Two, the lifetime isn't necessarily anonymous. It could be inferred to be a named lifetime, though of course we lint against that separately.
/// The `hidden_lifetimes_in_output_paths` lint detects the use | ||
/// of hidden lifetime parameters in types occurring as a function | ||
/// return value. |
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.
/// The `hidden_lifetimes_in_output_paths` lint detects the use | |
/// of hidden lifetime parameters in types occurring as a function | |
/// return value. | |
/// The `hidden_lifetimes_in_output_paths` lint detects use of | |
/// hidden lifetime parameters in the return type of a function. |
/// Hidden lifetime parameters can make it difficult to see at a | ||
/// glance that borrowing is occurring. This is especially true | ||
/// when a type is used as a function's return value: lifetime | ||
/// elision will link the return value's lifetime to an argument's | ||
/// lifetime, but no syntax in the function signature indicates | ||
/// 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.
/// Hidden lifetime parameters can make it difficult to see at a | |
/// glance that borrowing is occurring. This is especially true | |
/// when a type is used as a function's return value: lifetime | |
/// elision will link the return value's lifetime to an argument's | |
/// lifetime, but no syntax in the function signature indicates | |
/// that. | |
/// Hidden lifetime parameters can make it difficult to see at a | |
/// glance that borrowing is occurring. This is especially true | |
/// when the return type of a function hides a lifetime. Lifetime | |
/// elision will link the lifetime in the return type to an input | |
/// lifetime without any indication of this in the signature. |
(This is to clean up (or avoid) some terminology around types/values and arguments/parameters.)
/// The `hidden_lifetimes_in_type_paths` lint detects the use of | ||
/// hidden lifetime parameters in types not part of a function's | ||
/// arguments or return values. |
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.
/// The `hidden_lifetimes_in_type_paths` lint detects the use of | |
/// hidden lifetime parameters in types not part of a function's | |
/// arguments or return values. | |
/// The `hidden_lifetimes_in_type_paths` lint detects the use of | |
/// hidden lifetime parameters in types other than those used | |
/// within parameters or within the return type of a function. |
lint_hidden_lifetime_in_path = | ||
paths containing hidden lifetime parameters are deprecated |
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.
Since this thread has become long and there were multiple FCP proposals, I'll mention for @oli-obk's convenience the one we're reviewing this against is #120808 (comment). |
Description
Converts the existing
elided_lifetime_in_paths
lint into three smaller pieces:hidden_lifetimes_in_input_paths
— fires forfn(ContainsLifetime) -> ...
hidden_lifetimes_in_output_paths
— fires forfn(...) -> ContainsLifetime
hidden_lifetimes_in_type_paths
— fires for many other usages ofContainsLifetime
, such as in astatic
or in a turbofishA new group
hidden_lifetimes_in_paths
is created with the three smaller lints and places that use the oldelided_lifetime_in_paths
name are updated to match.Background
In general, we want to discourage function signatures like
fn (&T) -> ContainsLifetime
,fn (ContainsLifetime) -> &T
, andfn (ContainsLifetime) -> ContainsLifetime
as it is not obvious that a lifetime flows through the function and back out as there is no visual indication thatContainsLifetime
has a lifetime generic (such types are not usually literally called "contains lifetime" 😃).In #120808 (comment) (and multiple followup comments, e.g. #120808 (comment)), the lang team decided on a plan where we introduce a new warn-by-default lint
mismatched_lifetime_syntaxes
(supersedingelided_named_lifetimes
) which helps insure consistency between input and output lifetime syntaxes and then splitelided_lifetime_in_paths
into three parts. The combination of these lints should be enough to accomplish the original goal.History
Note that this PR has substantially changed from its original version. Check the (copious) comments below as well as the edit history of this message.