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

add lint futures_not_send #5423

Merged
merged 1 commit into from
Apr 17, 2020
Merged

Conversation

rkuhn
Copy link
Contributor

@rkuhn rkuhn commented Apr 5, 2020

changelog: add lint futures_not_send

fixes #5379

Remark: one thing that can (should?) still be improved is to directly include the error message from the Send check so that the programmer stays in the flow. Currently, getting the actual error message requires a restructuring of the code to make the Send constraint explicit.
It now shows all unmet constraints for allowing the Future to be Send.

Copy link
Contributor Author

@rkuhn rkuhn left a comment

Choose a reason for hiding this comment

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

forgot to mention: I think this could become a “restriction” lint (as it applies to some projects but not others, depending on their target audience)

clippy_lints/src/future_not_send.rs Outdated Show resolved Hide resolved
@rkuhn
Copy link
Contributor Author

rkuhn commented Apr 5, 2020

Thanks for your review @eddyb!

@flip1995 flip1995 added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Apr 6, 2020
@rkuhn
Copy link
Contributor Author

rkuhn commented Apr 6, 2020

@eddyb brought up a point on discord: in some cases it may depend on the concrete choice of type parameter whether the resulting Future is Send. This could be checked by bringing T: Send constraints into scope for all type parameters and seeing if that fixes the obligation error.

After thinking about it for a while, I come to the conclusion that while this is an interesting additional feature, it is outside of the scope I intend for this lint: this lint is meant to support library authors in ascertaining that the Futures returned by their library can successfully be used on a multithreaded executor. This is why the lint is opt-in. If an author opts into this check, they want to ensure that their Futures are Send — and the non-generic ones will need to be Send, as will be the library-supplied components of the generic ones. So I don’t see a plausible use-case for wanting futures to be Send but permitting non-Send type parameters to potentially thwart this effort. The lint can be switched off for individual functions or modules where this is too restrictive.

Put differently, the use-case of a library that wants to leave the Send-ness of all its Futures open to the user seems too narrow to me, I can only envision very generic Future transformators to fall into this category. That case will probably be better handled by an explicit compile-time assertion (as is done in many projects already).


I’ll finish this PR once rust-lang/rust#70821 has been merged.

@eddyb
Copy link
Member

eddyb commented Apr 6, 2020

I can only envision very generic Future transformators to fall into this category. That case will probably be better handled by an explicit compile-time assertion (as is done in many projects already).

This is a good point and one that I wasn't aware of.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 6, 2020
…xt, r=eddyb

expose suggestions::InferCtxtExt for clippy

This is very useful to do good async/await diagnostic reporting, for example for rust-lang/rust-clippy#5423.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 6, 2020
…xt, r=eddyb

expose suggestions::InferCtxtExt for clippy

This is very useful to do good async/await diagnostic reporting, for example for rust-lang/rust-clippy#5423.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 6, 2020
…xt, r=eddyb

expose suggestions::InferCtxtExt for clippy

This is very useful to do good async/await diagnostic reporting, for example for rust-lang/rust-clippy#5423.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 6, 2020
…xt, r=eddyb

expose suggestions::InferCtxtExt for clippy

This is very useful to do good async/await diagnostic reporting, for example for rust-lang/rust-clippy#5423.
@rkuhn rkuhn force-pushed the add_futures_not_send branch 4 times, most recently from b4155c6 to bbc4f5b Compare April 8, 2020 14:09
@rkuhn
Copy link
Contributor Author

rkuhn commented Apr 8, 2020

@flip1995 I have amended the documentation and updated to the latest rustc master, using the nice async/await error reporting. To my mind it is ready.

@bors
Copy link
Collaborator

bors commented Apr 8, 2020

☔ The latest upstream changes (presumably #5438) made this pull request unmergeable. Please resolve the merge conflicts.

@flip1995 flip1995 self-requested a review April 8, 2020 14:50
@flip1995 flip1995 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Apr 8, 2020
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

@rkuhn Thanks! Can you remove the tests/ui/future_not_send.stdout file please? After that this is ready to get merged.

@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Apr 15, 2020
@bors
Copy link
Collaborator

bors commented Apr 15, 2020

☔ The latest upstream changes (presumably #5470) made this pull request unmergeable. Please resolve the merge conflicts.

@rkuhn
Copy link
Contributor Author

rkuhn commented Apr 17, 2020

done

@flip1995
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 17, 2020

📌 Commit d2cbbff has been approved by flip1995

bors added a commit that referenced this pull request Apr 17, 2020
add lint futures_not_send

changelog: add lint futures_not_send

fixes #5379

~Remark: one thing that can (should?) still be improved is to directly include the error message from the `Send` check so that the programmer stays in the flow. Currently, getting the actual error message requires a restructuring of the code to make the `Send` constraint explicit.~
It now shows all unmet constraints for allowing the Future to be Send.
@bors
Copy link
Collaborator

bors commented Apr 17, 2020

⌛ Testing commit d2cbbff with merge 3379faf...

@bors
Copy link
Collaborator

bors commented Apr 17, 2020

💔 Test failed - checks-action_test

@flip1995
Copy link
Member

@bors retry

@bors
Copy link
Collaborator

bors commented Apr 17, 2020

⌛ Testing commit d2cbbff with merge f1fb815...

@bors
Copy link
Collaborator

bors commented Apr 17, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lint idea: public Futures should be Send
5 participants