Skip to content

Commit e3d4c40

Browse files
committed
Migrate trait_fn_async
1 parent 88afae5 commit e3d4c40

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,7 @@ impl<'a> AstValidator<'a> {
287287

288288
fn check_trait_fn_not_async(&self, fn_span: Span, asyncness: Async) {
289289
if let Async::Yes { span, .. } = asyncness {
290-
struct_span_err!(
291-
self.session,
292-
fn_span,
293-
E0706,
294-
"functions in traits cannot be declared `async`"
295-
)
296-
.span_label(span, "`async` because of this")
297-
.note("`async` trait functions are not currently supported")
298-
.note("consider using the `async-trait` crate: https://crates.io/crates/async-trait")
299-
.emit();
290+
self.session.emit_err(TraitFnAsync { fn_span, span });
300291
}
301292
}
302293

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,14 @@ pub enum InvalidVisibilityNote {
7171
#[note(ast_passes::individual_foreign_items)]
7272
IndividualForeignItems,
7373
}
74+
75+
#[derive(SessionDiagnostic)]
76+
#[error(ast_passes::trait_fn_async, code = "E0706")]
77+
#[note]
78+
#[note(ast_passes::note2)]
79+
pub struct TraitFnAsync {
80+
#[primary_span]
81+
pub fn_span: Span,
82+
#[label]
83+
pub span: Span,
84+
}

compiler/rustc_error_messages/locales/en-US/ast_passes.ftl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ ast_passes_invalid_visibility =
2121
.implied = `pub` not permitted here because it's implied
2222
.individual_impl_items = place qualifiers on individual impl items instead
2323
.individual_foreign_items = place qualifiers on individual foreign items instead
24+
25+
ast_passes_trait_fn_async =
26+
functions in traits cannot be declared `async`
27+
.label = `async` because of this
28+
.note = `async` trait functions are not currently supported
29+
.note2 = consider using the `async-trait` crate: https://crates.io/crates/async-trait

0 commit comments

Comments
 (0)