Skip to content

Add async_fn_in_trait lint #116184

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

Merged
merged 6 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review nits
  • Loading branch information
compiler-errors committed Oct 3, 2023
commit c373d206cd9ed7beec89c72e61d76ad61d6d35c1
2 changes: 1 addition & 1 deletion compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ lint_array_into_iter =
or use `IntoIterator::into_iter(..)` instead of `.into_iter()` to explicitly iterate by value

lint_async_fn_in_trait = use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified
.note = you can suppress this lint if you plan to use the trait locally, for concrete types, or do not care about auto traits like `Send` on the `Future`
.note = you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future`
.suggestion = you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`

lint_atomic_ordering_fence = memory fences cannot have `Relaxed` ordering
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_lint/src/async_fn_in_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ declare_lint! {
/// }
///
/// fn test<T: Trait>(x: T) {
/// fn is_send<T: Send>(_: T) {}
/// is_send(x.method()); // Not OK.
/// fn spawn<T: Send>(_: T) {}
/// spawn(x.method()); // Not OK.
/// }
/// ```
///
Expand Down Expand Up @@ -68,11 +68,10 @@ declare_lint! {
/// }
/// ```
///
/// Conversely, if the trait is used only locally, if only concrete types
/// that implement the trait are used, or if the trait author otherwise
/// does not care that the trait will not promise that the returned
/// [`Future`] implements any [auto traits] such as [`Send`], then the
/// lint may be suppressed.
/// Conversely, if the trait is used only locally, if it is never used in
/// generic functions, or if it is only used in single-threaded contexts
/// that do not care whether the returned [`Future`] implements [auto traits]
/// such as [`Send`], then the lint may be suppressed.
///
/// [`Future`]: https://doc.rust-lang.org/core/future/trait.Future.html
/// [`Send`]: https://doc.rust-lang.org/core/marker/trait.Send.html
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/in-trait/warn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: use of `async fn` in public traits is discouraged as auto trait bounds ca
LL | async fn not_send();
| ^^^^^
|
= note: you can suppress this lint if you plan to use the trait locally, for concrete types, or do not care about auto traits like `Send` on the `Future`
= note: you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future`
note: the lint level is defined here
--> $DIR/warn.rs:4:9
|
Expand Down