Skip to content
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

Issue function modifiers in the right order in manual_async_fn lint #10456

Merged
merged 1 commit into from
Mar 18, 2023

Conversation

samueltardieu
Copy link
Contributor

Fixes #10450

changelog: [manual_async_fn] output function modifiers in correct order

@rustbot
Copy link
Collaborator

rustbot commented Mar 5, 2023

r? @flip1995

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 5, 2023
@samueltardieu
Copy link
Contributor Author

r?

@rustbot
Copy link
Collaborator

rustbot commented Mar 11, 2023

Error: Parsing assign command in comment failed: ...'' | error: specify user to assign to at >| ''...

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

@samueltardieu
Copy link
Contributor Author

r? @Manishearth

@rustbot rustbot assigned Manishearth and unassigned flip1995 Mar 11, 2023
@samueltardieu
Copy link
Contributor Author

@Manishearth Is there anything more you'd like me to do on this one?

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just generally busy right now, will take time for reviews

@@ -74,11 +74,16 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
if let Some(ret_pos) = position_before_rarrow(&header_snip);
if let Some((ret_sugg, ret_snip)) = suggested_ret(cx, output);
then {
let header_snip = if header_snip.starts_with("pub ") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the Visibility on the function signature object here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the vis_span, as well as tests with pub(crate) and pub(self).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, please use the Visibility itself, not its span/snippet. It's a typed API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about cx.tcx.visibility(def_id), which returns a ty::Visibility? How would it help when what we are trying to achieve is to insert async at the right place in the function signature (right after the visibility)? I had the impression that ty::Visibility would give us semantic information that would need to be transformed back manually into a string to insert into the suggestion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not turning it back into a string, though, we're just checking if it's got a non-private visibility.

Copy link
Contributor Author

@samueltardieu samueltardieu Mar 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being obtuse, but we clearly do not understand each other, and I am fully conscious that the issue might be on my side.

Let me summarize this patch problem statement: given a function or method declaration, insert the async word between the function visibility in the source code, whatever it is, and the rest of the function signature (or right before the function signature if no visibility is present in the source).

All decisions to trigger the lint have been made before already, this patch only changes the place where async is inserted in the suggestion presented to the user. There is nothing to compare the ty::Visibility against, it wouldn't change our decision in any way, which is: insert async right after the visibility span if not empty, or before the function signature otherwise. I cannot envision any situation where we would ultimately end up doing anything different from this.

I'm afraid that checking for a non-private visibility could even be counter-productive when we get async trait functions in, as they will get a non-private visibility without any visibility span, so we would have to maintain the check on the span shown above.

I understand that you might not have a lot of time to explain to me why you think that using visibility semantic information would be beneficial over just looking at its span for this problem. I'll wait until someone else picks up this patch (either a contributor or another maintainer) as I do not understand how I can make any meaningful progress by following your suggestion to use semantic information when I can't see how it would benefit this patch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think the thing I missed on my first read-through was that we are reading the visibility as a string for the snippet anyway.

(the code changed a couple times and I missed it)

No, I have enough time, if I did not have time to review this at the typical speed I would have bounced the PR to someone else, I just don't have enough time to review stuff with very quick turnaround.

@@ -70,15 +72,21 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
"this function can be simplified using the `async fn` syntax",
|diag| {
if_chain! {
if let Some(vis_snip) = snippet_opt(cx, *vis_span);
if let Some(header_snip) = snippet_opt(cx, header_span);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this line is unnecessary now

@Manishearth
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 18, 2023

📌 Commit afe27ba has been approved by Manishearth

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Mar 18, 2023

⌛ Testing commit afe27ba with merge e64c596...

@bors
Copy link
Collaborator

bors commented Mar 18, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Manishearth
Pushing e64c596 to master...

@bors bors merged commit e64c596 into rust-lang:master Mar 18, 2023
@samueltardieu samueltardieu deleted the issue-10450 branch March 24, 2023 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

manual_async_fn butchers fn visibility ("async pub" instead of "pub async")
5 participants