Skip to content

Commit 31739fb

Browse files
Remove the async_fn_in_trait lint
1 parent 67d984b commit 31739fb

34 files changed

+13
-194
lines changed

compiler/rustc_lint/messages.ftl

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ lint_associated_const_elided_lifetime = {$elided ->
2121
.suggestion = use the `'static` lifetime
2222
.note = cannot automatically infer `'static` because of other lifetimes in scope
2323
24-
lint_async_fn_in_trait = use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified
25-
.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`
26-
.suggestion = you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`, but these cannot be relaxed without a breaking API change
27-
2824
lint_atomic_ordering_fence = memory fences cannot have `Relaxed` ordering
2925
.help = consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`
3026

compiler/rustc_lint/src/async_fn_in_trait.rs

-130
This file was deleted.

compiler/rustc_lint/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
// tidy-alphabetical-end
3737

3838
mod async_closures;
39-
mod async_fn_in_trait;
4039
pub mod builtin;
4140
mod context;
4241
mod dangling;
@@ -82,7 +81,6 @@ mod unqualified_local_imports;
8281
mod unused;
8382

8483
use async_closures::AsyncClosureUsage;
85-
use async_fn_in_trait::AsyncFnInTrait;
8684
use builtin::*;
8785
use dangling::*;
8886
use default_could_be_derived::DefaultCouldBeDerived;
@@ -238,7 +236,6 @@ late_lint_methods!(
238236
MissingDebugImplementations: MissingDebugImplementations,
239237
MissingDoc: MissingDoc,
240238
AsyncClosureUsage: AsyncClosureUsage,
241-
AsyncFnInTrait: AsyncFnInTrait,
242239
NonLocalDefinitions: NonLocalDefinitions::default(),
243240
ImplTraitOvercaptures: ImplTraitOvercaptures,
244241
IfLetRescope: IfLetRescope::default(),
@@ -604,6 +601,11 @@ fn register_builtins(store: &mut LintStore) {
604601
"converted into hard error, see issue #127323 \
605602
<https://github.com/rust-lang/rust/issues/127323> for more information",
606603
);
604+
store.register_removed(
605+
"async_fn_in_trait",
606+
"lint was relaxed since return-type notation is stabilized; \
607+
see <TODO> for more information",
608+
)
607609
}
608610

609611
fn register_internals(store: &mut LintStore) {

compiler/rustc_lint/src/lints.rs

-14
Original file line numberDiff line numberDiff line change
@@ -2100,20 +2100,6 @@ pub(crate) struct UnusedAllocationDiag;
21002100
#[diag(lint_unused_allocation_mut)]
21012101
pub(crate) struct UnusedAllocationMutDiag;
21022102

2103-
pub(crate) struct AsyncFnInTraitDiag {
2104-
pub sugg: Option<Vec<(Span, String)>>,
2105-
}
2106-
2107-
impl<'a> LintDiagnostic<'a, ()> for AsyncFnInTraitDiag {
2108-
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
2109-
diag.primary_message(fluent::lint_async_fn_in_trait);
2110-
diag.note(fluent::lint_note);
2111-
if let Some(sugg) = self.sugg {
2112-
diag.multipart_suggestion(fluent::lint_suggestion, sugg, Applicability::MaybeIncorrect);
2113-
}
2114-
}
2115-
}
2116-
21172103
#[derive(LintDiagnostic)]
21182104
#[diag(lint_unit_bindings)]
21192105
pub(crate) struct UnitBindingsDiag {

tests/ui/async-await/in-trait/async-associated-types.rs

-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ use std::fmt::Debug;
66
trait MyTrait<'a, 'b, T> where Self: 'a, T: Debug + Sized + 'b {
77
type MyAssoc;
88

9-
#[allow(async_fn_in_trait)]
109
async fn foo(&'a self, key: &'b T) -> Self::MyAssoc;
1110
}
1211

1312
impl<'a, 'b, T: Debug + Sized + 'b, U: 'a> MyTrait<'a, 'b, T> for U {
1413
type MyAssoc = (&'a U, &'b T);
1514

16-
#[allow(async_fn_in_trait)]
1715
async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
1816
(self, key)
1917
}

tests/ui/async-await/in-trait/async-default-fn-overridden.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
use std::future::Future;
55

66
trait AsyncTrait {
7-
#[allow(async_fn_in_trait)]
87
async fn default_impl() {
98
assert!(false);
109
}
1110

12-
#[allow(async_fn_in_trait)]
1311
async fn call_default_impl() {
1412
Self::default_impl().await
1513
}

tests/ui/async-await/in-trait/async-example-desugared-boxed.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use std::future::Future;
55
use std::pin::Pin;
66

7-
#[allow(async_fn_in_trait)]
87
pub trait MyTrait {
98
async fn foo(&self) -> i32;
109
}

tests/ui/async-await/in-trait/async-example-desugared-boxed.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: impl trait in impl method signature does not match trait method signature
2-
--> $DIR/async-example-desugared-boxed.rs:14:22
2+
--> $DIR/async-example-desugared-boxed.rs:13:22
33
|
44
LL | async fn foo(&self) -> i32;
55
| --------------------------- return type from trait method defined here
@@ -10,7 +10,7 @@ LL | fn foo(&self) -> Pin<Box<dyn Future<Output = i32> + '_>> {
1010
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
1111
= note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
1212
note: the lint level is defined here
13-
--> $DIR/async-example-desugared-boxed.rs:13:12
13+
--> $DIR/async-example-desugared-boxed.rs:12:12
1414
|
1515
LL | #[warn(refining_impl_trait)]
1616
| ^^^^^^^^^^^^^^^^^^^

tests/ui/async-await/in-trait/async-example-desugared-extra.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::pin::Pin;
66
use std::task::Poll;
77

88
pub trait MyTrait {
9-
#[allow(async_fn_in_trait)]
109
async fn foo(&self) -> i32;
1110
}
1211

tests/ui/async-await/in-trait/async-example-desugared-manual.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use std::future::Future;
55
use std::task::Poll;
66

7-
#[allow(async_fn_in_trait)]
87
pub trait MyTrait {
98
async fn foo(&self) -> i32;
109
}

tests/ui/async-await/in-trait/async-example-desugared-manual.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: impl trait in impl method signature does not match trait method signature
2-
--> $DIR/async-example-desugared-manual.rs:22:22
2+
--> $DIR/async-example-desugared-manual.rs:21:22
33
|
44
LL | async fn foo(&self) -> i32;
55
| --------------------------- return type from trait method defined here
@@ -10,7 +10,7 @@ LL | fn foo(&self) -> MyFuture {
1010
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
1111
= note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
1212
note: the lint level is defined here
13-
--> $DIR/async-example-desugared-manual.rs:21:12
13+
--> $DIR/async-example-desugared-manual.rs:20:12
1414
|
1515
LL | #[warn(refining_impl_trait)]
1616
| ^^^^^^^^^^^^^^^^^^^

tests/ui/async-await/in-trait/async-example-desugared.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use std::future::Future;
55

66
trait MyTrait {
7-
#[allow(async_fn_in_trait)]
87
async fn foo(&self) -> i32;
98
}
109

tests/ui/async-await/in-trait/async-example.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
//@ edition: 2021
33

44
trait MyTrait {
5-
#[allow(async_fn_in_trait)]
65
async fn foo(&self) -> i32;
76

8-
#[allow(async_fn_in_trait)]
97
async fn bar(&self) -> i32;
108
}
119

tests/ui/async-await/in-trait/async-lifetimes-and-bounds.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use std::fmt::Debug;
55

66
trait MyTrait<'a, 'b, T> {
7-
#[allow(async_fn_in_trait)]
87
async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T) where T: Debug + Sized;
98
}
109

tests/ui/async-await/in-trait/async-lifetimes.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//@ edition: 2021
33

44
trait MyTrait<'a, 'b, T> {
5-
#[allow(async_fn_in_trait)]
65
async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T);
76
}
87

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ edition:2021
22

3-
#[allow(async_fn_in_trait)]
4-
53
pub trait BleRadio<'a> {
64
async fn transmit(&mut self);
75
}

tests/ui/async-await/in-trait/bad-region.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//@ aux-build:bad-region.rs
22
//@ edition:2021
33

4-
#![allow(async_fn_in_trait)]
5-
64
extern crate bad_region as jewel;
75

86
use jewel::BleRadio;

tests/ui/async-await/in-trait/bad-region.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0726]: implicit elided lifetime not allowed here
2-
--> $DIR/bad-region.rs:12:6
2+
--> $DIR/bad-region.rs:10:6
33
|
44
LL | impl BleRadio for Radio {
55
| ^^^^^^^^ expected lifetime parameter

tests/ui/async-await/in-trait/early-bound-1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//@ edition:2021
33

44
pub trait Foo {
5-
#[allow(async_fn_in_trait)]
65
async fn foo(&mut self);
76
}
87

tests/ui/async-await/in-trait/early-bound-2.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//@ edition:2021
33

44
pub trait Foo {
5-
#[allow(async_fn_in_trait)]
65
async fn foo(&mut self);
76
}
87

tests/ui/async-await/in-trait/implied-bounds.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ trait TcpStack {
55
type Connection<'a>: Sized where Self: 'a;
66
fn connect<'a>(&'a self) -> Self::Connection<'a>;
77

8-
#[allow(async_fn_in_trait)]
98
async fn async_connect<'a>(&'a self) -> Self::Connection<'a>;
109
}
1110

tests/ui/async-await/in-trait/issue-102138.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ async fn yield_now() {}
88
trait AsyncIterator {
99
type Item;
1010

11-
#[allow(async_fn_in_trait)]
1211
async fn next(&mut self) -> Option<Self::Item>;
1312
}
1413

tests/ui/async-await/in-trait/issue-102219.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
//@ check-pass
44

55
trait T {
6-
#[allow(async_fn_in_trait)]
76
async fn foo();
87
}

tests/ui/async-await/in-trait/issue-102310.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//@ edition:2021
33

44
pub trait SpiDevice {
5-
#[allow(async_fn_in_trait)]
65
async fn transaction<F, R>(&mut self);
76
}
87

tests/ui/async-await/in-trait/issue-104678.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::future::Future;
55
pub trait Pool {
66
type Conn;
77

8-
#[allow(async_fn_in_trait)]
98
async fn async_callback<'a, F: FnOnce(&'a Self::Conn) -> Fut, Fut: Future<Output = ()>>(
109
&'a self,
1110
callback: F,

0 commit comments

Comments
 (0)